Skip to main content
POST
Claude Messages API
  • Fully compatible with Claude Messages API format
  • Supports multi-turn conversations and single queries
  • Supports multimodal content including text and images
For parameter details, see the official Anthropic Messages API documentation: https://platform.claude.com/docs/en/api/messages/create

Usage Examples

Basic Conversation

Streaming Response

Tool Use

Structured Output With Cache

Vision Understanding

Notes

  • Use max_tokens to control the output length.
  • Thinking tokens count toward max_tokens.
  • Image input can use supported base64 media payloads.

Authorizations

x-api-key
string
header
required

API key for authentication.

Visit the API Key Management Page to get your API Key

Add to the request header:

Body

application/json
model
string
required

Model name. Example: claude-sonnet-4-5-20250929.

Example:

"claude-sonnet-4-5-20250929"

messages
object[]
required

List of conversation messages in order. Each message contains a role and content. Use user for user input and assistant for previous model output in multi-turn conversations. Example: [{"role": "user", "content": "Summarize the purpose of feature canary releases in two sentences."}].

max_tokens
integer

Maximum number of tokens to generate.

Required range: x >= 1
Example:

1024

system

System prompt for the assistant. Supports a string or structured text blocks.

Example:

"You are a product announcement editor, keep it objective and concise."

cache_control
object

Top-level cache control automatically applies a cache_control marker to the last cacheable block in the request.

stream
boolean

Whether to use streaming output.

Example:

false

stop_sequences
string[]

Stop sequences. The model stops when it encounters any of these strings.

metadata
object

Additional metadata such as user_id.

output_config
object

Configuration options for the model's output, such as output format and effort level.

thinking
object

Configuration for Claude extended thinking. Use this field with the claude-opus-4-7-thinking model. Thinking tokens count toward max_tokens.

tools
object[]

Tool definitions available to the model.

tool_choice

Controls tool usage behavior. Examples: auto, or an object such as {"type": "tool", "name": "get_weather"}.

Example:

"auto"

Response

200 - application/json

Message created

code
integer
Example:

200

data
object