Verified, then logged.
Sun 6 Dec 2026 · 12:57 KST / 03:57 UTC한국어 | ENSearch /

01 / AI · Analysis

Z.AI details its GLM-5.2 API with 1M-token context

The developer guide covers project-wide code refactoring, Python SDK installation and streaming API calls.

Z.AI has published an API guide for GLM-5.2, a text model with a context window of one million tokens, covering tasks involving entire software projects. Tokens are units of text processed by AI models. The guide describes how developers can supply multiple code files and design documents in a single task.

The previous model, GLM-5.1, had a context limit of 200,000 tokens. Despite the larger context window, the maximum output length remains 128K tokens. Both models accept and generate text.

The official Python examples use a Z.AI API key and zai-sdk, a software development kit for connecting applications to the model. The documentation covers standard API calls and streaming, which delivers responses as the model generates them.

Project-wide code refactoring

Z.AI said it trained GLM-5.2 to retain earlier design decisions throughout extended coding tasks involving multiple files. One example is refactoring, the process of restructuring existing code without changing how the software behaves.

The developer guide recommends supplying source code, test files, configuration files and engineering rules together. Developers first ask the model to identify the project structure and each component's role, then specify the scope of modifications and the constraints it must preserve. The task concludes with a request for test results.

On Terminal-Bench 2.1, which evaluates performance on terminal-based tasks, GLM-5.2 scored 81.0 against GLM-5.1's 62.0, according to figures published by Z.AI.

Calling the model from Python

The Python SDK provides access to the model through the ZaiClient class and its client.chat.completions.create() method. The official examples follow these steps:

  1. Run pip install zai-sdk to install the official Python SDK.
  2. Import the client with from zai import ZaiClient and supply the issued API key through api_key.
  3. Set the model identifier to glm-5.2 and include task instructions and user requests in messages.
  4. Enable reasoning by setting type within thinking to enabled, and set reasoning_effort to max.
  5. Use max_tokens to limit response length and temperature to control output variability.
  6. Retrieve the completed response through response.choices[0].message, or add stream=True to receive it as it is generated.

Streaming separates the model's reasoning output, available through reasoning_content, from the main response in content. Applications can use these fields to display responses as they are generated during lengthy tasks.

Output limits and free model options

The official API examples set max_tokens to 4096. This is the output limit for the example request, rather than the model's maximum output capacity of 128K tokens.

Z.AI also lists GLM-4.7-Flash as a free model with a context window of 200K tokens. The GLM-5.2 developer overview does not specify API pricing.

The SDK installation command and complete Python examples for standard and streaming API calls are available in the official GLM-5.2 developer documentation.