Create Message
API Reference
Messages API
Create a message with the Anthropic Messages format
POST
Create Message
Send a structured conversation to a model and receive an assistant message. Models trained for alternating turns expect
user and assistant messages; a top-level system field sets standing instructions.
Create a message
POST /v1/messages
Headers
*Provide one of
Authorization or x-api-key.
Body parameters
string
required
Model ID. Examples:
claude-sonnet-4-5-20250929, kimi-k2.6:dev.array
required
Input turns. Each item has
role and content.role:user,assistant, orsystem(mid-conversation system instruction; cannot be the first entry)content: string, or an array of content blocks (see below)
assistant, generation continues from that partial reply.integer
Maximum number of tokens to generate before stopping. Required by many Anthropic clients; omit only when the client supplies a default.
string | array
Standing system prompt for the whole conversation.
- string: plain text
- array: list of
{ "type": "text", "text": "...", "cache_control"?: { "type": "ephemeral", "ttl"?: "5m" \| "1h" } }blocks
messages[0].role = "system"; use this field instead.object
Extended thinking configuration.
display is "summarized" or "omitted". When thinking is enabled, assistant content may include thinking blocks (with signature) before text / tool_use.array
Tools the model may call. Each custom tool:
name(string, required)description(string)input_schema(JSON Schema object)- optional:
cache_control,strict,defer_loading,eager_input_streaming,allowed_callers,input_examples
type (for example bash_20250124) and omit input_schema.object
How the model should use tools:
{ "type": "auto" }{ "type": "any" }{ "type": "tool", "name": "<tool_name>" }{ "type": "none" }
number
Sampling temperature. Range depends on the upstream model (commonly 0 to 1).
number
Nucleus sampling.
0 is ignored.integer
Top-k sampling.
0 is ignored.array
Custom strings that stop generation when emitted.
boolean
If
true, respond with server-sent events. Default false.object
Optional
{ "user_id": string } for abuse tracking. Opaque ID only; do not put PII.array
Anthropic beta feature flags. Accepted and forwarded when relevant.
object
Server-side context edits, for example:
object
Output controls such as
{ "effort": "low" | "medium" | "high" }.Content blocks
content may be a string (shorthand for one text block) or an array of blocks.
User / mid-conversation system
Server tool result types (for example
web_search_tool_result) are accepted as passthrough blocks.
Assistant
On multi-turn requests, include the full previous assistant
content array (including thinking blocks) so reasoning continuity is preserved.
Response
Non-streaming responses are Anthropic message objects:stop_reason is typically end_turn, max_tokens, stop_sequence, or tool_use.
Errors use Anthropic’s envelope:
Example
Count tokens
POST /v1/messages/count_tokens
Estimate input tokens for a Messages request without running inference.
Body
Same shape as Create a message: at leastmodel and messages. system, tools, and related fields are included in the estimate when present.
Response
Authorizations
Enter your API key (starts with 'ek-')
Body
application/json
Model ID
Example:
"claude-sonnet-4-5-20250929"
Conversation turns
Maximum tokens to generate
Required range:
0 <= x <= 1Top-level system prompt
Available options:
auto, any, none - Option 1
- Option 2
Ignored for models that do not support reasoning_effort
Available options:
none, minimal, low, medium, high, xhigh Response
200 - application/json
Success
Available options:
message Available options:
assistant - Option 1
- Option 2
- Option 3
- Option 4
- Option 5
- Option 6
Available options:
end_turn, max_tokens, stop_sequence, tool_use 