Overview
The Chat Completions API is the primary gateway surface for sending multi-turn messages to language models. It accepts a standard chat-completions request body, routes the request through the Allternit model selector or to an explicit provider/model pair, and returns a completion in a familiar shape with usage metadata. The gateway supports non-streaming and streaming responses, tool-call deltas, structured JSON outputs, reasoning controls, multimodal inputs, session reuse, automatic cross-provider failover, and prompt caching.Base URL
On the hosted Cloud API (
https://api.allternit.com), only POST /v1/chat/completions and GET /v1/models are served under /v1. best_of, partial and /v1/tokens below are served by the Allternit API data-plane node (http://127.0.0.1:8013/v1).Endpoints
Authentication
All gateway requests use a virtual key in theAuthorization header. Keys are created through the Keys API and have the prefix ak-.
Create a chat completion
Request body
Message object
Content parts
A messagecontent array may contain:
Example request
Example response
Response fields
Model selection
Themodel field supports three forms:
- Policy alias —
auto,allternit-balanced,allternit-code,allternit-reasoning,allternit-knowledge, orallternit-instruct. The gateway scores connected providers against benchmark weights and picks a winner plus a cross-provider fallback chain. - Explicit provider/model — e.g.
provider/model. The gateway uses that pair as the primary and still derives a fallback chain from the balanced scorecard. - Bare model id — The gateway looks the model up in the connected catalog and selects the first provider that offers it.
Streaming
Setstream: true to receive server-sent events. The stream emits a role chunk, content deltas, optional tool-call deltas, a finish chunk, and (when stream_options.include_usage is true) a final usage chunk followed by [DONE].
Tool calling
Tool definitions are validated but execution happens inside the Allternit runtime. The final assistant message may includetool_calls describing the requested tool invocations.
Structured outputs
Enforce a JSON schema on the response:Reasoning mode
Usereasoning_effort to request extended thinking:
Multimodal inputs
Images and videos are accepted as content parts:Session reuse
Pass the headerx-allternit-session-id from a previous completion to continue the same runtime session. Only the last user message is forwarded; the runtime supplies the historical context.
Idempotency
Include anIdempotency-Key header (1–255 ASCII characters) on non-streaming requests. The gateway stores the response body and replays it for identical keys. Keys are scoped to the virtual key and ignored for streaming requests.
Token and cost estimation
POST /v1/tokens returns a token count and cost estimate without invoking a model.
Error codes
Related pages
- Models — list models and pricing
- Embeddings — text embeddings
- Files — upload and reference files
- Batches — asynchronous batch inference
- Cache — reusable prompt caches
- Context Caches — reusable message prefixes
- Images — image generation and editing
- Realtime Audio — voice sessions
- Vector Stores — file collections for retrieval
- Estimates — token and cost estimation
- Proxy — gateway middleware and routing
- Translate — wire-format translation layer
- Authentication — virtual keys