GLM-5.2

glm-5.2
Open sourceGLM series

Overview

1M ContextReasoningCode generationAgentic tasks

GLM-5.2 is the flagship base model of the GLM-5 series, covering text generation, deep reasoning and code engineering. Aiming at "staying usable across long tasks", we redesigned the context-compression path and the goal-consistency mechanism so the model reliably retains key constraints across multi-day engineering collaboration, and keeps aligning with user intent through long-chain tasks without context drift. Combined with tiered thinking effort, function calling, MCP tools and structured output, it can drive project-scale software development and complex automation pipelines.

Million-token context
A 1M-token context window loads project-scale codebases and very long documents in a single pass.
Long-horizon agents
Optimized for multi-step, long-running agentic workflows, maintaining engineering context throughout a task.
Tiered thinking modes
Effort levels such as high / xhigh cover everything from fast responses to deep reasoning.
Open weights, self-hostable
Open model weights support private deployment and enterprise customization.

Features

Tool calling
Structured output
Context caching
Batch
Web search
Streaming
Reasoning
MCP
Prefix completion
Fine-tuning

Pricing

Input¥8/M tokens
Input (cache hit)¥2/M tokens
Output¥28/M tokens

Rate Limits & Context

Context Window1M
Max Output128K
RPM (requests/min)200
TPM (tokens/min)3M

Built-in Tools

web_search
Responses API
code_interpreter
Responses API
web_extractor
Responses API

API Reference

ENDPOINT
POST https://api.tokenfab.cn/v1/chat/completions

Request Example

curl https://api.tokenfab.cn/v1/chat/completions \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $TOKENFAB_API_KEY" \
  -d '{
    "model": "glm-5.2",
    "messages": [
      {"role": "system", "content": "You are a helpful assistant."},
      {"role": "user", "content": "请用 Python 实现一个快速排序算法,并附上时间复杂度分析。"}
    ]
  }'

Response Example

JSON
{
  "id": "chatcmpl-9d2k7f1",
  "object": "chat.completion",
  "created": 1784950000,
  "model": "glm-5.2",
  "choices": [{
    "index": 0,
    "message": {
      "role": "assistant",
      "content": "快速排序使用分治策略:选定基准值(pivot),将数组分为小于和大于基准的两部分,递归排序后合并。最优 O(n log n),最差 O(n²)。"
    },
    "finish_reason": "stop"
  }],
  "usage": {
    "prompt_tokens": 15,
    "completion_tokens": 128,
    "total_tokens": 143
  }
}

Request Parameters

ParameterTypeRequiredDescription
modelstringModel ID, e.g. glm-5.2 or GLM-5.1
messagesarrayList of chat messages, each with role and content
temperaturefloatSampling temperature, 0–2, default 0.7
top_pfloatNucleus sampling, 0–1, default 0.9
max_tokensintMaximum output tokens
streamboolWhether to stream the response, default false
toolsarrayTool definitions for function calling
tool_choicestringTool choice policy: auto / none / a named function