⌘K

GLM-5.2

glm-5.2

GLM-5.2 是 Z.AI 面向长周期工程和智能体任务的旗舰基础模型,支持思考模式、流式输出、函数调用、结构化输出与 MCP 工具集成。本接口采用 OpenAI Chat Completions 兼容协议。

认证

authorization string 必填

所有 API 均使用 Bearer Token 鉴权

获取 API Key:

访问 API Key 管理页面 获取 API Key

用法:

将以下 Header 添加到请求中:

Authorization: Bearer YOUR_API_KEY

接口与兼容性

POST https://cloud.vtrix.ai/llm/chat/completions

该接口返回 OpenAI Chat Completions 格式:顶层包含 choices 与 usage。它不是异步任务接口,因此响应中没有 status、output、资源 url、jobId、cost 或 discount 字段。

参数

model string 必填

请求使用的模型 ID。

值: glm-5.2


messages array 必填

表示对话历史的消息对象数组。

role string 必填

消息角色。可选值: user、assistant、system、tool。

content string | array 必填

文本字符串或多模态内容数组。


thinking object

控制 GLM 原生思考模式。未传入时,上游可能返回 message.reasoning_content;如只需最终回答,可传入 {"type":"disabled"}。

type string

可选值: enabled、disabled。

clear_thinking boolean

是否清除历史消息中的 reasoning_content。默认值: true。


reasoning_effort string

启用思考模式时的推理强度。默认值: max。

可选值: max、xhigh、high、medium、low、minimal、none。


max_tokens integer

单次完成生成的最大 token 数。范围: 1 - 131072。思考 token 也会占用该预算,因此启用思考模式时应留出足够的 max_tokens。


temperature number

采样温度。默认值: 1.0;范围: 0.0 - 1.0。


top_p number

核采样参数,可作为 temperature 的替代采样控制。默认值: 0.95;范围: 0.01 - 1.0。


stream boolean

是否以 Server-Sent Events (SSE) 方式增量返回。默认值: false。流式响应同样使用 OpenAI Chat Completions 的 chunk 格式,并以 data: [DONE] 结束。


tools array

模型可调用的工具列表,使用 OpenAI function tool 结构。

type string 必填

值: function。

function object 必填

函数定义。


tool_choice string | object

控制工具选择策略。可使用 auto、none、required,或指定某个 function 工具。


stop string | array

模型停止生成的一个或多个序列;最多 4 个字符串。


response_format object

输出格式约束。type 可为 text 或 json_object。

响应格式

id string

本次 Chat Completion 的请求 ID。


object string

固定为 chat.completion。


created integer

响应创建时间的 Unix 时间戳(秒)。


model string

实际处理本次请求的模型 ID。


choices array

一个或多个生成结果。

index integer

结果序号。

message object

助手消息。

role string

固定为 assistant。

content string | null

最终回答文本。

reasoning_content string(可选)

启用思考模式时返回的推理文本;关闭思考模式时通常为空字符串或不返回。

finish_reason string

生成结束原因,例如 stop、length 或 tool_calls。


usage object

本次请求的 token 使用统计。

prompt_tokens integer

输入 token 数。

completion_tokens integer

输出 token 数。

total_tokens integer

输入与输出 token 总数。

completion_tokens_details.reasoning_tokens integer(可选)

思考模式消耗的 token 数。