Messages
Claude Messages
Messages
POST /v1/messages — the Claude native protocol endpoint
POST
Messages
The Claude native protocol endpoint, fully compatible with Anthropic’s official API, with advanced features not in the OpenAI protocol such as
The response includes an extra
See Reasoning & thinking.
See Cache billing.
Or base64:
The assistant content in the response includes a
Return the execution result via a user message:
cache_control and thinking.
Request
Headers
| Header | Required | Description |
|---|---|---|
x-api-key | ✅ | The sk- key issued by OpenPAI |
anthropic-version | ✅ | API version, currently 2023-06-01 |
anthropic-beta | Experimental features, e.g. prompt-caching-2024-07-31 | |
Content-Type | ✅ | application/json |
Body fields
| Field | Type | Required | Description |
|---|---|---|---|
model | string | ✅ | Claude model ID |
messages | array | ✅ | Conversation history; role must alternate user / assistant |
max_tokens | integer | ✅ | Maximum output tokens |
system | string | array | System prompt; array form can carry cache_control | |
temperature | number | 0-1 | |
top_p | number | ||
top_k | integer | ||
stop_sequences | array | Stop sequences | |
stream | boolean | SSE stream | |
tools | array | Tool definitions | |
tool_choice | object | {type:"auto"} / {type:"any"} / {type:"tool",name:"x"} | |
thinking | object | { type:"enabled", budget_tokens: 8000 } | |
metadata | object | { user_id: "..." } |
content structure
Claude’scontent can be a string or a block array. Block types:
text— plain textimage— image (source.typeisbase64orurl)tool_use— a model-initiated tool call (assistant message)tool_result— a tool’s returned result (user message)thinking— a thinking block (thinking-mode response)document— documents like PDF
Response
stop_reason: end_turn / max_tokens / stop_sequence / tool_use.
Streaming response
Withstream: true, events are pushed as SSE:
Thinking mode
claude-sonnet-4-6 and claude-haiku-4-5 use extended thinking (thinking + budget_tokens); claude-opus-4-8 uses adaptive thinking (effort, defaults to high):
thinking block:
Prompt caching
Vision
Tools
tool_use block: