Skip to main content
Third-party models

GLM-ZHIPU

This document describes how to call the Z.AI GLM model inference service on QwenCloud.

Service activation

  1. Go to the QwenCloud console, search for GLM, find the Z.AI direct-supply GLM model card, and click Activate Now.
  2. Confirm the activation and authorization in the dialog box.
After completing these steps, you can call the GLM model service provided by Z.AI.

Quick start

Prerequisites
  • You must have activated QwenCloud and created an API Key.
  • If calling via SDK, install the corresponding SDK.
glm-5.2 is the latest model in the GLM series, with a genuinely usable 1M context. ZHIPU/GLM-5.2, ZHIPU/GLM-5.1, and ZHIPU/GLM-5 support thinking and non-thinking modes via the enable_thinking parameter:
  • Thinking mode (enable_thinking: true, default): The model outputs a detailed reasoning process (reasoning_content).
  • Non-thinking mode (enable_thinking: false): The model outputs the result directly, without a reasoning process.
The following example shows how to call ZHIPU/GLM-5.2 in thinking mode for text generation.
  • OpenAI compatible
  • DashScope
enable_thinking is not a standard OpenAI parameter. The OpenAI Python SDK passes it via extra_body; the Node.js SDK passes it as a top-level parameter.
  • Python
  • Node.js
from openai import OpenAI
import os

client = OpenAI(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)

completion = client.chat.completions.create(
  model="ZHIPU/GLM-5.2",
  messages=[{"role": "user", "content": "What is 1+1?"}],
  # reasoning_effort controls the reasoning effort. Optional values: max (default), high, none.
  extra_body={"enable_thinking": True, "reasoning_effort": "max"}
)

msg = completion.choices[0].message

if getattr(msg, "reasoning_content", None):
  print("\n" + "=" * 20 + " Reasoning " + "=" * 20 + "\n")
  print(msg.reasoning_content or "")
print("\n" + "=" * 20 + " Response " + "=" * 20 + "\n")
print(msg.content)

Clear thinking history (clear_thinking)

The clear_thinking parameter controls whether the reasoning_content (thinking process) from previous turns is included as context input for the model in multi-turn conversations. Only GLM series models support this parameter.
  • true: Ignore reasoning_content from previous turns. Only visible text, tool calls, and results are used as context, reducing context length and cost.
  • false (default): Retain reasoning_content from previous turns and pass it to the model as part of the context. To enable Preserved Thinking, you must pass the complete, unmodified reasoning_content from previous turns in the original order. Missing, trimmed, rewritten, or reordered content may degrade effectiveness or prevent it from working.
This parameter only affects the thinking content from previous turns. It does not change whether the model generates or outputs thinking in the current turn.
The following example uses the same multi-turn messages (with reasoning_content in the assistant messages). When clear_thinking is set to true, the historical thinking content is excluded from context, resulting in fewer prompt_tokens compared to false (default). The actual difference depends on the length of the historical reasoning_content.
  • OpenAI compatible
  • Python
  • curl
from openai import OpenAI
import os
client = OpenAI(
  api_key=os.getenv("DASHSCOPE_API_KEY"),
  base_url="https://dashscope-intl.aliyuncs.com/compatible-mode/v1",
)
messages = [
  {"role": "user", "content": "What is 15 * 23?"},
  {"role": "assistant", "content": "15 times 23 equals 345.", "reasoning_content": "15 * 23 = 345"},
  {"role": "user", "content": "Now add 55 to that."},
  {"role": "assistant", "content": "345 plus 55 equals 400.", "reasoning_content": "345 + 55 = 400"},
  {"role": "user", "content": "What were the intermediate results?"},
]
completion = client.chat.completions.create(
  model="ZHIPU/GLM-5.2",
  messages=messages,
  extra_body={
    "thinking": {
      "type": "enabled",
      "clear_thinking": False  # False = retain thinking content
    }
  }
)
print(completion.usage.prompt_tokens)  # fewer when true vs false

Other features

ModelMulti-turn conversationFunction callingWeb searchContext cachingReasoning effort control
ZHIPU/GLM-5.2✓ (non-thinking mode only)✓ (reasoning_effort)
ZHIPU/GLM-5.1✓ (non-thinking mode only)
ZHIPU/GLM-5✓ (non-thinking mode only)

Parameter defaults

Modelenable_thinkingtemperaturetop_ptop_krepetition_penalty
ZHIPU/GLM-5.2true1.00.95
ZHIPU/GLM-5.1true1.00.95201.0
ZHIPU/GLM-5true1.00.95201.0

Model list and billing

ZHIPU/GLM-5.2, ZHIPU/GLM-5.1, and ZHIPU/GLM-5 are hybrid reasoning models supplied directly by Z.AI, suitable for intelligent interaction, enterprise applications, and development assistance. For model context length and pricing, see the QwenCloud console. Billing is based on the model's input and output tokens.
In thinking mode, the chain of thought is billed based on output tokens.

Error codes

If a call fails, see Error codes to resolve the issue.