{
"id": "response_demo",
"object": "response",
"created_at": 1789971757,
"model": "glm-5.3-flash",
"status": "completed",
"output": [
{
"type": "message",
"id": "message_demo",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "你好,我是 GLM,可以帮你完成对话、写作和代码任务。",
"annotations": []
}
]
}
],
"usage": {
"input_tokens": 17,
"output_tokens": 24,
"total_tokens": 41,
"input_tokens_details": {
"cached_tokens": 0
},
"output_tokens_details": {
"reasoning_tokens": 0
}
},
"error": null
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}GLM 全模型接口 - Responses 完整参数
使用 Responses 格式调用 GLM,支持文本对话、流式输出、函数调用,以及按型号提供的图像理解和联网搜索能力。具体参数与模型差异见下方说明。
{
"id": "response_demo",
"object": "response",
"created_at": 1789971757,
"model": "glm-5.3-flash",
"status": "completed",
"output": [
{
"type": "message",
"id": "message_demo",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "你好,我是 GLM,可以帮你完成对话、写作和代码任务。",
"annotations": []
}
]
}
],
"usage": {
"input_tokens": 17,
"output_tokens": 24,
"total_tokens": 41,
"input_tokens_details": {
"cached_tokens": 0
},
"output_tokens_details": {
"reasoning_tokens": 0
}
},
"error": null
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}{
"error": {
"message": "<string>",
"type": "<string>",
"param": "<string>",
"code": "<string>"
}
}https://direct.evolink.ai,对文本模型支持更好,支持长连接;https://api.evolink.ai 为备用地址。模型与参数差异
| 模型 | 输入能力 | 思考档位 |
|---|---|---|
glm-5.3 | 文本 | low / high / max,兼容规则见下表 |
glm-5.3-flash | 文本、图像 | 同 glm-5.3 |
glm-5.3-flashx | 文本、图像 | 同 glm-5.3 |
glm-5.2 | 文本 | 不适用 5.3 系列的兼容规则 |
input 中携带历史消息实现多轮对话。
通过 reasoning.effort 设置推理强度,不要用顶层 reasoning_effort 或 thinking 替代。glm-5.3、glm-5.3-flash 与 glm-5.3-flashx 按以下规则处理:
| 传入值 | 实际思考档位 |
|---|---|
low / high / max | 保持对应档位 |
xhigh | max |
medium | high |
minimal / none | low,仍会思考 |
minimal 与 none 按 low 处理,仍会产生思考 token,并按输出计费。glm-5.2 传入 none 仍可能产生推理 token,不能通过该值确保关闭思考。所有型号的推理 token 都包含在输出用量中。系统提示词与多轮对话
系统提示词推荐放在input 数组的 role="system" 消息中。glm-5.3-flash 的顶层 instructions 可用于字符串输入;使用消息数组时,请改用系统消息。
{
"model": "glm-5.3-flash",
"input": [
{"role": "system", "content": "请用简洁的中文回答。"},
{"role": "user", "content": "记住暗号是 RED-583。"},
{"role": "assistant", "content": "已记住。"},
{"role": "user", "content": "暗号是什么?只回复暗号。"}
],
"reasoning": {"effort": "low"},
"max_output_tokens": 1024
}
glm-5.3-flash 与 glm-5.3-flashx 支持通过响应 ID 续聊:首轮传 store=true,次轮把返回的顶层 id 原样填入 previous_response_id,保持相同模型并传入新问题。它不是 output 中某一项的 ID。
glm-5.2 不支持通过响应 ID 续聊。 传入 previous_response_id 会返回 400,设置 store=true 不会开启此能力。需要跨型号使用时,省略 previous_response_id,每轮携带完整历史。流式响应
设置stream=true 后,按 SSE 事件逐条处理:
| 事件 | 处理方式 |
|---|---|
response.created / response.in_progress | 本轮开始 |
response.output_text.delta | 将 delta 追加到正文 |
response.reasoning_text.delta / response.reasoning_summary_text.delta | 推理相关内容,和正文分开处理;客户端应兼容这两种事件形式 |
response.output_item.done | 收集完整输出项,例如 function_call |
response.completed | 本轮生成完成;读取 response.output 与 response.usage |
response.incomplete / response.failed / error | 处理截断或错误,结束本轮 |
[DONE]。HTTP 200 只表示流已建立,还要检查事件中的最终状态。工具调用轮次可能以 response.completed 结束,但仍需客户端执行函数并发起下一轮。
函数调用
在请求示例中选择“客户端函数调用”查看完整请求。Responses 的函数定义是平铺结构:{
"type": "function",
"name": "get_temperature",
"description": "返回指定城市温度",
"parameters": {
"type": "object",
"properties": {"city": {"type": "string"}},
"required": ["city"],
"additionalProperties": false
}
}
- 遍历
response.output,找出所有type="function_call"项。 - 解析并校验
argumentsJSON 字符串,再由你的程序执行对应函数。 - 将上一轮完整
output追加到历史,再为每个调用追加function_call_output,使用原始call_id与字符串形式的output。 - 把更新后的历史作为下一轮
input,继续请求。请求示例中的“回传函数执行结果”展示了这一结构。
parallel_tool_calls=false 不能确保每轮只调用一个函数。 客户端应处理本轮返回的全部函数调用,并在执行前校验参数。图像、搜索与 JSON 输出
- 图像理解:仅
glm-5.3-flash与glm-5.3-flashx支持。在用户消息的content中混排input_text与input_image,通过image_url传入图片公网 URL 或 Base64 Data URL。glm-5.3和glm-5.2不支持图像输入,请使用纯文本。 - 联网搜索:声明
tools: [{"type":"web_search"}]。搜索由服务端执行,结果通过web_search_call和正文返回;是否调用搜索以实际输出项为准。实际搜索除 token 外可能产生按次费用,以模型定价为准。 - JSON 输出:使用
text.format.type="json_object",在提示词中明确要求合法 JSON,并在客户端解析、校验。本接口暂不提供严格 JSON Schema 约束,不能依赖json_schema或strict=true确保输出符合指定结构。
output(包括 web_search_call 和 message)追加到 input,再加入新问题。保留输出项的原始 id、status、action 等字段。搜索已由服务端执行,无需为 web_search_call 构造 function_call_output。请求示例 web_search_history 展示了这一结构。
响应与用量
正文位于output 中 type="message" 项的 content[type="output_text"].text。响应可能包含顶层 output_text;为兼容该字段缺失的情况,仍应遍历 output。推理可能位于 reasoning.content 或 reasoning.summary,不要把它拼入正文。
usage.input_tokens包含缓存命中的输入;input_tokens_details.cached_tokens是其中的子集。usage.output_tokens包含推理 token;output_tokens_details.reasoning_tokens是其中的子集,可能为0或缺失。- 前缀缓存自动生效,无需额外
cache_control,命中量以本次返回的cached_tokens为准。 status="incomplete"且incomplete_details.reason="max_output_tokens"表示预算耗尽,可能只有推理、没有正文;请提高输出上限。
授权
在 Authorization 请求头中传入 Bearer YOUR_API_KEY。
请求体
选择 GLM 模型。四个型号均支持本接口的文本调用。
| 模型 ID | 输入能力 | 推理参数注意事项 |
|---|---|---|
glm-5.3 | 文本 | 实际思考档位为 low / high / max;支持兼容取值,见 reasoning;不能关闭思考 |
glm-5.3-flash | 文本、图像 | 同上;图像使用 input_image 内容块 |
glm-5.3-flashx | 文本、图像 | 同 glm-5.3;图像使用 input_image 内容块 |
glm-5.2 | 文本 | 传入 none 仍可能产生推理 token,不保证关闭思考 |
不同模型支持的能力有所不同,请查看对应型号的说明。
glm-5.3, glm-5.3-flash, glm-5.3-flashx, glm-5.2 "glm-5.3-flash"
必填。纯文本字符串,或 Responses 输入项数组。数组支持消息、回传的模型输出项与 function_call_output。多轮对话可在每次请求中携带完整历史;系统提示词推荐作为 role=system 消息放在数组首项。图片使用 input_image,仅 glm-5.3-flash 与 glm-5.3-flashx 支持。不要使用 Chat Completions 的 messages / image_url 内容块格式。
"请用一句话介绍你自己。"
本次生成的输出 token 上限,包含推理 token。建议从 1024 起按任务调整。过小可能在思考阶段耗尽预算,只返回 reasoning 项而没有正文;检查 status 和 incomplete_details。不要改写为 max_tokens。
x >= 11024
开启 SSE 流式返回。正文读取 response.output_text.delta 的 delta;成功终态为 response.completed。遇到 response.incomplete、response.failed 或 error 也应结束本轮并处理。不要只等待 [DONE] 或连接断开。
Responses 使用嵌套 reasoning.effort,而非顶层 reasoning_effort 或 thinking。推理用量包含在 output_tokens 中;简单任务可能返回 reasoning_tokens=0,这不代表支持关闭思考。
Show child attributes
Show child attributes
系统指令。glm-5.3-flash 可在 input 为字符串时使用此字段。input 为消息数组时,请将系统提示词放在数组首项的 role=system 消息中。
支持客户端 function 工具和服务端 web_search。函数声明使用平铺的 name / description / parameters,不能嵌套成 Chat Completions 的 function 对象。function_call 需要由你的程序执行并回传结果;web_search 由服务端执行,实际搜索除 token 外可能产生按次费用,以模型定价为准。
- Option 1
- Option 2
Show child attributes
Show child attributes
auto:由模型选择;none:不调用工具;required:要求调用工具;指定函数可传 {"type":"function","name":"get_temperature"}。并非所有模型与工具组合都保证支持相同的强制选择行为。
auto, none, required "auto"
是否允许一轮调用多个工具。设置 false 不能确保每轮只返回一个函数调用,客户端应遍历并处理全部 function_call。
输出格式。示例提供 json_object;HTTP 200 不等于返回内容满足 JSON Schema。
Show child attributes
Show child attributes
是否保存本次响应以便后续引用。glm-5.3-flash 与 glm-5.3-flashx 可配合 store=true 与 previous_response_id 串联多轮对话。glm-5.2 不支持响应 ID 续聊,设置 store=true 不会开启此能力;请在 input 中携带完整历史。
上一轮响应的顶层 id,用于串联多轮对话。glm-5.3-flash 与 glm-5.3-flashx 支持此方式,请配合 store=true 并保持相同模型。原样传入响应 id,不要使用 output 中某一项的 id。glm-5.2 不支持此方式,传入该字段会返回 400。需要跨型号使用时,请省略此字段并在 input 中携带完整历史。
"上一轮返回的响应 ID"
自定义字符串键值元数据,可在响应的 metadata 中读取。不要放入密钥或敏感信息。
Show child attributes
Show child attributes
{ "conversation": "demo" }
采样参数;具体有效范围和是否生效由模型决定。不要依赖它保证确定性,推理场景可省略。
采样参数;具体有效范围和是否生效由模型决定,通常可省略。
响应
生成成功或返回不完整结果;检查 status。流式时返回 text/event-stream。
本轮响应 ID。用于 previous_response_id 时原样传入。
"response_demo"
"response"创建时间,Unix 秒。
"glm-5.3-flash"
completed 表示本轮生成结束,也可能仅有工具调用;incomplete 表示输出不完整。请同时检查 output 和 error。
completed, incomplete, failed, in_progress, queued 有序输出项。遍历 type=message 的 content 中 type=output_text 的 text 得到正文。reasoning 可能在正文之前;function_call 轮次可能没有正文。不要固定读取 output[0]。
Show child attributes
Show child attributes
可选的正文聚合字段,可能缺失。通用客户端应遍历 output。
Show child attributes
Show child attributes
响应错误;成功时通常为 null。
Show child attributes
Show child attributes
Show child attributes
Show child attributes