GLM-5.2 is live — Z.AI's flagship with a 1M-token lossless contextfrom $0.900 per 1M tokens
GLM-5.2 API Guide: 1M Context, Pricing, and Coding (2026)
2026/08/01

GLM-5.2 API Guide: 1M Context, Pricing, and Coding (2026)

Use the GLM-5.2 API with OpenAI-compatible code. Learn its 1M context, $1.40/$4.40 official pricing, reAPI rates, reasoning controls, and limits.

GLM-5.2 is Z.AI's open-weight flagship for long-horizon coding and agent work. The GLM-5.2 API combines a one-million-token context window, 128K maximum output, thinking that can be disabled, function calling, JSON mode, and an OpenAI-compatible request shape.[1]

Its headline price is competitive: Z.AI lists $1.40 per million input tokens, $0.26 for cached input, and $4.40 per million output tokens. reAPI currently lists $0.90 input and $3 output through its compatible gateway.[2]

TL;DR

  • Model id: glm-5.2, with the dot.
  • Context: 1M tokens; maximum output is 131,072 tokens.
  • Official price: $1.40 input, $0.26 cached input, $4.40 output per MTok.
  • reAPI price: $0.90 input and $3 output per MTok.
  • Thinking: enabled by default but switchable off.
  • Reasoning effort: accepts seven labels but collapses to three effective behaviors; default is max.
  • Tools: up to 128 functions, tool_choice: "auto", streamed tool-call arguments.
  • Main trap: the page slug is glm-5-2, but API requests must send glm-5.2.

GLM-5.2 specifications

PropertyGLM-5.2
VendorZ.AI
DistributionOpen weight
API model idglm-5.2
Context window1,000,000 tokens
Maximum output131,072 tokens
Input/outputText / text
Thinking defaultEnabled
Reasoning defaultmax
Temperature0.0–1.0, default 1.0
Top-p0.01–1.0, default 0.95
ToolsUp to 128 functions
Structured outputJSON object mode, not JSON Schema

Z.AI positions the model for long-horizon tasks. The long context supports large codebases and document collections, but it should not be treated as a reason to send every file on every turn. Search and context selection still reduce latency and cost.

GLM-5.2 API pricing

RouteInput / MTokCached inputOutput / MTok
Z.AI official$1.40$0.26$4.40
reAPI$0.90Not separately published$3.00

For a monthly workload with 100M uncached input tokens and 20M output tokens, the simple standard-rate calculation is:

Z.AI: 100 × $1.40 + 20 × $4.40 = $228
reAPI: 100 × $0.90 + 20 × $3.00 = $150

That example assumes the same token use and no cache hits. Z.AI's $0.26 cached rate can materially change a workload with repeated system prompts, tool definitions, or stable repository context.

The reasoning-effort labels collapse into three behaviors

GLM-5.2 accepts more effort strings than it meaningfully executes. According to Z.AI's request behavior, the values map as follows:

GLM-5.2 reasoning effort map showing seven accepted labels collapsing into no-thinking, high, and max behavior

Values sentEffective behavior
none, minimalSkip thinking
low, medium, highHigh reasoning
xhigh, maxMaximum reasoning

The default is max, which is expensive for routine classification, extraction, and simple code edits. If the task needs reasoning but not the maximum, send high. If it is deterministic and simple, compare none with thinking disabled.

reasoning_effort only matters while thinking is enabled. Do not expect max to override thinking: {"type": "disabled"}.

How conversation thinking is handled

GLM-5.2 separates visible content from reasoning_content. With the default clear_thinking: true, prior reasoning is removed rather than preserved across turns. Set it to false only when the complete reasoning history remains relevant and your application can replay the full ordered messages correctly.[3]

This differs from Kimi K3, where preserved thinking is mandatory. GLM-5.2 lets you choose between a cleaner context and continuity of hidden work.

Calling GLM-5.2 with the OpenAI Python SDK

from openai import OpenAI

client = OpenAI(
    api_key="YOUR_REAPI_KEY",
    base_url="https://api.reapi.ai/v1",
)

