GLM

Copied!
Try AIAdd to Compare
Text GenerationReasoning

Overview

Text GenerationReasoning

GLM-5.2 is the latest flagship model from Zhipu AI, designed for long-horizon tasks with support for an ultra-long 1M context window. It features powerful logical reasoning, long-text comprehension, and code generation capabilities, balancing performance with inference efficiency. It excels across multi-task benchmarks and is well-suited for intelligent interaction, enterprise applications, and development assistance scenarios.

Input

Text

Output

Text

Features

Prefix Completion

Enable Partial Mode when calling the Qwen API to make the model continue strictly from your provided prefix text.View docs

Function Calling

Use function calling to connect large language models with external tools and systems.View docs

Cache

Context Cache stores shared prefixes for long-context requests to reduce repeated computation, improve latency, and lower cost.View docs

Structured Outputs

Structured Outputs help ensure the model returns a JSON string in the expected format.View docs

Batches

Web Search

Enable web search so the model can answer with real-time retrieved data.View docs

feature.funeTuning

Pricing

  • Input
    $1.4Per 1M tokens
  • Output
    $4.4Per 1M tokens
  • Input(Implicit Cache)
    $0.28Per 1M tokens

toc.rateLimitsAndContext

  • Max Input
    1.04M
  • Max Output
    131.07K
  • RPMRequests Per Minute
    500
  • TPMTokens Per Minute
    1M
  • contextField.maxInputThinking
    1.04M
  • contextField.maxOutputThinking
    131.07K
  • Context
    1.04M

API Reference

Get API Key
Copied!
12345678910111213141516171819202122232425262728293031323334353637
import os
from dashscope import Generation
import dashscope
dashscope.base_http_api_url = "https://dashscope-intl.aliyuncs.com/api/v1/"

messages = [{"role": "user", "content": "Who are you"}]

completion = Generation.call(
    api_key=os.getenv("DASHSCOPE_API_KEY"),
    model="glm-5.2",
    messages=messages,
    result_format="message", 
    stream=True,
    incremental_output=True, 
)

is_answering = False

print("=" * 20 + "Thinking process" + "=" * 20)

for chunk in completion:
    if (
        chunk.output.choices[0].message.content == ""
        and chunk.output.choices[0].message.reasoning_content == ""
    ):
        pass
    else:
        if (
            chunk.output.choices[0].message.reasoning_content != ""
            and chunk.output.choices[0].message.content == ""
        ):
            print(chunk.output.choices[0].message.reasoning_content, end="", flush=True)
        elif chunk.output.choices[0].message.content != "":
            if not is_answering:
                print("\n" + "=" * 20 + "Full response" + "=" * 20)
                is_answering = True
            print(chunk.output.choices[0].message.content, end="", flush=True)