Anthropic Messages
Create Anthropic-compatible messages with native response and streaming event shapes.
POST /v1/messages
Creates a message using the Anthropic protocol. The incoming protocol controls the request, response, stream, and error shapes; it does not restrict routing to Anthropic-owned models.
POST /v1/messages
x-api-key: $API_KEY
anthropic-version: 2023-06-01
Content-Type: application/jsonAuthorization: Bearer $API_KEY is also accepted. The platform controls the protocol version used for the selected upstream endpoint.
Request body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Complete public model ID. |
messages | array | Yes | Non-empty sequence of user and assistant messages. |
max_tokens | integer | Yes | Maximum tokens to generate. |
system | string or array | No | System prompt or system content blocks. |
stream | boolean | No | Return Anthropic SSE events when true. |
temperature | number | No | Sampling temperature supported by the model. |
top_p | number | No | Nucleus sampling value. |
top_k | integer | No | Model-specific top-k sampling value. |
stop_sequences | string[] | No | Custom stop sequences. |
tools | array | No | Anthropic function tool declarations. |
tool_choice | object | No | auto, any, none, or a named tool choice. |
metadata | object | No | Provider-compatible request metadata. |
Message content can be a string or an array of content blocks. Common block types are text, image, tool_use, and tool_result. URL and base64 image sources are accepted when the selected model supports vision.
Sampling on current Claude models
Claude 4.7 and later models, and Claude Mythos Preview, reject non-default
temperature, top_p, and top_k. Omit all three for those models and use
prompting to control behavior.
Request example
curl "http://127.0.0.1:11113/v1/messages" -H "x-api-key: $API_KEY" -H "anthropic-version: 2023-06-01" -H "Content-Type: application/json" -d '{
"model": "anthropic/claude-sonnet-4-5",
"max_tokens": 256,
"system": "Answer concisely.",
"messages": [
{"role": "user", "content": "What is a model gateway?"}
]
}'Synchronous response
{
"id": "msg_01J...",
"type": "message",
"role": "assistant",
"model": "anthropic/claude-sonnet-4-5",
"content": [
{
"type": "text",
"text": "A model gateway provides one API over multiple AI models."
}
],
"stop_reason": "end_turn",
"stop_sequence": null,
"stop_details": null,
"usage": {
"input_tokens": 12,
"output_tokens": 13
}
}The content field is always an array. Tool requests use tool_use blocks. Reasoning-capable responses can include thinking blocks when the selected model and route expose them. Native refusal responses use stop_reason: "refusal" and can include stop_details with the policy category.
Streaming response
Set stream: true to receive Anthropic event names and payloads. A normal stream follows this lifecycle:
message_start- One or more
content_block_start,content_block_delta, andcontent_block_stopgroups message_deltawith the stop reason and final usagemessage_stop
event: content_block_delta
data: {"type":"content_block_delta","index":0,"delta":{"type":"text_delta","text":"Hello"}}
event: message_stop
data: {"type":"message_stop"}Compatibility and restrictions
Same-protocol routes preserve Anthropic fields such as thinking, cache controls, metadata, and provider extensions. Cross-protocol conversion maps system instructions, text and image blocks, tool use and results, function tools, tool choice, output limits, temperature, top_p, stop sequences, stream events, and usage. Nonportable fields can be omitted and reported in x-dropped-params.
Anthropic content blocks have no compatible field for Gemini thought signatures. Multi-turn Gemini function calling through the Messages dialect can therefore fail when the upstream requires that signature; use Gemini Generate Content or another native-compatible route for that workflow.
Missing model, empty messages, or missing max_tokens returns 400 invalid_request. /v1/messages/count_tokens is not exposed. Client routing fields and paid service-tier selections are rejected.
Help us improve this page
Found something unclear, outdated, or incorrect?
Last updated on