Curl / SDK 呼叫範例(Anthropic 相容介面)
想在自己的程式或腳本裡直接呼叫?NextHub 介面完全相容 Anthropic 官方格式,遷移成本為零。
Curl 命令列範例
bash
curl https://api.nexthub.cc/v1/messages \
-H "Content-Type: application/json" \
-H "x-api-key: 你的ApiKey" \
-H "anthropic-version: 2023-06-01" \
-d '{
"model": "claude-opus-5-5",
"max_tokens": 1024,
"messages": [
{ "role": "user", "content": "你好,介紹一下你自己" }
]
}'Python SDK 範例
python
import anthropic
client = anthropic.Anthropic(
api_key="你的 NextHub ApiKey",
base_url="https://api.nexthub.cc",
)
message = client.messages.create(
model="claude-opus-5-5",
max_tokens=1024,
messages=[{"role": "user", "content": "你好!"}]
)
print(message.content)Node.js SDK 範例
javascript
import Anthropic from '@anthropic-ai/sdk';
const client = new Anthropic({
apiKey: '你的 NextHub ApiKey',
baseURL: 'https://api.nexthub.cc',
});
const message = await client.messages.create({
model: 'claude-opus-5-5',
max_tokens: 1024,
messages: [{ role: 'user', content: '你好!' }],
});
console.log(message.content);無縫遷移
把官方文件裡的 https://api.anthropic.com 替換為 https://api.nexthub.cc,其他參數一字不改即可正常使用。