Anthropic Messages API

Chat with the Claude family of models using the native Anthropic Messages API format

POST/v1/messages
  • Compatible with the native Anthropic Messages API format
  • Works directly with the official Anthropic SDKs (Python / JavaScript) — just change the base_url
  • Supports streaming output (SSE)
  • Supports multi-turn conversations, system prompts, vision input, and tool calls

Note: If you're already using the OpenAI SDK, we recommend the OpenAI format endpoint. If you're using the Anthropic SDK or Claude Code, this endpoint is recommended.

Authorizations

Authorizationstring

Bearer Token authentication, for direct HTTP calls

Authorization: Bearer YOUR_API_KEY
x-api-keystring

API Key authentication, compatible with the Anthropic SDK

x-api-key: YOUR_API_KEY
anthropic-versionstringDefault 2023-06-01

Anthropic API version, passed automatically when using the Anthropic SDK

Recommended value: 2023-06-01

Body

modelstringRequired

Model name

Supports all Claude family models, for example:

  • claude-opus-4-6
  • claude-sonnet-4-6
  • claude-haiku-4-5
messagesobject[]Required

List of conversation messages, in chronological order. Only the user and assistant roles are supported; for system prompts use the top-level system field

ShowHide messages[n]
rolestringRequired

Message role, one of: user, assistant

contentstring | object[]Required

Message content, a string or an array of content blocks

ShowHide content block
typestringRequired

Content type: text or image

textstring

Text content, required when type is text

sourceobject

Image source, required when type is image

ShowHide source
typestringRequired

Image source type: base64 or url

media_typestring

MIME type, required when type is base64, e.g. image/jpeg, image/png

datastring

Base64-encoded image data, required when type is base64

urlstring

Image URL, required when type is url

max_tokensintegerRequired

Maximum number of tokens to generate

  • Claude Sonnet 4-6 supports up to 64000
  • Claude Opus 4-6 supports up to 32000
systemstring | object[]

System prompt, set at the top level (not inside messages)

Supports a string or a content-block array format

streambooleanDefault false

Whether to enable streaming output (Server-Sent Events)

  • true: stream results token by token; event format follows the Anthropic SSE spec
  • false: wait for the full response and return it all at once
temperaturenumberDefault 1

Sampling temperature, controls output randomness

Range: 0 ~ 1

top_pnumber

Nucleus sampling probability threshold

Range: 0 ~ 1. We recommend not setting both temperature and top_p at the same time

stop_sequencesstring[]

Stop sequences; generation stops when the specified string is encountered

Response

idstring

Unique identifier for this request, in the format msg_*

typestring

Object type, always message

rolestring

Response role, always assistant

contentobject[]

List of generated content blocks

  • content[].type: content type, usually text
  • content[].text: the generated text content
modelstring

The model actually used

stop_reasonstring

Reason for stopping

  • end_turn: the model finished normally
  • max_tokens: reached the max_tokens limit
  • stop_sequence: a stop sequence was triggered
usageobject

Token usage statistics for this request

  • usage.input_tokens: number of input tokens
  • usage.output_tokens: number of output tokens