Skip to main content
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, or system (mid-conversation system instruction; cannot be the first entry)
  • content: string, or an array of content blocks (see below)
Consecutive same-role turns may be merged by the model. If the last message is 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
Keep the array shape when using prompt caching breakpoints. Do not put the initial system prompt as 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
Anthropic built-in tools may set 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 least model and messages. system, tools, and related fields are included in the estimate when present.

Response

Authorizations

Authorization
string
header
required

Enter your API key (starts with 'ek-')

Body

application/json
model
string
required

Model ID

Example:

"claude-sonnet-4-5-20250929"

messages
object[]
required

Conversation turns

max_tokens
integer

Maximum tokens to generate

temperature
number
Required range: 0 <= x <= 1
top_p
number
top_k
integer
stream
boolean
default:false
system

Top-level system prompt

tools
object[]
tool_choice
Available options:
auto,
any,
none
thinking
object
reasoning_effort
enum<string>

Ignored for models that do not support reasoning_effort

Available options:
none,
minimal,
low,
medium,
high,
xhigh
betas
string[]
context_management
object
output_config
object
metadata
object

Response

200 - application/json

Success

id
string
required
type
enum<string>
required
Available options:
message
role
enum<string>
required
Available options:
assistant
content
object[]
required
model
string
required
stop_reason
enum<string> | null
required
Available options:
end_turn,
max_tokens,
stop_sequence,
tool_use
usage
object
required
stop_sequence
string | null