Everything I Found Assumed I Already Knew What GLM Was
I kept seeing GLM mentioned alongside models I already knew — DeepSeek, Qwen — and every time I looked it up, the documentation jumped straight into advanced parameters without ever showing a plain, working first call. So here's the version of that first call I wish I'd found.
GLM is a large language model family originally developed by a Tsinghua University research group, now maintained commercially as Z.ai. It's OpenAI-API-compatible, which meant I didn't need a new SDK — just a different base URL and model name.
Getting an API Key
Sign up on Z.ai's platform (or through BigModel, the mainland-facing endpoint) and generate a key from your account dashboard. Same basic flow as most other LLM providers at this point — nothing GLM-specific to worry about here.
pip install openai python-dotenv
The Minimal Working Call
import os
from dotenv import load_dotenv
from openai import OpenAI
load_dotenv()
client = OpenAI(
api_key=os.getenv("GLM_API_KEY"),
base_url="https://api.z.ai/api/paas/v4"
)
response = client.chat.completions.create(
model="glm-5.3",
messages=[
{"role": "user", "content": "Explain what a hash map is in two sentences."}
],
)
print(response.choices[0].message.content)

That's the whole first call. If you've used any other OpenAI-compatible provider, this will look identical except for the base_url and model string.
The One Thing That Actually Tripped Me Up
The current GLM models default to an extended "thinking" mode — the model generates an internal reasoning trace before answering, which adds latency you might not expect for a simple prompt. On GLM-5.3 specifically, this can't be fully turned off (older versions like 5.2 allowed a disabled setting; 5.3 replaced that with graduated effort levels instead). If you're just testing your first call and it feels slower than you expected, that's likely why — not a network issue, not a bug in your code.
response = client.chat.completions.create(
model="glm-5.3",
messages=[{"role": "user", "content": "Explain what a hash map is in two sentences."}],
extra_body={"thinking": {"type": "enabled", "effort": "low"}},
)

For a simple factual prompt like the one above, effort: low gets you close to the fastest response the model can give — worth setting explicitly rather than leaving it on the default if latency matters for what you're building.
A Slightly More Realistic Example
Most tutorials stop at a single hardcoded prompt, which doesn't tell you much about actually building something. Here's a small wrapper that takes a variable prompt and handles the basic case of an empty or malformed response:
def ask_glm(prompt, effort="low"):
try:
response = client.chat.completions.create(
model="glm-5.3",
messages=[{"role": "user", "content": prompt}],
extra_body={"thinking": {"type": "enabled", "effort": effort}},
)
content = response.choices[0].message.content
if not content:
return "No response content returned."
return content
except Exception as e:
return f"Request failed: {e}"
print(ask_glm("Summarize the plot of a story about a lighthouse keeper in one sentence."))
Nothing sophisticated — just enough structure to actually build on top of, rather than a single throwaway print() call.
Where I Took This After the First Call
Once I had this working, I wanted to see how GLM's output compared to a couple of models I was already using for a small side project, without setting up a completely separate client and auth flow for each one. I ended up testing GLM through RouteAI alongside those other models — same request format shown above, just a different base_url and model name per test. That's a convenience note for anyone doing model comparisons, not a requirement for getting GLM working on its own; the code above runs fine against Z.ai's endpoint directly.
If You're Setting This Up Yourself
Start with the direct endpoint before adding anything else — get one working call before worrying about comparisons or routing
If your first call feels slow, check your thinking/effort settings before assuming something's broken
The OpenAI-compatible format means most of what you already know about calling other LLM APIs transfers directly — don't expect to relearn much
TL;DR: GLM's API is OpenAI-compatible, so getting started is mostly a different base_url and model name. The main gotcha for first-timers is the default thinking mode adding unexpected latency — set an explicit effort level if speed matters for your prompt. Full minimal example above.
Worth exploring if this is relevant to your stack: www.fastrouteai.com
Top comments (0)