v1

latestOpenAPI 3.1.02026-07-267724480.0 KB

Anthropic Messages

Send structured messages to Claude models using the Anthropic native API format. Supports text and multimodal inputs, multi-turn conversations, adaptive thinking, tool use, prompt caching, streaming, and web search. Use this endpoint when you need Claude-specific features like adaptive thinking or prompt caching that are not available through the OpenAI-compatible endpoint.

post/v1/messages

Headers

anthropic-versionstring
Example:2023-06-01

The Anthropic API version to use. Defaults to 2023-06-01.

anthropic-betastring

Comma-separated list of beta features to enable. Examples: max-tokens-3-5-sonnet-2024-07-15, pdfs-2024-09-25, output-128k-2025-02-19.

Request body

modelstring required

The Claude model to use. See the Models page for available Claude model IDs.

max_tokensinteger required

The maximum number of tokens to generate. The model may stop before reaching this limit. When using thinking, the thinking tokens count towards this limit.

temperaturenumber

Model-dependent sampling control. Many newer Claude models reject non-default temperature values on the Messages API. Omit this field unless you have verified that the selected model accepts it; if the model returns an unsupported or deprecated-parameter error, remove the field instead of substituting another sampling value.

top_pnumber

Model-dependent nucleus sampling control. Many newer Claude models reject non-default top_p values on the Messages API. Omit this field unless you have verified support for the selected model. Do not set temperature and top_p together.

top_kinteger

Model-dependent top-k sampling control. Many newer Claude models reject non-default top_k values on the Messages API. Omit this field unless you have verified support for the selected model.

streamboolean

If true, stream the response incrementally using Server-Sent Events (SSE). Events include message_start, content_block_start, content_block_delta, content_block_stop, message_delta, and message_stop.

stop_sequencesstring[]

Custom strings that cause the model to stop generating when encountered. The stop sequence is not included in the response.

service_tier'auto' | 'standard_only'

The service tier to use. auto tries priority capacity first, standard_only uses only standard capacity.

Example request

{
  "model": "claude-sonnet-5",
  "max_tokens": 1024,
  "temperature": 1,
  "top_p": 1,
  "output_config": {
    "effort": "medium"
  }
}

Response

Successful response. When stream is true, the response is a stream of SSE events.

idstring

Unique identifier for this message (e.g., msg_01XFDUDYJgAACzvnptvVoYEL).

type'message'

Always message.

role'assistant'

Always assistant.

modelstring

The specific model version that generated this response, such as claude-sonnet-5.

stop_reason'end_turn' | 'max_tokens' | 'stop_sequence' | 'tool_use' | 'pause_turn' | 'refusal'

Why the model stopped generating. refusal can be returned as a successful HTTP response when the model declines a request.

stop_sequencestring nullable

The stop sequence that caused the model to stop, if applicable.