Messages API
Create Claude conversations through the Anthropic native protocol. HaoAI is fully compatible with the Anthropic Messages API, so you can use the official SDK directly.
Endpoint
POST https://api.hao.ai/anthropic/v1/messagesAuthentication
The Anthropic protocol uses the x-api-key header:
x-api-key: <your HAOAI_API_KEY>
anthropic-version: 2023-06-01Request Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
model | string | ✅ | Model identifier, e.g. anthropic/claude-sonnet-4.6 |
max_tokens | number | ✅ | Maximum tokens to generate |
messages | array | ✅ | Message array |
system | string | — | System prompt |
temperature | number | — | Sampling temperature 0-1 |
top_p | number | — | Nucleus sampling parameter |
top_k | number | — | Top-K sampling |
stream | boolean | — | Enable streaming response |
tools | array | — | Tool definitions |
tool_choice | object | — | Tool selection strategy |
thinking | object | — | Claude thinking configuration; valid values depend on the model version |
output_config | object | — | Output configuration for Claude 4.6+ adaptive thinking, such as effort |
Message Format
interface Message {
role: 'user' | 'assistant'
content: string | ContentBlock[]
}
type ContentBlock =
| { type: 'text'; text: string }
| { type: 'image'; source: { type: 'base64'; media_type: string; data: string } }
| { type: 'tool_use'; id: string; name: string; input: object }
| { type: 'tool_result'; tool_use_id: string; content: string }Claude Thinking Modes
Claude thinking parameters differ by model version. Configure thinking for the exact model you call, and do not send adaptive or budget_tokens to models that do not support them.
| Model | Recommended configuration | Notes |
|---|---|---|
anthropic/claude-sonnet-4.5, anthropic/claude-haiku-4.5 | Manual thinking | Use enabled + budget_tokens; does not support adaptive |
anthropic/claude-sonnet-4.6, anthropic/claude-opus-4.6 | Adaptive thinking | Use adaptive; manual budget_tokens still works, but is no longer recommended |
anthropic/claude-opus-4.7+ | Adaptive thinking | Use adaptive only; does not support manual budget_tokens |
budget_tokens must be less than max_tokens. Thinking consumes output tokens and is billed as output usage. If you only need the final answer, use display: "omitted" where supported to avoid returning thinking text.
Manual Thinking: Sonnet 4.5 / Haiku 4.5
claude-sonnet-4.5 and claude-haiku-4.5 use manual thinking and require an explicit budget_tokens value.
{
"model": "anthropic/claude-sonnet-4.5",
"max_tokens": 16000,
"thinking": {
"type": "enabled",
"budget_tokens": 10000
},
"messages": [
{
"role": "user",
"content": "Analyze this complex problem in depth..."
}
]
}Adaptive Thinking: Sonnet 4.6 / Opus 4.6
claude-sonnet-4.6 and claude-opus-4.6 should use adaptive thinking. Set output_config.effort to low, medium, or high based on task complexity.
{
"model": "anthropic/claude-sonnet-4.6",
"max_tokens": 16000,
"thinking": {
"type": "adaptive"
},
"output_config": {
"effort": "medium"
},
"messages": [
{
"role": "user",
"content": "Analyze this complex problem in depth..."
}
]
}Opus 4.7+: Do Not Use budget_tokens
claude-opus-4.7+ should continue to use thinking: {"type":"adaptive"}. Do not send manual budget_tokens to these models, or the upstream provider may return a parameter error.
Request Examples
cURL
curl https://api.hao.ai/anthropic/v1/messages \
-H "x-api-key: $HAOAI_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4.6",
"max_tokens": 1024,
"system": "You are a professional programming assistant.",
"messages": [
{"role": "user", "content": "Write a quicksort in Python"}
]
}'Response Format
{
"id": "msg_abc123",
"type": "message",
"role": "assistant",
"content": [
{
"type": "text",
"text": "Here's a Python quicksort implementation..."
}
],
"model": "anthropic/claude-sonnet-4.6",
"stop_reason": "end_turn",
"usage": {
"input_tokens": 25,
"output_tokens": 200
}
}Streaming
Python
with client.messages.stream(
model="anthropic/claude-sonnet-4.6",
max_tokens=1024,
messages=[{"role": "user", "content": "Tell me a story"}]
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)Supported Models
| Model | Description |
|---|---|
anthropic/claude-opus-4.6 | Claude Opus 4 — Most capable |
anthropic/claude-sonnet-4.6 | Claude Sonnet 4 — Balanced performance |
anthropic/claude-sonnet-4.5 | Claude Sonnet 4.5 — Supports manual thinking |
anthropic/claude-haiku-4.5 | Claude Haiku 4.5 — Fast responses |
HaoAI’s Anthropic protocol supports all native features, including Vision, Tool Use, Prompt Caching, Extended Thinking, and more. For the complete available model list, use the Models API or Model Plaza.