透過 TokenHub 統一的 /chat/completions endpoint 呼叫 Anthropic Claude models。完整相容 OpenAI-compatible 的請求與回應格式 — 無需遷移 SDK。支援串流、tool use(function calling)以及 vision(image input)。依 model tier 以每 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 為字串或 parts 陣列(用於視覺 / 工具結果)。 |
| max_tokens | integer | 選填 | 1024 | 最大輸出 tokens(Claude 需要此參數)。通常為 1024–4096。 |
| temperature | number | 選填 | 1.0 | Sampling temperature, 0.0–1.0. Lower = more deterministic. |
| top_p | number | 選填 | 1.0 | 核採樣。請使用 temperature 或 top_p,其一即可,不要同時使用。 |
| stream | boolean | 選填 | false | 若為 true,回傳 Server-Sent Events(SSE)增量。 |
| stop | string[] | 選填 | — | 最多 4 個停止序列。 |
| tools | array | 選填 | — | 工具 / 函式定義清單,用於工具使用(function calling)。 |
| tool_choice | string|object | 選填 | auto | 控制工具選擇:auto | none | required | { type:'function', function:{ name } }。 |
| response_format | object | 選填 | — | JSON mode: { "type": "json_object" } forces the model to return valid 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