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.
Refusal handoff (Cloud API)
On the hosted Cloud API, a user who turned on handoff in Settings > Open models gets a refused completion re-run on an open-lane model, after the hard-line filter. The handed-off response carries thex-allternit-handoff: from->to header and an allternit.handoff object (in a stream, as a first chunk with no choices). Pass allternit.handoff_model to pick the open model, or allternit.handoff: false to skip handoff for one request. With handoff on, streams start after their first 400 characters. Full reference: Open lane and refusal handoff.
Credits (Cloud API)
On the hosted Cloud API (https://api.allternit.com/v1), a call to an Allternit Cloud model is paid from the account’s credit balance (one credit is one US dollar). There is no free monthly allowance. The same check runs for model calls made by an artifact, billed to its viewer. Calls that route through the person’s own provider key, plan and Copilot models (plan/…, copilot/…) and platform project runtimes are billed their own way and skip it.
The
402 is always a JSON body, sent before any stream starts, so a streaming client gets it as the HTTP response, not as an event:
packslists the same four packs asGET /api/v1/billing/packs($10, $25, $50, $100). The example shows one.- For
credits_exhaustedthe message isYour Allternit Cloud credits are used up. Add credits to keep going. - To check before sending, read
cloud_modelsonGET /api/v1/billing/credits(see Cloud billing).
glm-5.3, with the same credits check. Other models that are not plan models stay refused for a session with 403. The apps save these chats in the plan chat store under allternit/<alias>.
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