OpenAI Integration¶
HiveFlow integrates with OpenAI via optional extras and the shared LLMClient abstraction.
Install¶
pip install "hiveflow-core[llm]"
export OPENAI_API_KEY=sk-...
Core: OpenAIClient¶
from hiveflow import OpenAIClient, LLMMessage
client = OpenAIClient(model="gpt-4o-mini", api_key=os.environ["OPENAI_API_KEY"])
response = await client.chat(
messages=[LLMMessage(role="user", content="Summarize multi-agent orchestration in one sentence.")],
)
print(response.content)
Agent runtime¶
The Agent package uses the same client for ReAct workers:
from hiveflow import OpenAIClient
from app import HiveMindApp # packages/agent
app = HiveMindApp(llm_client=OpenAIClient(model="gpt-4o-mini"))
result = await app.run_query("What is on the blackboard?")
Studio¶
- Open Settings → LLM Config
- Provider: OpenAI
- Set API key (stored in Studio credentials store, not in repo)
- Run workflows from Orchestrator in real mode (toggle off mock)
Environment variables¶
| Variable | Purpose |
|---|---|
OPENAI_API_KEY |
API authentication |
OPENAI_BASE_URL |
Optional proxy / Azure-compatible endpoint |
Multimodal (optional)¶
pip install "hiveflow-core[all]"
Use OpenAIImageProcessor, OpenAIAudioProcessor, and OpenAIVideoProcessor from hiveflow.multimodal — see example 15.
Troubleshooting¶
| Issue | Fix |
|---|---|
ImportError: openai |
pip install "hiveflow-core[llm]" |
| 401 Unauthorized | Check OPENAI_API_KEY |
| Rate limits | Lower concurrency in scheduler or add retries in custom handler |