stream = client.chat.completions.create(
    model="glm-5.2",
    messages=[
        {"role": "user", "content": "Refactor this module and add tests."}
    ],
    max_tokens=8192,
    stream=True,
    extra_body={
        "thinking": {"type": "enabled"},
        "reasoning_effort": "high",
    },
)

for chunk in stream:
    delta = chunk.choices[0].delta
    reasoning = getattr(delta, "reasoning_content", None)
    if reasoning:
        print(reasoning, end="")
    if delta.content:
        print(delta.content, end="")

The model id contains a dot. glm-5-2 is the website slug and will produce an unknown-model error if sent in the request body.

Function calling and structured output

GLM-5.2 supports up to 128 function definitions and streams tool-call arguments when tool_stream is enabled. Its tool_choice behavior is narrower than many OpenAI models: auto is the supported choice. Design the prompt and tool descriptions so the model can decide when to call them.

The model supports JSON object mode through:

{
  "response_format": {"type": "json_object"}
}

This is not JSON Schema enforcement. Validate the returned object in your application and retry or repair when required fields are missing.

Temperature, top-p, and stop sequences

Unlike several reasoning models, GLM-5.2 allows temperature and top-p tuning. Z.AI recommends changing one rather than both, because two simultaneous sampling changes make output behavior harder to attribute.[1]

  • Use the defaults for general agent work.
  • Lower temperature for repeatable extraction or transformation.
  • Use one stop string only; the API does not accept a long stop list.
  • Keep max_tokens realistic. A 128K ceiling is not a target for every call.

For coding agents, reasoning effort and context selection usually affect cost more than small sampling changes.

When to use GLM-5.2

Use it for large-codebase work. The context window and tool support fit repository navigation, migrations, test generation, and long-running repair.

Use it for cost-sensitive agents. Its official and reAPI rates sit well below the flagship Claude and GPT tiers.

Use it when open weights matter. Teams can evaluate self-hosting or private deployment rather than depend exclusively on a closed API.

Avoid it when native image understanding is required. The documented GLM-5.2 API is text in and text out. Choose a vision model for image or video analysis.

Common integration mistakes

  1. Sending glm-5-2 instead of glm-5.2.
  2. Leaving the default max effort on every low-value request.
  3. Expecting response_format to enforce a JSON Schema.
  4. Setting tool_choice to an unsupported forced-tool value.
  5. Tuning temperature and top-p simultaneously.
  6. Reading only content during streaming and discarding reasoning_content without deciding whether it is needed.
  7. Filling the 1M context window instead of retrieving relevant files.

FAQ

Is GLM-5.2 open source?

It is safer to describe GLM-5.2 as open weight unless the specific license and release artifacts satisfy your definition of open source. Review the current model license before redistribution or commercial deployment.

How much does the GLM-5.2 API cost?

Z.AI lists $1.40 input, $0.26 cached input, and $4.40 output per million tokens. reAPI currently lists $0.90 input and $3 output.

Does GLM-5.2 support one million tokens?

Yes. Z.AI documents a 1M-token context window and 128K maximum output.

Can thinking be disabled?

Yes. Set thinking.type to disabled, or use a no-thinking effort value where supported. The default is enabled with maximum reasoning.

Does GLM-5.2 support images?

No on the documented chat model surface. It accepts text and returns text.

Is the GLM-5.2 API OpenAI compatible?

The reAPI route is compatible with OpenAI Chat Completions. Vendor-specific fields such as thinking and reasoning_effort should be passed through the SDK's extra-body mechanism.

Conclusion

The GLM-5.2 API is compelling when a one-million-token context, open weights, and low token prices matter more than native multimodality. The integration is straightforward once three details are handled correctly: send glm-5.2 with the dot, lower the default max effort for routine traffic, and treat JSON mode as syntax—not schema validation.

References

  1. Z.AI. GLM-5.2 model guide and API behavior. docs.z.ai/guides/llm/glm-5.2
  2. Z.AI. Model pricing. docs.z.ai/guides/overview/pricing
  3. Z.AI. Chat Completions API reference. docs.z.ai/api-reference/llm/chat-completion

Further reading