Model API reference
The model API is served under LLM_GATEWAY_PATH (default /llm). It speaks the OpenAI Chat Completions and Responses formats and the Anthropic Messages format, so OpenAI SDKs, Anthropic SDKs, Codex, Claude Code and Cursor work unchanged. Point OpenAI clients at https://<gateway-host>/llm/v1 and Anthropic clients at https://<gateway-host>/llm.
Every format runs through the same pipeline (access, context rules, guardrails, budgets, routing and fallback, logging), and any provider can serve any format: a Claude Code request can be served by an OpenAI deployment and the reverse.
Authenticate with an AI key (Authorization: Bearer zk_... or x-api-key) or with the profile's gateway credentials.
Endpoints
| Method and path | Description |
|---|---|
GET /llm/v1/models | Models the caller may use (active, listed, granted to the client and in the profile subset). |
GET /llm/v1/models/{name} | One model. 404 if it does not exist or is not available to the caller. |
POST /llm/v1/chat/completions | Chat completion in OpenAI format, including tools, images and stream: true (server-sent events). With streaming, send stream_options: {"include_usage": true} to receive token usage in the last chunk. |
POST /llm/v1/responses | OpenAI Responses API, used by Codex. Stateless: send the whole conversation in input (store: false); previous_response_id is not supported. Supports instructions, message, function_call and function_call_output items, function tools, custom (free-form) tools such as Codex's apply_patch, text.format JSON schemas and streaming events (response.created ... response.completed). Reasoning items and built-in tools (web search, file search) are ignored. |
POST /llm/v1/messages | Anthropic Messages API, used by Claude Code and Anthropic SDKs: system prompts, text and image blocks, tool_use / tool_result, tool choice and streaming events (message_start ... message_stop). Errors use the Anthropic error shape. Thinking blocks and Anthropic server tools are ignored. |
POST /llm/v1/messages/count_tokens | Estimated input tokens for an Anthropic Messages request. |
POST /llm/v1/embeddings | Embeddings for a string or a list of strings (models of kind Embeddings). Guardrails check and mask the input. Vectors are not stored in AI Logs. |
POST /llm/v1/images/generations | Image generation (kind Images); the provider's response is returned as is. Guardrails check the prompt. |
POST /llm/v1/audio/speech | Text to speech (kind Audio); returns the provider's audio (for example audio/mpeg). Guardrails check the input; audio is not logged. |
POST /llm/v1/audio/transcriptions | Speech to text (kind Audio) as a multipart form with model and file. Raise the maximum request size in AI Settings for long recordings. |
POST /llm/v1/moderations | Moderation with a provider's moderation model (any kind). |
Embeddings, images, audio and moderations are served by OpenAI-compatible providers (OpenAI, Azure OpenAI, Groq, OpenRouter, Ollama, Gemini, custom servers; Vertex AI for embeddings where its OpenAI-compatible endpoint offers them). Calling a model on an endpoint of another kind returns 400 invalid_request_error.
model may be omitted when the client has a default model.
Response headers
| Header | Meaning |
|---|---|
X-Zerq-Request-ID | ID of the AI log entry. |
X-LLM-Provider | Name of the provider that served the request. |
X-LLM-Model | Upstream model that served it. |
X-Zerq-Fallback | Number of failed attempts before the one that succeeded (only when a fallback happened). |
Errors
Errors use the OpenAI shape: {"error": {"message": "...", "type": "...", "code": "..."}}.
| Status | Type | When |
|---|---|---|
| 400 | invalid_request_error | Body is not a JSON object, messages is missing, model is missing with no default, or the provider rejected the request as malformed. |
| 400 | context_length_exceeded | The prompt is too long for the model (see context). |
| 400 | guardrail_blocked | A guardrail blocked the prompt or the answer. |
| 400 | content_filter | The provider's content filter rejected the request. |
| 401 | authentication_error | Missing or invalid AI key or credentials. |
| 403 | AI access is not enabled for the profile, or the profile has no authentication. | |
| 403 | model_not_allowed | The model exists but is not granted to this client or profile. |
| 404 | model_not_found | The model does not exist or is inactive. |
| 413 | request_too_large | The body exceeds the maximum request size in Settings (default 4 MB). |
| 429 | rate_limit_exceeded | A per-minute or concurrency limit was reached, or every provider is rate limiting. Includes Retry-After. |
| 429 | budget_exceeded | A token or spend quota, or the profile's token cap, is used up. Includes Retry-After. |
| 502 | upstream_unavailable | Every deployment and fallback model failed. |
| 503 | gateway_disabled | Model traffic is switched off in Settings. |
| 504 | upstream_timeout | The providers did not answer within their timeout. |
When a stream has already started, an error is sent as a final data: event with the same error object.