Use the Anthropic SDK with BigModel.io
Call BigModel.io's Anthropic-compatible Messages API from the official Anthropic Python and TypeScript SDKs by setting base_url to https://bigmodel.io. Streaming and tool use.
On this page
BigModel.io serves the Anthropic Messages API at https://bigmodel.io/v1/messages. Point the official Anthropic SDK at the gateway root; the SDK adds /v1/messages itself.
| Setting | Value |
|---|---|
| Base URL | https://bigmodel.io (no /v1) |
| API key | your BigModel.io key (sk-...) |
| Model | a model ID from the model catalog, e.g. glm-5.3 |
The key's group must serve
/v1/messages. GLM and DeepSeek groups are Chat Completions only and return 404 here; use the OpenAI SDK with those keys.
export BIGMODEL_API_KEY="sk-..."#Install
pip install anthropicnpm install @anthropic-ai/sdk#Minimal call
import os
from anthropic import Anthropic
client = Anthropic(
base_url="https://bigmodel.io",
api_key=os.environ["BIGMODEL_API_KEY"],
)
message = client.messages.create(
model="glm-5.3",
max_tokens=512,
messages=[{"role": "user", "content": "Explain vector databases in three sentences."}],
)
print(message.content[0].text)import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic({
baseURL: "https://bigmodel.io",
apiKey: process.env.BIGMODEL_API_KEY,
});
const message = await client.messages.create({
model: "glm-5.3",
max_tokens: 512,
messages: [{ role: "user", content: "Explain vector databases in three sentences." }],
});
console.log(message.content[0].type === "text" ? message.content[0].text : message.content);api_key / apiKey is sent as x-api-key. If you prefer Authorization: Bearer, pass auth_token / authToken instead; the gateway accepts both. The SDK also reads ANTHROPIC_BASE_URL, ANTHROPIC_API_KEY and ANTHROPIC_AUTH_TOKEN from the environment, so unset stray values left over from other setups.
#Streaming
with client.messages.stream(
model="glm-5.3",
max_tokens=512,
messages=[{"role": "user", "content": "Write a haiku about latency."}],
) as stream:
for text in stream.text_stream:
print(text, end="", flush=True)const stream = client.messages.stream({
model: "glm-5.3",
max_tokens: 512,
messages: [{ role: "user", content: "Write a haiku about latency." }],
});
stream.on("text", (text) => process.stdout.write(text));
await stream.finalMessage();An error after the stream has started arrives as an SSE error event, which the SDK raises as an exception.
#Tool use
Tools use the standard Messages format. Whether a model calls tools well depends on the model; test the one you plan to use. See Tool calling.
message = client.messages.create(
model="glm-5.3",
max_tokens=512,
tools=[{
"name": "get_weather",
"description": "Get the current weather for a city",
"input_schema": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
},
}],
messages=[{"role": "user", "content": "What's the weather in Hangzhou?"}],
)
for block in message.content:
if block.type == "tool_use":
print(block.name, block.input)const message = await client.messages.create({
model: "glm-5.3",
max_tokens: 512,
tools: [{
name: "get_weather",
description: "Get the current weather for a city",
input_schema: {
type: "object",
properties: { city: { type: "string" } },
required: ["city"],
},
}],
messages: [{ role: "user", content: "What's the weather in Hangzhou?" }],
});
for (const block of message.content) {
if (block.type === "tool_use") console.log(block.name, block.input);
}When you send the history back with thinking blocks or tool IDs that don't match, the gateway returns 409 malformed_session_state. Send back the assistant content exactly as you received it.
#Prompt caching and token counting
cache_control breakpoints pass through (up to 4; extra ones are removed). Cache writes and reads are billed at the model's cache prices. client.messages.count_tokens(...) calls POST /v1/messages/count_tokens on groups that serve Messages. See Prompt caching.
#Verify the setup
Run the minimal call above, then open Usage and check that the request is listed with endpoint /v1/messages. With curl:
curl https://bigmodel.io/v1/messages \
-H "x-api-key: $BIGMODEL_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "Content-Type: application/json" \
-d '{"model":"glm-5.3","max_tokens":64,"messages":[{"role":"user","content":"ping"}]}'#Troubleshooting
404 ... platform only supports /v1/chat/completions; /v1/messages is not available. The key's group serves Chat Completions only. Use a key from a group with Messages support, or switch to the OpenAI SDK.
404 on every request. The base URL ends in /v1, so the SDK calls /v1/v1/messages. Use https://bigmodel.io.
401 INVALID_API_KEY or API_KEY_REQUIRED. The key is empty or wrong, or an old ANTHROPIC_API_KEY in your environment is being used. Run env | grep ANTHROPIC.
403 This group does not allow /v1/messages dispatch. The key's group does not allow the Messages API. Use a different group.
403 permission_error API Key is not assigned to any group. Edit the key in API Keys and pick a group.
503 No available accounts: no available accounts supporting model: .... The model ID is wrong or not served by the key's group. Copy it from the model catalog.
403 INSUFFICIENT_BALANCE or 429 API_KEY_QUOTA_EXHAUSTED. Top up in Billing or raise the key's quota. See Limits & rate limits.
#Related
- Claude Code uses the same Messages endpoint
- OpenAI SDK for Chat Completions
- LangChain (
ChatAnthropic) and Vercel AI SDK (@ai-sdk/anthropic) - Errors
Updated · View as Markdown