通过 TokenHub 统一的 /chat/completions 端点调用 Anthropic Claude model。请求和响应格式完全 OpenAI-compatible——无需迁移 SDK。支持流式输出、tool 调用(function calling)和视觉(图片输入)。按 model 阶梯进行按 token 计费。
th-xxxxxxxxxxxx...)https://tokenhub.store/api/v1在 Authorization 请求头中传入 API Key:
Authorization: Bearer th-your-api-keyPOST/chat/completions聊天补全。与 OpenAI /v1/chat/completions 的 schema 完全一致,包含流式输出、工具使用、视觉和 JSON 模式。
价格按每 100 万 tokens 计费(USD)。仅成功的调用才会计费。支持标准 ID 和 anthropic/* 别名。
| 层级 | 模型 ID | 输入 | 输出 | 备注 |
|---|---|---|---|---|
| Opus 4.7 | anthropic/claude-opus-4-7 | $5.00 | $25.00 | 最新,推理与编码质量最高。 |
| Opus 4.6 | anthropic/claude-opus-4-6 | $5.00 | $25.00 | 最新,推理与编码质量最高。 |
| Sonnet 4.6 | anthropic/claude-sonnet-4-6 | $3.00 | $15.00 | 旗舰级平衡方案,兼顾质量与成本(推荐默认)。 |
| Haiku 4.5 | anthropic/claude-haiku-4-5 | $1.00 | $5.00 | 速度最快、价格最低的第 4 代;非常适合高 QPS 和分类任务。 |
| Sonnet 4.5 | anthropic/claude-sonnet-4-5 | $3.00 | $15.00 | 上一代通用主力模型。 |
| Opus 4.5 | anthropic/claude-opus-4-5 | $5.00 | $25.00 | 最新,推理与编码质量最高。 |
| Sonnet 4 | anthropic/claude-4-sonnet | $3.00 | $15.00 | 上一代通用主力模型。 |
| Opus 4 | anthropic/claude-4-opus | $15.00 | $75.00 | 最新,推理与编码质量最高。 |
| 3.5 Sonnet | anthropic/claude-3-5-sonnet-latest | $3.00 | $15.00 | 稳定、经过生产验证;兼容性广泛。 |
| 3.5 Haiku | anthropic/claude-3-5-haiku-latest | $0.80 | $4.00 | 稳定、经过生产验证;兼容性广泛。 |
| 参数 | 类型 | 必填 | 默认值 | 描述 |
|---|---|---|---|---|
| model | string | 必填 | — | Claude model ID。示例:"anthropic/claude-sonnet-4-6"。支持 anthropic/* 前缀形式和不带前缀的简写名称。 |
| messages | array | 必填 | — | 聊天历史。每一项为 { role, content }。role ∈ system | user | assistant。content 可以是字符串或部件数组(用于视觉 / 工具结果)。 |
| max_tokens | integer | 可选 | 1024 | 最大输出 tokens(Claude 需要此参数)。通常为 1024–4096。 |
| temperature | number | 可选 | 1.0 | 采样 temperature,0.0–1.0。越低越确定性。 |
| top_p | number | 可选 | 1.0 | 核采样。使用 temperature 或 top_p,二选一。 |
| stream | boolean | 可选 | false | 如果为 true,将返回 Server-Sent Events (SSE) 增量。 |
| stop | string[] | 可选 | — | 最多 4 个停止序列。 |
| tools | array | 可选 | — | 用于工具使用(function calling)的工具 / function 定义列表。 |
| tool_choice | string|object | 可选 | auto | 控制工具选择:auto | none | required | { type:'function', function:{ name } }。 |
| response_format | object | 可选 | — | JSON 模式:{ "type": "json_object" } 会强制 model 返回有效 JSON。 |
| user | string | 可选 | — | 可选的终端用户 ID,用于你自己的追踪。 |
curl https://tokenhub.store/api/v1/chat/completions \
-H "Authorization: Bearer th-your-api-key" \
-H "Content-Type: application/json" \
-d '{
"model": "anthropic/claude-sonnet-4-6",
"messages": [
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain CAP theorem in 3 bullets."}
],
"max_tokens": 512,
"temperature": 0.3
}'from openai import OpenAI
client = OpenAI(
api_key="th-your-api-key",
base_url="https://tokenhub.store/api/v1",
)
resp = client.chat.completions.create(
model="anthropic/claude-sonnet-4-6",
max_tokens=512,
temperature=0.3,
messages=[
{"role": "system", "content": "You are a concise assistant."},
{"role": "user", "content": "Explain CAP theorem in 3 bullets."},
],
)
print(resp.choices[0].message.content)
print("usage:", resp.usage)import OpenAI from "openai";
const client = new OpenAI({
apiKey: "th-your-api-key",
baseURL: "https://tokenhub.store/api/v1",
});
const resp = await client.chat.completions.create({
model: "anthropic/claude-sonnet-4-6",
max_tokens: 512,
temperature: 0.3,
messages: [
{ role: "system", content: "You are a concise assistant." },
{ role: "user", content: "Explain CAP theorem in 3 bullets." },
],
});
console.log(resp.choices[0].message.content);
console.log("usage:", resp.usage);注册 TokenHub,开始通过我们的 OpenAI-compatible API 调用 Claude