Create Anthropic Messages

OpenAI-compatible gateway endpoint for Anthropic Messages API payloads.

POST/v1/anthropic/messages

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": "..."}.

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/anthropic/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/v1/anthropic and use your AI Router API key.