Messages (Anthropic)
Uses the Messages protocol format — for Claude-family models and any SDK or client that speaks it.
POST https://wrouter.ai/v1/messagesHeaders
| Header | Required | Notes |
|---|---|---|
Authorization | ✓* | Bearer sk-... |
x-api-key | ✓* | sk-... (alternative to Authorization) |
anthropic-version | ✓ | e.g. 2023-06-01 |
Content-Type | ✓ | application/json |
*Use either Authorization or x-api-key.
Body parameters
| Parameter | Type | Required | Notes |
|---|---|---|---|
model | string | ✓ | e.g. claude-sonnet-4-5, claude-opus-4-1 |
messages | array | ✓ | Standard Messages-protocol structure |
max_tokens | integer | ✓ | |
system | string | array | System prompt | |
temperature | number | ||
top_p | number | ||
top_k | integer | ||
stream | boolean | SSE streaming | |
stop_sequences | array | ||
tools | array | Anthropic tool defs | |
tool_choice | object | {"type":"auto"|"any"|"tool","name":"..."} | |
thinking | object | Extended thinking, e.g. {"type":"enabled","budget_tokens":10000} | |
cache_control | object | Prompt caching to save cost | |
context_management | object | Long-conversation context strategy | |
output_config | object | Output configuration | |
output_format | object | Output format constraints (e.g. structured output) | |
mcp_servers | array | MCP (Model Context Protocol) server list | |
container | string | object | Tool execution container | |
inference_geo | string | Inference region hint | |
metadata | object | {"user_id": "..."} | |
speed | string | "standard" | "fast" | |
service_tier | string | "auto" | "standard_only" |
Field semantics follow the Messages protocol spec.
Examples
bash
curl https://wrouter.ai/v1/messages \
-H "x-api-key: $WROUTER_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 1024,
"messages": [{"role":"user","content":"Introduce WRouter in one sentence."}]
}'Python (anthropic SDK)
python
import anthropic
client = anthropic.Anthropic(
api_key="sk-...",
base_url="https://wrouter.ai",
)
resp = client.messages.create(
model="claude-sonnet-4-5",
max_tokens=1024,
messages=[{"role": "user", "content": "Hello"}],
)
print(resp.content[0].text)Response
Response shape:
json
{
"id": "msg_xxx",
"type": "message",
"role": "assistant",
"content": [{"type":"text","text":"Hello! ..."}],
"model": "claude-sonnet-4-5",
"stop_reason": "end_turn",
"usage": {"input_tokens": 12, "output_tokens": 24}
}Streaming follows the Messages SSE event protocol: message_start, content_block_delta, message_delta, message_stop.
Cross-vendor calls
You may pass non-Claude IDs (e.g. gpt-4o) to /v1/messages — WRouter translates protocols. For non-Claude models, however, /v1/chat/completions exposes more native features.