Z.ai opened the API for GLM-5.4 on 2 December 2026. It is the company’s new flagship coding and agent model and, according to the official GLM-5.4 guide, the first one built on a Loop Transformer architecture. On paper it gives you a 1M-token context window, up to 128K output tokens, and text, image, video and file input.

If you already call GLM-5.3 or GLM-5.2, switching takes one line, but a few defaults have changed. Thinking can no longer be turned off. Reasoning from earlier turns is now kept by default. And there is a separate switch for streaming tool-call arguments. This guide walks through the changes, with Python code that uses the standard OpenAI SDK.

What is new in GLM-5.4

Z.ai’s model page and migration guide list these points:

  • Model code: glm-5.4
  • Context and output: 1M tokens of context, up to 128K output tokens
  • Input types: text, image, video and file. Output is text only.
  • Forced thinking: thinking.type only accepts enabled
  • Reasoning effort: reasoning_effort accepts only low, high or max. The default is max.
  • Preserved thinking on by default: thinking.clear_thinking defaults to false
  • Tool streaming: tool_stream=true streams function-call arguments as they’re generated

Under the hood, Z.ai says GLM-5.4 runs 28 layers of the GLM-5 base model through two iterations. That lets the model “reason more deeply without adding parameters”. The company also reports that on its own tests, part of the reasoning moves out of the visible chain of thought and into the loop. If you’re building something, the practical upshot is that you shouldn’t assume the reasoning_content you get back will be the same length as on GLM-5.3.

Step 1: Make your first call

The Chat Completions endpoint is OpenAI-compatible, so the official openai Python package works. Point the client at Z.ai’s base URL:

# pip install openai
import os
from openai import OpenAI

client = OpenAI(
    api_key=os.environ["ZAI_API_KEY"],
    base_url="https://api.z.ai/api/paas/v4/",
)

resp = client.chat.completions.create(
    model="glm-5.4",
    messages=[{"role": "user", "content": "Explain Python's GIL in three sentences."}],
    temperature=1.0,
    extra_body={"thinking": {"type": "enabled"}},
)

msg = resp.choices[0].message
print(getattr(msg, "reasoning_content", None))  # the model's reasoning
print(msg.content)                               # the final answer

Fields that aren’t part of the OpenAI schema, like thinking, go in extra_body. The reasoning comes back in a separate reasoning_content field next to content. The OpenAI SDK passes it through as an extra attribute, which is why the code reads it with getattr.

Z.ai recommends temperature: 1, top_p: 0.95 and reasoning_effort: max for GLM-5.4. The migration guide also suggests tuning only one of temperature and top_p, not both.

Step 2: Choose a reasoning effort

On GLM-5.4 you can’t turn thinking off. The docs say a request with "thinking": {"type": "disabled"} returns an error. Use reasoning_effort to control how hard the model thinks instead:

Value Meaning in Z.ai’s docs
max Deep reasoning (default and recommended)
high Enhanced reasoning
low Light reasoning
def ask(prompt: str, effort: str = "max") -> str:
    resp = client.chat.completions.create(
        model="glm-5.4",
        messages=[{"role": "user", "content": prompt}],
        reasoning_effort=effort,  # "low" | "high" | "max"
        extra_body={"thinking": {"type": "enabled"}},
    )
    return resp.choices[0].message.content

print(ask("Rename this variable to snake_case: userEmailAddress", effort="low"))
print(ask("Design a rate limiter for a multi-region API.", effort="max"))

On the standard API, GLM-5.4 only accepts those three values. The Deep Thinking page says any other value causes an error. If your GLM-5.2 code sends none, minimal, medium or xhigh, change it before you switch models. (The Coding Plan endpoint maps those values to the nearest level, but the standard API doesn’t.)

A sensible default is low for quick edits, classification and formatting, and max for planning, debugging and long agent loops.

Step 3: Understand preserved thinking

This is the change most likely to catch existing agent code out. According to the Thinking Mode guide, from GLM-5.4 onwards preserved thinking is on by default on every endpoint. The model is designed to see the reasoning_content from its earlier turns, which Z.ai says improves continuity and cache hit rates.

That only works if you send the reasoning back. The docs are strict about this. Earlier reasoning blocks must be returned complete, unchanged and in their original order. Missing, truncated, rewritten or reordered blocks “may degrade performance or prevent the feature from taking effect.”

In practice, keep reasoning_content on every assistant message you add to the history:

messages = [{"role": "user", "content": "Plan a migration from MySQL 5.7 to 8.4."}]

first = client.chat.completions.create(
    model="glm-5.4", messages=messages,
    extra_body={"thinking": {"type": "enabled", "clear_thinking": False}},
).choices[0].message

messages.append({
    "role": "assistant",
    "content": first.content,
    "reasoning_content": getattr(first, "reasoning_content", ""),  # keep it, unedited
})
messages.append({"role": "user", "content": "Now list the rollback steps."})

second = client.chat.completions.create(
    model="glm-5.4", messages=messages,
    extra_body={"thinking": {"type": "enabled", "clear_thinking": False}},
).choices[0].message
print(second.content)

If you’d rather drop old reasoning to keep requests small, for example in a simple chat app, the docs say "clear_thinking": true gives you the older behaviour.

Step 4: Stream tool calls with tool_stream

GLM-5.4 can stream a function call’s arguments while it generates them, so your UI can show progress before the full JSON arrives. The migration guide says this is off by default and needs both stream=True and tool_stream=True:

tools = [{
    "type": "function",
    "function": {
        "name": "get_weather",
        "description": "Get current weather for a city",
        "parameters": {
            "type": "object",
            "properties": {"location": {"type": "string"}},
            "required": ["location"],
        },
    },
}]

stream = client.chat.completions.create(
    model="glm-5.4",
    messages=[{"role": "user", "content": "What's the weather in Pune?"}],
    tools=tools,
    stream=True,
    extra_body={"tool_stream": True, "thinking": {"type": "enabled"}},
)

reasoning, content, calls = "", "", {}
for chunk in stream:
    delta = chunk.choices[0].delta
    reasoning += getattr(delta, "reasoning_content", None) or ""
    content += delta.content or ""
    for tc in delta.tool_calls or []:
        call = calls.setdefault(tc.index, {"id": tc.id, "name": "", "arguments": ""})
        if tc.function and tc.function.name:
            call["name"] = tc.function.name
        if tc.function and tc.function.arguments:
            call["arguments"] += tc.function.arguments  # concatenate pieces

print(calls)

Only run json.loads() on arguments once the stream has finished. Partway through, the string isn’t valid JSON yet. When you send the tool result back, include the assistant message with its reasoning_content and tool_calls. The interleaved-thinking example in the docs follows the same pattern.

Migration checklist

  1. Change model to glm-5.4.
  2. Remove any "thinking": {"type": "disabled"}. On GLM-5.4 it returns an error.
  3. Map reasoning_effort to low, high or max.
  4. Keep reasoning_content in your stored history, unchanged and in order, or set clear_thinking: true on purpose.
  5. If you stream tool calls, add tool_stream: true and join the argument pieces.
  6. Check max_tokens against the 128K output limit.
  7. Re-run your evaluation prompts. A new architecture can shift output length, latency and tool-calling behaviour.

Takeaway

For most code, GLM-5.4 is a drop-in model change. The parts that need attention are the ones that affect agents: forced thinking, three reasoning-effort levels, and preserved thinking that expects you to send earlier reasoning back exactly as you got it. Make those changes, add tool_stream if your UI streams tool calls, and test on your own prompts before switching production traffic. Full details are in Z.ai’s GLM-5.4 documentation.