GLM-5.2-Fast
复制成功!
文本生成
概述
文本生成
GLM-5.2-Fast-Preview 是智谱 AI 旗舰模型 GLM-5.2 的高速版本,支持 1M 超长上下文,模型能力对齐 GLM-5.2 标准版,具备逻辑推理、长文本理解与代码生成能力。通过推理加速优化,输出 TPS 可达 GLM-5.2 标准版的 1.5~2 倍,显著提升输出速度,适用于实时对话、Agent 多轮调用、流式代码生成等对输出速度敏感的场景。
输入
文本
输出
文本
功能
定价
- 输入¥16/M tokens
- 输出¥56/M tokens
- 输入(缓存命中)¥4/M tokens
速率限制与上下文
- 最大输入1.04M
- 最大输出131.07K
- RPM每分钟请求数500
- TPM每分钟 Token 数1M
- 最大输入(思考模式)1.04M
- 最大输出(思考模式)131.07K
- 上下文1.04M
API 参考
获取 API Key复制成功!
12345678910111213141516171819202122232425262728293031323334353637
import os
from dashscope import Generation
import dashscope
dashscope.base_http_api_url = "https://dashscope.aliyuncs.com/api/v1/"
messages = [{"role": "user", "content": "你是谁?"}]
completion = Generation.call(
api_key=os.getenv("DASHSCOPE_API_KEY"),
model="glm-5.2-fast-preview",
messages=messages,
result_format="message",
stream=True,
incremental_output=True,
)
is_answering = False
print("=" * 20 + "思考过程" + "=" * 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 + "完整回复" + "=" * 20)
is_answering = True
print(chunk.output.choices[0].message.content, end="", flush=True)