# Use BigModel.io with LangChain

> Connect LangChain to BigModel.io with ChatOpenAI (base_url https://bigmodel.io/v1) or ChatAnthropic (https://bigmodel.io). Streaming usage, tool binding and the reasoning_content caveat.

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

LangChain talks to BigModel.io through its OpenAI or Anthropic integration. Use `ChatOpenAI` for any key; use `ChatAnthropic` only if the key's group serves `/v1/messages`.

| Class | Base URL setting | Value |
|---|---|---|
| `ChatOpenAI` (Python) | `base_url` | `https://bigmodel.io/v1` |
| `ChatOpenAI` (JS) | `configuration.baseURL` | `https://bigmodel.io/v1` |
| `ChatAnthropic` (Python) | `anthropic_api_url` | `https://bigmodel.io` (no `/v1`) |
| `ChatAnthropic` (JS) | `anthropicApiUrl` | `https://bigmodel.io` (no `/v1`) |

Model IDs come from the [model catalog](https://bigmodel.io/models); availability depends on the key's group.

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

## Install

```bash [Python]
pip install langchain-openai langchain-anthropic
```

```bash [TypeScript]
npm install @langchain/openai @langchain/anthropic @langchain/core zod
```

## ChatOpenAI

```python [Python]
import os
from langchain_openai import ChatOpenAI

llm = ChatOpenAI(
    model="glm-5.3",
    base_url="https://bigmodel.io/v1",
    api_key=os.environ["BIGMODEL_API_KEY"],
    stream_usage=True,
)
print(llm.invoke("List five things to verify before launch.").content)
```

```ts [TypeScript]
import { ChatOpenAI } from "@langchain/openai";

const llm = new ChatOpenAI({
  model: "glm-5.3",
  apiKey: process.env.BIGMODEL_API_KEY,
  configuration: { baseURL: "https://bigmodel.io/v1" },
  streamUsage: true,
});
const result = await llm.invoke("List five things to verify before launch.");
console.log(result.content);
```

In Python, `stream_usage` is off by default when you set a custom base URL, so streamed responses carry no `usage_metadata`. Pass `stream_usage=True` as shown.

Passing `reasoning=...` or `use_responses_api=True` switches `ChatOpenAI` to `/v1/responses`, which GLM and DeepSeek groups do not serve (404). Leave both unset for those keys.

## ChatAnthropic

```python [Python]
import os
from langchain_anthropic import ChatAnthropic

llm = ChatAnthropic(
    model="glm-5.3",
    anthropic_api_url="https://bigmodel.io",
    api_key=os.environ["BIGMODEL_API_KEY"],
    max_tokens=1024,
)
print(llm.invoke("List five things to verify before launch.").content)
```

```ts [TypeScript]
import { ChatAnthropic } from "@langchain/anthropic";

const llm = new ChatAnthropic({
  model: "glm-5.3",
  anthropicApiUrl: "https://bigmodel.io",
  apiKey: process.env.BIGMODEL_API_KEY,
  maxTokens: 1024,
});
const result = await llm.invoke("List five things to verify before launch.");
console.log(result.content);
```

`ChatAnthropic` also reads `ANTHROPIC_API_URL` / `ANTHROPIC_BASE_URL` from the environment; an explicit argument wins.

## Streaming

```python [Python]
for chunk in llm.stream("Write a haiku about latency."):
    print(chunk.content, end="", flush=True)
```

```ts [TypeScript]
const stream = await llm.stream("Write a haiku about latency.");
for await (const chunk of stream) {
  process.stdout.write(typeof chunk.content === "string" ? chunk.content : "");
}
```

## Tool calling

`bind_tools` sends standard OpenAI or Anthropic tool definitions; the gateway forwards them. Tool support depends on the model.

```python [Python]
from langchain_core.tools import tool

@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"Sunny in {city}"

llm_with_tools = llm.bind_tools([get_weather])
msg = llm_with_tools.invoke("What's the weather in Hangzhou?")
print(msg.tool_calls)
```

```ts [TypeScript]
import { tool } from "@langchain/core/tools";
import { z } from "zod";

const getWeather = tool(async ({ city }) => `Sunny in ${city}`, {
  name: "get_weather",
  description: "Get the current weather for a city.",
  schema: z.object({ city: z.string() }),
});

const msg = await llm.bindTools([getWeather]).invoke("What's the weather in Hangzhou?");
console.log(msg.tool_calls);
```

## reasoning_content caveat

Thinking models on GLM and DeepSeek groups return their reasoning in a `reasoning_content` field. The gateway passes it through, but `ChatOpenAI` does not surface it: you get the final answer only. If you need the reasoning text, call the model with the [OpenAI SDK](https://bigmodel.io/docs/openai-sdk-langchain) and read `reasoning_content` there. See [Reasoning & thinking](https://bigmodel.io/docs/reasoning).

## Verify the setup

```python [Python]
msg = llm.invoke("ping")
print(msg.content, msg.usage_metadata)
```

```ts [TypeScript]
const msg = await llm.invoke("ping");
console.log(msg.content, msg.usage_metadata);
```

A reply with token counts means the base URL and key work. The request should also appear in [Usage](https://bigmodel.io/usage).

## Troubleshooting

**404 on every request with `ChatOpenAI`.** The base URL is missing `/v1`. In JS it must be inside `configuration`, not a top-level `baseURL`.

**404 on every request with `ChatAnthropic`.** The URL ends in `/v1`. Use `https://bigmodel.io`.

**404 `... only supports /v1/chat/completions`.** Either `ChatAnthropic` is used with a Chat-Completions-only group, or `ChatOpenAI` was switched to the Responses API by `reasoning` / `use_responses_api`. Use plain `ChatOpenAI`.

**No token usage on streamed responses.** Set `stream_usage=True` (Python) or `streamUsage: true` (JS).

**401 `INVALID_API_KEY`.** The key is not reaching the client; an `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` in your environment may be used instead. Pass `api_key` explicitly.

**503 `No available accounts: no available accounts supporting model: ...`.** The model ID is wrong or not in the key's group. Copy it from the [model catalog](https://bigmodel.io/models).

**403 `INSUFFICIENT_BALANCE` or 429.** Top up in [Billing](https://bigmodel.io/purchase); for 429 see [Limits & rate limits](https://bigmodel.io/docs/rate-limits).

## Related

- [OpenAI SDK](https://bigmodel.io/docs/openai-sdk-langchain) and [Anthropic SDK](https://bigmodel.io/docs/anthropic-sdk)
- [LlamaIndex](https://bigmodel.io/docs/llamaindex) and [Vercel AI SDK](https://bigmodel.io/docs/vercel-ai-sdk)
- [Tool calling](https://bigmodel.io/docs/tool-calling) and [Streaming](https://bigmodel.io/docs/streaming)
