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 support
    • Tool calls support (future)
  2. GET /v1/models
    • List available agents as models
    • Model metadata (tokens, description)
  3. GET /health
    • Health check endpoint
    • Returns 200 OK

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
    • System/user/assistant roles
    • GitHub Copilot workspace extraction
    • Prompt formatting
  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)

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

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

Workspace Root Extraction

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