The /v1/messages endpoint is compatible with the Anthropic Messages API. Any Anthropic SDK or HTTP client works with Rolter without code changes — set base_url to your gateway address and supply a Rolter virtual key. Rolter accepts both x-api-key (the Anthropic convention) and Authorization: Bearer (the OpenAI convention) so you can use either depending on which SDK you are working with. Rolter handles routing, load balancing, and retries before the request reaches your upstream.
Request#
POST /v1/messages
Headers#
Your Rolter virtual key. This is the header expected by Anthropic SDKs and is the recommended approach when targeting /v1/messages.
Must be application/json.
Optional session identifier. Pass a stable value to enable affinity-based routing and improve KV-cache reuse across turns in a multi-turn conversation.
Body#
The route name defined in your rolter.toml, for example claude. Rolter looks up this route and rewrites model to the upstream model ID (e.g. claude-sonnet-4-20250514) before forwarding. Returns 404 if no matching route exists.
Array of message objects forming the conversation.
The maximum number of tokens to generate. The Anthropic API requires this field — requests without it are rejected by the upstream with a validation error.
Set to true to receive the response as a Server-Sent Events stream. Rolter proxies the upstream SSE stream directly to your client.
Default: "false"
An optional system prompt prepended to the conversation context. Passed through to the upstream unchanged.
Sampling temperature. Passed through to the upstream and subject to the route’s param_policy.
Nucleus sampling probability mass. An alternative to temperature.
Array of strings at which the model stops generating further tokens.
max_tokens is required by the Anthropic API. Omitting it produces a validation error from the upstream. Rolter forwards the request body as-is and does not inject max_tokens automatically — set it in [routes.params] if you want a default applied gateway-side.
Examples#
Self-hosted vLLM with session affinity#
If you run a pool of vLLM instances configured with an OpenAI-compatible provider and your pool serves a model that accepts Anthropic-format requests, you can use x-session-id to pin multi-turn traffic to the same replica.
Response#
A successful non-streaming response follows the Anthropic Messages shape:
Unique message identifier, prefixed with msg_.
Always "message" for a completed response.
Array of content blocks. Each block has a type field ("text" for standard text) and a text field.
Why generation stopped: end_turn, max_tokens, or stop_sequence.
Token counts for the request.