Source Code:
src/gaia/api/Import:
from gaia.api.openai_server import appDetailed Spec: spec/api-server
7.1 OpenAI-Compatible API
Purpose: Expose GAIA agents as OpenAI-compatible REST API.Port 8080 is shared by default with
gaia mcp docker. Run one of them on a
different port (e.g. gaia api start --port 8081) if you need both alive at
the same time.7.2 Custom API Agent
Import:from gaia.agents.base.api_agent import ApiAgent
ApiAgent is a mixin that already subclasses the core Agent; you only need to
inherit from ApiAgent:
Registering new agents with the server
The API server exposes a static registry of agent models atsrc/gaia/api/agent_registry.py, not a runtime register() API. To add a new
model, append an entry to AGENT_MODELS:
class_name lazily on the first request. init_params are
passed to the agent’s constructor; gaia api start --debug, --show-prompts,
--streaming, and --step-through inject GAIA_API_* env-vars that the
registry merges into init_params at startup.
Runtime plug-in discovery is on the roadmap (see
src/gaia/agents/registry.py),
but the OpenAI-compatible server still requires editing AGENT_MODELS and
restarting the process.7.3 SSE Streaming
Import:from gaia.api.sse_handler import SSEOutputHandler
Events emitted
The API-layerSSEOutputHandler emits a strict subset used for OpenAI-style
chat completions: chunk (streamed token deltas) and answer (final message).
The Agent UI uses a richer handler in src/gaia/ui/sse_handler.py that emits
additional events — tool_start, tool_end, tool_result, thinking,
processing, error. When wiring SSE through the Agent UI routers you will see
both surfaces.
Related Topics
- Core Agent System - Learn about the base Agent class
- MCP Integration - Model Context Protocol support
- Specialized Agents - Pre-built agent implementations
- Application Packaging - Package agents for distribution