Anthropic Python SDK 通过 NordRouter
设置:
bash
pip install anthropic为了Anthropic SDK 基础URL,输出 无 /v1:
python
import os
from anthropic import Anthropic
client = Anthropic(
api_key=os.environ["NORDROUTER_API_KEY"],
base_url="https://nordrouter.com",
)
response = client.messages.create(
model="anthropic/claude-sonnet-4.6",
max_tokens=256,
messages=[{"role": "user", "content": "Ответь: работает"}],
)
print(response.content[0].text)无机的 AsyncAnthropic 得到了相同的 api_key 和 base_url;通过 messages.create 调用的呼叫是通过 await..