Create Anthropic Messages
OpenAI-compatible gateway endpoint for Anthropic Messages API payloads.
POST/v1/anthropic/messages
Request Parameters
| Name | Type | Required | Description |
|---|---|---|---|
model | string | Required | Anthropic model ID, for example anthropic/claude-sonnet-4.5. |
messages | array | Required | Anthropic-formatted message list. |
max_tokens | integer | Required | Maximum tokens to generate. |
system | string | array | System prompt string or array of system content blocks. | |
temperature | number | Sampling temperature between 0 and 1. | |
top_p | number | Nucleus sampling threshold. | |
top_k | integer | Top-K sampling: only consider the K most likely tokens. | |
stop_sequences | array | Sequences that will cause the model to stop generating. | |
stream | boolean | If true, returns a streaming SSE response. Defaults to false. | |
metadata | object | Arbitrary metadata object passed through with the request. | |
tools | array | Tool definitions available to the model (Anthropic tool format). | |
tool_choice | object | How 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:
| Name | Type | Required | Description |
|---|---|---|---|
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_stopNotes
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.