Skip to Content
APIAnthropic NativeMessages

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/messages

Authentication

The Anthropic protocol uses the x-api-key header:

x-api-key: <your HAOAI_API_KEY> anthropic-version: 2023-06-01

Request Parameters

ParameterTypeRequiredDescription
modelstring✅Model identifier, e.g. anthropic/claude-fable-5-1
max_tokensnumber✅Maximum tokens to generate
messagesarray✅Message array
systemstring—System prompt
temperaturenumber—Sampling temperature 0-1
top_pnumber—Nucleus sampling parameter
top_knumber—Top-K sampling
streamboolean—Enable streaming response
toolsarray—Tool definitions
tool_choiceobject—Tool selection strategy
thinkingobject—Claude thinking configuration; valid values depend on the model version
output_configobject—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.

ModelRecommended configurationNotes
anthropic/claude-sonnet-4.5, anthropic/claude-haiku-4.5Manual thinkingUse enabled + budget_tokens; does not support adaptive
anthropic/claude-sonnet-4.6, anthropic/claude-opus-4.6Adaptive thinkingUse adaptive; manual budget_tokens still works, but is no longer recommended
anthropic/claude-opus-4.7+Adaptive thinkingUse 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

Terminal
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-fable-5-1", "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-fable-5-1", "stop_reason": "end_turn", "usage": { "input_tokens": 25, "output_tokens": 200 } }

Streaming

anthropic_stream.py
with client.messages.stream( model="anthropic/claude-fable-5-1", 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

ModelDescription
anthropic/claude-fable-5-1Claude Fable 5.1 — Flagship capability
anthropic/claude-sonnet-5Claude Sonnet 5 — Balanced performance
anthropic/claude-sonnet-4.5Claude Sonnet 4.5 — Supports manual thinking
anthropic/claude-haiku-4.5Claude 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.