Base URL
Authentication
All requests require a MetrixLLM API key. The gateway accepts both formats:Internal Authentication
For backend-to-gateway communication, the gateway supports internal authentication:
Internal auth skips the standard API key validation. Used by the MetrixLLM backend for playground, replay, and batch operations.
Endpoints
Request Headers
Every request supports these headers:
Session Tracing
Use these headers to group related requests into sessions and trace spans:
Custom Properties
Attach up to 10 custom metadata properties per request:
Example:
metrix-property-team: engineering, metrix-property-environment: production
Worker-to-Gateway
These headers are set by the Cloudflare Edge Worker when routing through the Durable Object balance system:
IP Detection
Chat Completions
Request Body
Send standard OpenAI Chat Completions requests. The gateway accepts all standard OpenAI fields plus MetrixLLM-specific extensions.Examples
Response Body
Response Headers
Every successful response includes these headers:
On cache HIT responses, only
Content-Type and X-Metrix-Cache-Status: HIT are returned.
On rate limited responses (429 Too Many Requests):
Streaming
Set"stream": true in the request body to receive Server-Sent Events (SSE).
Streaming is supported through the gateway proxy endpoints (
/v1/chat/completions and /openai/v1/chat/completions). The gateway returns SSE events in the standard OpenAI format.Web Search
Enable web search to give the model access to real-time information.
Additional parameters:
Native Web Search Example
Prompt Management
Useprompt_id to reference a stored prompt template. The gateway fetches the template, renders {{variable}} placeholders with values from inputs, and sends the rendered messages to the provider.
inputs object replaces {{variable}} placeholders in each message’s content field.
Error Responses
Errors return a JSON body with anerror field. The HTTP status code indicates the error type.
Error Response Format
Retry and Fallback
The gateway automatically retries failed requests and falls back to alternative providers:- Retry: Retries on
429,500,502,503,504status codes with exponential backoff - Fallback: If the primary provider fails, the gateway tries the next configured provider in the chain
- Circuit Breaker: Providers with repeated failures are temporarily skipped (circuit opens for 60 seconds)
- Cerebras Fallback: If all configured providers fail on system errors, the gateway falls back to Cerebras (if enabled)
Mode Override
Control provider key selection with themode field: