Skip to main content

The /v1/chat/completions endpoint is fully compatible with the OpenAI Chat Completions API. Any client or SDK that already targets OpenAI works with Rolter without code changes — set base_url to your gateway address and supply a Rolter virtual key as the API key. Rolter authenticates the request, selects an upstream target based on your route configuration, optionally injects admin-configured param defaults, and forwards the request transparently.

Request#

POST /v1/chat/completions

Headers#

Authorizationstringrequired#

Bearer <virtual-key> — your Rolter virtual key.

Content-Typestringrequired#

Must be application/json.

x-session-idstring#

Optional session identifier for affinity-based routing. Pass a stable value (e.g. a user or conversation ID) to pin multi-turn requests to the same upstream replica and improve KV-cache hit rates.

Body#

modelstringrequired#

The route name defined in your rolter.toml, for example gpt-4o. Rolter looks up this route and rewrites model to the upstream model ID before forwarding. Returns 404 if no matching route exists.

messagesarrayrequired#

Array of message objects forming the conversation history.

streamboolean#

Set to true to receive a streaming response over Server-Sent Events (SSE). Each event carries a data: line with a JSON delta chunk; the stream terminates with data: [DONE].

Default: "false"

temperaturenumber#

Sampling temperature between 0 and 2. Higher values produce more random output. Passed through to the upstream; may be overridden or pinned by the route’s param_policy in your config.

max_tokensinteger#

Maximum number of tokens to generate. Passed through to the upstream; may be capped by the route’s params defaults.

stopstring | array#

One or more sequences at which the model stops generating further tokens.

top_pnumber#

Nucleus sampling probability mass. An alternative to temperature; most providers recommend adjusting one but not both.

Note

Any additional fields you include in the body — frequency_penalty, presence_penalty, logit_bias, tools, response_format, and others — are forwarded to the upstream as-is. Rolter only reads model and stream for its own logic.

Streaming#

When "stream": true, Rolter proxies the upstream’s Server-Sent Events stream directly to your client. Each event looks like:

Use curl’s -N flag (--no-buffer) to disable output buffering when testing streaming from the command line.

Examples#

Session affinity for multi-turn conversations#

Pass x-session-id to pin a conversation thread to the same upstream replica. This is especially useful with self-hosted vLLM or SGLang pools where KV-cache reuse across turns can significantly reduce latency and cost.

curl (session affinity)
OpenAI SDK (session affinity)

Param policy#

Your rolter.toml can attach default inference parameters to a route under [routes.params] (e.g. temperature = 0.0, max_tokens = 1024). The route’s param_policy then controls whether callers can override those defaults:

  • mode = "allow" (default) — callers may override any default except params listed in deny.
  • mode = "deny" — the admin default wins for every param except those listed in allow.

When an override is denied, the admin default silently replaces the caller-supplied value before the request reaches the upstream.