claude-haiku-4-5,同时支持 OpenAI 兼容的 Chat Completions API。
核心能力
- Messages API - 使用 Anthropic 原生请求与响应格式
- OpenAI 兼容 - 也可通过 Chat Completions 调用
- 流式输出 - 通过 SSE 增量返回内容
- 系统提示词 - 使用顶层 system 指令
- 工具调用 - 支持 Anthropic 工具定义
快速示例
Messages API
- cURL
- Python
- Streaming
curl "https://api.mixroute.ai/v1/messages" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-haiku-4-5",
"max_tokens": 256,
"messages": [
{
"role": "user",
"content": "Explain quantum entanglement in simple terms."
}
]
}'
from anthropic import Anthropic
client = Anthropic(api_key="YOUR_API_KEY", base_url="https://api.mixroute.ai")
message = client.messages.create(
model="claude-haiku-4-5",
max_tokens=256,
messages=[{"role": "user", "content": "Explain quantum entanglement in simple terms."}],
)
print(message.content[0].text)
from anthropic import Anthropic
client = Anthropic(api_key="YOUR_API_KEY", base_url="https://api.mixroute.ai")
with client.messages.stream(
model="claude-haiku-4-5",
max_tokens=256,
messages=[{"role": "user", "content": "Write a short poem about the sea."}],
) as stream:
for text in stream.text_stream:
print(text, end="")
OpenAI 兼容 API
- cURL
- Python
- Streaming
curl "https://api.mixroute.ai/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "claude-haiku-4-5",
"messages": [
{
"role": "user",
"content": "Explain quantum entanglement in simple terms."
}
],
"max_tokens": 256
}'
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.mixroute.ai/v1")
response = client.chat.completions.create(
model="claude-haiku-4-5",
messages=[{"role": "user", "content": "Explain quantum entanglement in simple terms."}],
max_tokens=256,
)
print(response.choices[0].message.content)
from openai import OpenAI
client = OpenAI(api_key="YOUR_API_KEY", base_url="https://api.mixroute.ai/v1")
stream = client.chat.completions.create(
model="claude-haiku-4-5",
messages=[{"role": "user", "content": "Write a short poem about the sea."}],
max_tokens=256,
stream=True,
)
for chunk in stream:
print(chunk.choices[0].delta.content or "", end="")
参数
Messages API
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 固定为 claude-haiku-4-5。 |
messages | array | 是 | 包含 role 与 content 的输入消息。 |
max_tokens | integer | 是 | 最大生成 token 数。 |
system | string | array | 否 | 顶层系统指令。 |
stream | boolean | 否 | 启用 SSE 流式输出。 |
tools | array | 否 | Anthropic 工具定义。 |
thinking | object | 否 | 模型支持时使用的扩展思考配置。 |
OpenAI 兼容 API
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 固定为 claude-haiku-4-5。 |
messages | array | 是 | 包含 role 与 content 的对话消息。 |
max_tokens | integer | 否 | 最大生成 token 数。 |
stream | boolean | 否 | 启用 SSE 流式输出,默认 false。 |
temperature | number | 否 | 模型支持时用于控制采样随机性。 |
top_p | number | 否 | 模型支持时使用的核采样阈值。 |
stop | string | array | 否 | 触发停止生成的序列。 |
tools | array | 否 | OpenAI 兼容工具定义。 |