1. Chat
The Delegation
  • Documentation
    • Getting started
    • TypeScript client
    • Python client
    • Go client
    • Operations and observability
  • AI Gateway
    • Chat
      • Create a chat completion
        POST
    • Embeddings
      • Create text embeddings
    • Audio
      • Transcribe audio with AWS Transcribe
      • Text-to-speech
    • Images
      • Generate images with Gemini
    • Models
      • List available models
      • Retrieve a model
    • Users
      • List all users
      • Create a user
      • Get a user
      • Delete a user
      • Get user usage and cost summary
    • Health
      • Liveness / readiness probe
      • Provider health check
      • Gateway info
    • Admin
      • Per-provider request metrics
      • List configured providers
    • Schemas
      • ContentPartText
      • ContentPartImageURL
      • ContentPartAudio
      • ContentPartVideo
      • ContentPartDocument
      • ContentPart
      • FunctionDef
      • Tool
      • ToolCall
      • ChatMessage
      • ChatRequest
      • Usage
      • Choice
      • ChatResponse
      • EmbeddingsRequest
      • EmbeddingObject
      • EmbeddingsResponse
      • TranscriptionResponse
      • TTSRequest
      • ImageGenerationRequest
      • ImageData
      • ImageGenerationResponse
      • ModelInfo
      • ModelList
      • UsageRecord
      • User
      • UserUsageSummary
      • ProviderHealth
      • HealthResponse
      • ProviderMetrics
      • MetricsResponse
      • ErrorDetail
      • ErrorResponse
  • Platform API
    • Projects
      • List projects
      • Create project
      • Get project
      • Update project
      • Delete project
    • Tasks
      • Create task
      • Get task
      • Update task
    • Conversations
      • Get conversation
      • Clear conversation
      • Send message
    • Keys
      • Gateway usage statistics
    • Account
      • Get account
      • Update account role
      • Delete account
    • Schemas
      • Error
      • ChatMessage
      • ToolDefinition
      • ToolCall
      • ChatCompletionRequest
      • ChatCompletionResponse
      • EmbeddingRequest
      • ImageGenRequest
      • Project
      • Task
      • Message
      • Conversation
      • UserFile
      • GatewayKey
      • User
      • UserBalance
      • AuthSession
      • Session
  • File Service
    • Files
      • List files
      • Upload file
      • Update file
      • Delete / trash file
      • Restore file from trash
    • Schemas
      • Error
      • ChatMessage
      • ToolDefinition
      • ToolCall
      • ChatCompletionRequest
      • ChatCompletionResponse
      • EmbeddingRequest
      • ImageGenRequest
      • Project
      • Task
      • Message
      • Conversation
      • UserFile
      • GatewayKey
      • User
      • UserBalance
      • AuthSession
      • Session
  1. Chat

Create a chat completion

POST
/v1/chat/completions
Create a chat completion. Model IDs infer the provider; no provider extension is needed for standard clients. Claude and Gemini support tool calls and streaming. For streams, failures before the first event return HTTP 502; failures after output begins emit a data event with an error envelope and no [DONE]. Treat incomplete streams as failures. Request IDs are returned in headers. Usage and cost attribution use server-controlled X-User-ID and optional session headers.

Request

Header Params

Body Params application/jsonRequired

Examples

Responses

🟢200
application/json
Non-streaming — Content-Type: application/json
Streaming — Content-Type: text/event-stream. Each event:
data: {StreamChunk json}\n\n. Ends with data: [DONE]\n\n.
Headers

Body

🟠400BadRequest
🟠401Unauthorized
🟠429RateLimited
🔴502ProviderError
🔴503Unavailable
Request Request Example
Shell
JavaScript
Java
Swift
cURL
curl --location '/v1/chat/completions' \
--header 'X-User-ID;' \
--header 'X-Session-ID;' \
--header 'Content-Type: application/json' \
--data '{
    "provider": "claude",
    "model": "claude-sonnet-4-6",
    "messages": [
        {
            "role": "user",
            "content": "Explain quantum entanglement in one paragraph."
        }
    ],
    "max_tokens": 256
}'
Response Response Example
200 - Example 1
{
    "id": "chatcmpl-1234567890",
    "object": "chat.completion",
    "created": 0,
    "model": "claude-sonnet-4-6",
    "provider": "claude",
    "choices": [
        {
            "index": 0,
            "message": {
                "role": "system",
                "content": "string",
                "name": "string",
                "tool_calls": [
                    {
                        "id": "call_abc123",
                        "type": "function",
                        "function": {
                            "name": "get_weather",
                            "arguments": "{\"location\":\"Paris, FR\"}"
                        },
                        "index": 0
                    }
                ],
                "tool_call_id": "call_abc123"
            },
            "finish_reason": "stop",
            "logprobs": null
        }
    ],
    "usage": {
        "prompt_tokens": 12,
        "completion_tokens": 48,
        "total_tokens": 60
    }
}
Modified at 2026-10-20 19:28:20
Previous
Operations and observability
Next
Create text embeddings
Built with