Guide
Use GLM with the OpenAI SDK
You don't need Z.ai's own SDK to call GLM. Nicrron serves GLM models through an OpenAI-compatible API, so the OpenAI SDK you already use calls them after two changes: the base URL and the key.
The same key also calls every other model on Nicrron, so trying GLM against what you use today is a one-word change.
1. Get a key
Make an API key in the dashboard and add credit. Keep the key in an environment variable, for example NICRRON_API_KEY.
2. Point the SDK at Nicrron
Set base_url (Python) or baseURL (TypeScript) to https://api.nicrron.ai/v1, and use the model id z-ai/glm-5.3.
import os
from openai import OpenAI
client = OpenAI(
base_url="https://api.nicrron.ai/v1",
api_key=os.environ["NICRRON_API_KEY"],
)
reply = client.chat.completions.create(
model="z-ai/glm-5.3",
messages=[{"role": "user", "content": "Write a haiku about the sea."}],
)
print(reply.choices[0].message.content)import OpenAI from "openai";
const client = new OpenAI({
baseURL: "https://api.nicrron.ai/v1",
apiKey: process.env.NICRRON_API_KEY,
});
const reply = await client.chat.completions.create({
model: "z-ai/glm-5.3",
messages: [{ role: "user", content: "Write a haiku about the sea." }],
});
console.log(reply.choices[0].message.content);3. Pick a GLM model
| Model id | Context | Input / 1M | Output / 1M |
|---|---|---|---|
| z-ai/glm-5.3-flashx | 1M | $0.37 | $1.25 |
| z-ai/glm-5.3-flash | 1M | $0.15 | $0.50 |
| z-ai/glm-5.3 | 1M | $1.40 | $4.40 |
| z-ai/glm-5.2 | 1M | $1.40 | $4.40 |
| z-ai/glm-5.1 | 205k | $1.40 | $4.40 |
| z-ai/glm-5-turbo | 203k | $1.20 | $4.00 |
| z-ai/glm-5 | 205k | $1.00 | $3.20 |
| z-ai/glm-4.7 | 205k | $0.60 | $2.20 |
| z-ai/glm-4.6 | 205k | $0.60 | $2.20 |
| z-ai/glm-4.5-air | 131k | $0.20 | $1.10 |
| z-ai/glm-4.5 | 131k | $0.60 | $2.20 |
List prices in US dollars from the live catalog; requests paid from credit add a 5% platform fee. More on the Z.ai models page.
4. Stream the answer
Streaming works the same as with OpenAI: pass stream=True and read the chunks.
stream = client.chat.completions.create(
model="z-ai/glm-5.3",
messages=[{"role": "user", "content": "Explain DNS in three sentences."}],
stream=True,
)
for chunk in stream:
if chunk.choices and chunk.choices[0].delta.content:
print(chunk.choices[0].delta.content, end="")5. Add a fallback
Nicrron takes a models list as well as model. If GLM 5.3 can't answer, the same request goes to the next model in the list, and reply.model says which one answered. The OpenAI SDK sends extra fields through extra_body.
reply = client.chat.completions.create(
model="z-ai/glm-5.3",
messages=[{"role": "user", "content": "Hello!"}],
# Tried in order if GLM 5.3 can't answer: an outage or a rate limit.
extra_body={"models": ["openai/gpt-6.2-sol"]},
)
print(reply.model) # the model that actually answeredMore in Fall back to another model.
Questions
- Can I use GLM with the OpenAI SDK?
- Yes. Point the OpenAI SDK at https://api.nicrron.ai/v1 with a Nicrron API key, and set the model to a GLM id such as "z-ai/glm-5.3". The request and the answer have the OpenAI chat completions shape, so the rest of your code stays the same.
- Which GLM models can I call this way?
- 11 right now: GLM 5.3 FlashX, GLM 5.3 Flash, GLM 5.3, GLM 5.2, GLM 5.1, GLM 5 Turbo, GLM 5, GLM 4.7, GLM 4.6, GLM 4.5 Air, GLM 4.5. The ids and prices are on nicrron.ai/models.
- Do streaming and function calling work with GLM?
- Streaming works with stream: true, as server-sent events of chat.completion.chunk. Tools use the OpenAI tools format; Nicrron passes them to models that support function calling.
- How much does GLM cost through Nicrron?
- The provider's list price per token, shown for each model on its page. Requests paid from Nicrron credit add a 5% platform fee. API keys spend paid credit: add credit in the dashboard, with no subscription.