Skip to main content
Source Code: src/gaia/api/
Components: OpenAI-compatible API Server, Schemas, Endpoints, SSE Streaming Module: gaia.api Import: from gaia.api import app, schemas, agent_registry

Overview

The GAIA API Server provides an OpenAI-compatible REST API for exposing GAIA agents to external tools like VSCode, Claude Dev, and custom applications. It implements the OpenAI chat completions interface with streaming support, agent registration, and comprehensive debugging features. Key Features:
  • OpenAI-compatible endpoints (/v1/chat/completions, /v1/models)
  • Server-Sent Events (SSE) streaming
  • Dynamic agent registry
  • Workspace root extraction from GitHub Copilot
  • Debug modes (logging, prompts, step-through)
  • CORS support
  • Health checks
  • Token usage tracking

Requirements

Functional Requirements

Core Endpoints

  1. POST /v1/chat/completions
    • Non-streaming responses
    • SSE streaming responses
    • Message history: prior turns are loaded into the agent’s conversation, and system / developer messages are added to its system prompt
    • temperature, top_p, and max_tokens apply to every model call the agent makes for the request
    • Tool calls support (future)
  2. GET /v1/models
    • List available agents as models
    • Model metadata (tokens, description)
  3. GET /health
    • Reports API, Lemonade LLM, and RAG component status
    • Returns 200 OK while the API process is serving
    • Uses top-level degraded when Lemonade is unavailable or no LLM is loaded

Agent Registry

  1. Agent Registration
    • Dynamic agent discovery
    • Model ID mapping
    • Agent instantiation
    • Workspace configuration
  2. Agent Management
    • Singleton instances per agent type
    • Silent mode operation
    • Workspace root injection

Request Processing

  1. Message Handling
    • OpenAI message format; content is a string or an array of content parts
    • Text parts are joined with newlines; any other part type (image_url, input_audio, file) is rejected with 400
    • system and developer messages are appended to the agent’s system prompt
    • The last message must be from the user (400 otherwise); earlier user/assistant/tool messages become the agent’s conversation history
  2. Response Generation
    • Agent process_query() integration
    • Token counting
    • Usage statistics
    • Unique response IDs

Streaming Support

  1. SSE Streaming
    • Chunk-based streaming
    • Delta content format
    • Finish reason reporting
    • Proper SSE formatting (data: prefix)
    • A client disconnect stops the agent (its cancel event and the SSE handler’s cancelled flag are set), so it stops running tools and generating
    • If the agent raises mid-stream, the stream ends with an {"error": {...}} chunk followed by data: [DONE]

Non-Functional Requirements

  1. Performance
    • Low latency response
    • Efficient streaming
    • Connection pooling
  2. Reliability
    • Error handling
    • Connection recovery
    • Graceful degradation
  3. Debugging
    • Request/response logging
    • Prompt display
    • Step-through mode
    • Raw HTTP logging
  4. Security
    • CORS configuration
    • Input validation
    • Error sanitization
    • Confirmation-gated tools (shell, file writes, MCP writes) are refused — the API has no approval channel. See SDK → API Server for the GAIA_AUTO_APPROVE_TOOLS opt-out.

API Specification

File Locations

Schemas (Pydantic Models)

API Endpoints

Agent Registry

The API-server’s AgentRegistry is not a runtime plug-in registry — it is a hardcoded AGENT_MODELS dict in src/gaia/api/agent_registry.py plus a dynamic import helper. There is no register_agent() method today; to add a new model you edit AGENT_MODELS and restart the server.
For the richer agent registry used by the Agent UI (not the OpenAI-style API server), see the Agent Registry spec covering src/gaia/agents/registry.py and ~/.gaia/agents/ discovery of Python custom agents.

Implementation Details

Request Processing Flow

Debug Middleware


Testing Requirements

Unit Tests

File: tests/api/test_api_server.py

Usage Examples

Example 1: Start API Server

Example 2: Non-Streaming Request (curl)

Example 3: Streaming Request (curl)

Example 4: Python Client

Example 5: OpenAI Python SDK


CLI Interface

Commands


API Server Technical Specification

VS Code client authentication

Run GAIA: Set API Key from the VS Code command palette and enter the same value as the server’s GAIA_API_KEY. The extension stores it in VS Code SecretStorage and uses it for model discovery and chat completions. Leave the input blank to clear it; cancelling preserves the existing key. Keyless loopback servers continue to work.