跳到主要内容

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,其他参数一字不改即可正常使用。

NextHub · 官方号池直连 OpenAI / Anthropic,用得安心、用得省心。