Skip to content
Search documentation titles, headings, and guides
API v1Updated 2026-09-16

Anthropic Messages

Drop-in Anthropic-compatible POST /v1/messages endpoint with system prompts, image inputs, and tool use.

POST /v1/messages is a drop-in replacement for the Anthropic Messages API. Point the Anthropic SDK (or any Anthropic-compatible client) at the gateway base URL and your existing code keeps working, including system prompts, image inputs, and tool use.

Endpoint#

POST/v1/messages
Auth: api-key

Create a message. Responses follow the Anthropic message object shape; errors use the Anthropic-shaped envelope ({ type: "error", error: {...} }).

Parameters

modelstringbodyrequired

The model identifier (`<public-name>`). See [Model Catalog](/en/docs/api-reference/models).

messagesarraybodyrequired

The conversation as an ordered array of `{ role, content }` objects.

systemstringbodyoptional

A top-level system prompt, Anthropic style. Optional but recommended for steering behavior.

max_tokensintegerbodyrequired

The maximum number of tokens to generate. Required by the Anthropic Messages API.

streambooleanbodyoptionaldefault: false

Set `true` to receive Server-Sent Events. See [Streaming & SSE](/en/docs/api-reference/streaming).

temperaturenumberbodyoptional

Sampling temperature. Forwarded to the upstream unchanged when provided.

Request Example

curl -X POST "https://api.zrouter.dev/v1/messages" \
  -H "x-api-key: YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "<public-name>",
    "max_tokens": 1024,
    "messages": [{"role": "user", "content": "Say hello!"}]
  }'

Responses

200Successful message.
{
  "id": "msg_...",
  "type": "message",
  "role": "assistant",
  "model": "<public-name>",
  "content": [
    { "type": "text", "text": "Hello!" }
  ],
  "stop_reason": "end_turn",
  "usage": { "input_tokens": 9, "output_tokens": 3 }
}
400`invalid_request` — malformed or invalid body.
401`invalid_api_key` — missing key, wrong key, or two headers with different values.
402`insufficient_balance` — Token Plan and PAYG balance cannot cover the request.
404`model_not_found` — the model identifier does not exist or is hidden.
429`technical_limit` — passthrough of an upstream 429, not a zrouter rate limit.
502`upstream_error` — the upstream provider failed to process the request.
503`overloaded` or `circuit_open` — capacity shed or an open circuit breaker.

Streaming#

With "stream": true the gateway relays the native Anthropic event stream unchanged, ending with message_stop. Raw event examples are in Streaming & SSE.