Use BigModel.io with LlamaIndex

Connect LlamaIndex to BigModel.io with OpenAILike in Python or the OpenAI class in TypeScript, using https://bigmodel.io/v1. Set is_chat_model, context window, streaming and tools.

On this page
  1. Install
  2. Minimal call
  3. Streaming
  4. Tool calling (Python)
  5. Verify the setup
  6. Troubleshooting
  7. Related

LlamaIndex reaches BigModel.io through its OpenAI-compatible LLM classes: OpenAILike in Python and OpenAI from @llamaindex/openai in TypeScript.

Setting Python (OpenAILike) TypeScript (OpenAI)
Base URL api_base="https://bigmodel.io/v1" baseURL: "https://bigmodel.io/v1"
API key api_key=... apiKey: ...
Model model="glm-5.3" model: "glm-5.3"
Chat endpoint is_chat_model=True (required) default

Copy model IDs from the model catalog; availability depends on the key's group.

bash
export BIGMODEL_API_KEY="sk-..."

#Install

Python
pip install llama-index-llms-openai-like
TypeScript
npm install llamaindex @llamaindex/openai

#Minimal call

Python
import os
from llama_index.llms.openai_like import OpenAILike

llm = OpenAILike(
    model="glm-5.3",
    api_base="https://bigmodel.io/v1",
    api_key=os.environ["BIGMODEL_API_KEY"],
    is_chat_model=True,
    is_function_calling_model=True,
    context_window=128000,  # set to the model's context window from its model page
)
print(llm.complete("Explain vector databases in three sentences."))
TypeScript
import { OpenAI } from "@llamaindex/openai";

const llm = new OpenAI({
  model: "glm-5.3",
  apiKey: process.env.BIGMODEL_API_KEY,
  baseURL: "https://bigmodel.io/v1",
});

const res = await llm.chat({
  messages: [{ role: "user", content: "Explain vector databases in three sentences." }],
});
console.log(res.message.content);

is_chat_model defaults to False, which makes OpenAILike call the legacy /v1/completions endpoint. Always set it to True. Set context_window to the model's real window so LlamaIndex packs prompts correctly.

To use the model everywhere in LlamaIndex (query engines, agents), set it globally:

python
from llama_index.core import Settings

Settings.llm = llm

#Streaming

Python
for chunk in llm.stream_complete("Write a haiku about latency."):
    print(chunk.delta, end="", flush=True)
TypeScript
const stream = await llm.chat({
  messages: [{ role: "user", content: "Write a haiku about latency." }],
  stream: true,
});
for await (const chunk of stream) {
  process.stdout.write(chunk.delta);
}

#Tool calling (Python)

With is_function_calling_model=True, LlamaIndex sends OpenAI tools. Whether the model calls them depends on the model.

python
from llama_index.core.tools import FunctionTool

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

tool = FunctionTool.from_defaults(fn=get_weather)
print(llm.predict_and_call([tool], "What's the weather in Hangzhou?"))

#Verify the setup

Run the minimal call. A reply means the base URL and key work; the request should also appear in Usage with endpoint /v1/chat/completions. If Usage shows nothing and you got a 404, is_chat_model is probably unset.

#Troubleshooting

404 on every request (Python). is_chat_model is False, so the call goes to /v1/completions. Set is_chat_model=True.

404 on every request. The base URL is missing /v1. Use https://bigmodel.io/v1.

Prompts are truncated or "context window" errors. context_window is left at its small default. Set it from the model page.

401 INVALID_API_KEY or API_KEY_REQUIRED. The key is empty in this process, or an OPENAI_API_KEY from your environment is used instead. Pass the 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.

403 INSUFFICIENT_BALANCE or 429. Top up in Billing; for 429 see Limits & rate limits.

Updated · View as Markdown