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

For local development:
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 the Authorization header. Keys are created through the Keys API and have the prefix ak-.

Create a chat completion

Request body

Message object

Content parts

A message content array may contain:

Example request

Example response

Response fields

Model selection

The model field supports three forms:
  1. Policy alias — auto, allternit-balanced, allternit-code, allternit-reasoning, allternit-knowledge, or allternit-instruct. The gateway scores connected providers against benchmark weights and picks a winner plus a cross-provider fallback chain.
  2. 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.
  3. Bare model id — The gateway looks the model up in the connected catalog and selects the first provider that offers it.
The resolved fallback chain is sent to the runtime and is used automatically on retryable provider failures.

Streaming

Set stream: 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 include tool_calls describing the requested tool invocations.

Structured outputs

Enforce a JSON schema on the response:

Reasoning mode

Use reasoning_effort to request extended thinking:

Multimodal inputs

Images and videos are accepted as content parts:

Session reuse

Pass the header x-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 an Idempotency-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 the x-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:
  • packs lists the same four packs as GET /api/v1/billing/packs ($10, $25, $50, $100). The example shows one.
  • For credits_exhausted the message is Your Allternit Cloud credits are used up. Add credits to keep going.
  • To check before sending, read cloud_models on GET /api/v1/billing/credits (see Cloud billing).
Signed-in sessions. A Clerk session (the Allternit apps with no computer) may call a Cloud catalog alias by its bare id, such as 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