# 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.

Web version: https://bigmodel.io/docs/anthropic-sdk · Updated 2026-10-18

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](https://bigmodel.io/models), 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](https://bigmodel.io/docs/openai-sdk-langchain) with those keys.

```bash
export BIGMODEL_API_KEY="sk-..."
```

## Install

```bash [Python]
pip install anthropic
```

```bash [TypeScript]
npm install @anthropic-ai/sdk
```

## Minimal call

```python [Python]
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)
```

```ts [TypeScript]
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

```python [Python]
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)
```

```ts [TypeScript]
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](https://bigmodel.io/docs/tool-calling).

```python [Python]
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)
```

```ts [TypeScript]
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](https://bigmodel.io/docs/prompt-caching).

## Verify the setup

Run the minimal call above, then open [Usage](https://bigmodel.io/usage) and check that the request is listed with endpoint `/v1/messages`. With curl:

```bash
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](https://bigmodel.io/docs/openai-sdk-langchain).

**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](https://bigmodel.io/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](https://bigmodel.io/models).

**403 `INSUFFICIENT_BALANCE` or 429 `API_KEY_QUOTA_EXHAUSTED`.** Top up in [Billing](https://bigmodel.io/purchase) or raise the key's quota. See [Limits & rate limits](https://bigmodel.io/docs/rate-limits).

## Related

- [Claude Code](https://bigmodel.io/docs/claude-code) uses the same Messages endpoint
- [OpenAI SDK](https://bigmodel.io/docs/openai-sdk-langchain) for Chat Completions
- [LangChain](https://bigmodel.io/docs/langchain) (`ChatAnthropic`) and [Vercel AI SDK](https://bigmodel.io/docs/vercel-ai-sdk) (`@ai-sdk/anthropic`)
- [Errors](https://bigmodel.io/docs/errors)
