Create Anthropic Messages

OpenAI-compatible gateway endpoint for Anthropic Messages API payloads.

POST/v1/messages
Legacy path deprecated
The legacy aliases /v1/anthropic/messages and /v1/anthropic/messages/count_tokens are deprecated and will be removed on September 3, 2026. Responses on those paths carry Deprecation and Sunset headers. Migration is a base-URL change only: point your Anthropic SDK at https://api.therouter.ai β€” the SDK appends /v1/messages itself.

Request Parameters

NameTypeRequiredDescription
model
stringRequiredAnthropic model ID, for example anthropic/claude-sonnet-4.5.
messages
arrayRequiredAnthropic-formatted message list.
max_tokens
integerRequiredMaximum tokens to generate.
system
string | arraySystem prompt string or array of system content blocks.
temperature
numberSampling temperature between 0 and 1.
top_p
numberNucleus sampling threshold.
top_k
integerTop-K sampling: only consider the K most likely tokens.
stop_sequences
arraySequences that will cause the model to stop generating.
stream
booleanIf true, returns a streaming SSE response. Defaults to false.
metadata
objectArbitrary metadata object passed through with the request.
tools
arrayTool definitions available to the model (Anthropic tool format).
tool_choice
objectHow the model selects tools: {"type": "auto"}, {"type": "any"}, or {"type": "tool", "name": "..."}.
thinking
objectExtended thinking controls, e.g. {"type": "enabled", "budget_tokens": 4096}. This endpoint takes the native Anthropic thinking block β€” the normalized reasoning object is an OpenAI-compatible-endpoint parameter (/v1/chat/completions) and is not translated here. On Claude 4.6+ models thinking is adaptive β€” the model self-selects its reasoning depth and budget_tokens does not apply.

Authentication

This endpoint accepts both Authorization: Bearer and x-api-key headers. Use x-api-key for drop-in compatibility with the native Anthropic SDK.

Request Example

bash
curl -X POST https://api.therouter.ai/v1/messages \
  -H "x-api-key: $THEROUTER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "anthropic/claude-sonnet-4.5",
    "max_tokens": 256,
    "messages": [{"role": "user", "content": "Explain retrieval augmented generation."}]
  }'

Response

json
{
  "id": "msg_abc123",
  "type": "message",
  "role": "assistant",
  "content": [{"type": "text", "text": "RAG combines..."}],
  "model": "anthropic/claude-sonnet-4.5",
  "stop_reason": "end_turn",
  "usage": {"input_tokens": 22, "output_tokens": 81}
}

Streaming

Set stream: true to receive the response as server-sent events (SSE). The gateway supports two routing paths, both producing Anthropic-format SSE events:

NameTypeRequiredDescription
Native passthrough
When the resolved provider is Anthropic, events are streamed directly from the upstream API.
Translation path
When routing to a non-Anthropic provider, the gateway translates OpenAI SSE chunks into Anthropic-format events in real time.

Events follow the standard Anthropic streaming format:

text
event: message_start
event: content_block_start
event: content_block_delta     # repeated for each text chunk
event: content_block_stop
event: message_delta           # final usage and stop_reason
event: message_stop
Notes
Use this route when migrating existing Anthropic SDK payloads. Set your SDK base URL to https://api.therouter.ai (the SDK appends /v1/messages itself) and use your TheRouter API key.
Help & contact