Responses
面向 GLM 5 与 Codex 的 OpenAI 兼容 Responses API:请求结构、流式事件、哪些模型可以使用、鉴权方式,以及它与 Chat Completions 在用法和返回结构上的差异。
Responses
GLM5 提供兼容 Responses API 的端点,可用于 Codex Desktop、Codex CLI 以及其他使用 OpenAI Responses API 的客户端。
端点
POST https://glm5.app/api/v1/responses
使用 GLM5 API Key 鉴权:
Authorization: Bearer sk-glm5-...
Content-Type: application/json
文本响应
新接入默认使用 glm-5.3-flash:
curl https://glm5.app/api/v1/responses \
-H "Authorization: Bearer $GLM5_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.3-flash",
"input": "审阅这个函数,找出边界情况。",
"max_output_tokens": 800
}'
响应遵循标准 Responses 结构,包含 id、object: "response"、status、output、
output_text、model 和 usage。
Input items
input 可以是字符串,也可以是标准 input item 数组。支持 user、developer 和
system 角色的 message item。请在每次请求中发送完整输入历史;GLM5 不会在服务端
持久化 Responses 状态。
流式输出
将 stream 设置为 true 后,接口会通过 Server-Sent Events 返回标准生命周期事件,
包括 response.created、response.output_text.delta、response.output_text.done 和
response.completed。
curl --no-buffer https://glm5.app/api/v1/responses \
-H "Authorization: Bearer $GLM5_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.3-flash",
"input": "用一段话解释这个错误。",
"stream": true
}'
函数调用
函数工具使用 Responses 格式。GLM5 返回 function_call output item;客户端执行函数后,
在下一次请求中发送 function_call_output item。
{
"model": "glm-5.3-flash",
"input": "检查当前项目状态。",
"tools": [
{
"type": "function",
"name": "shell",
"description": "运行安全的 Shell 命令。",
"parameters": {
"type": "object",
"properties": { "command": { "type": "string" } },
"required": ["command"]
}
}
]
}
Responses 端点与 /v1/chat/completions 共用模型、API Key、积分、限流和消费上限;它不会
替客户端执行函数,也不会代替客户端提供内置网页搜索。
可安全重试的请求
可能因网络中断而重试的请求请携带 Idempotency-Key。同一 API Key、相同请求内容和相同 key 只会对应一个任务;重复提交会返回原始 request_id 与 status_url,不会再次调用模型或再次预扣积分。
Idempotency-Key: codex:turn_01JQ9KPC3H5YQ2T8
使用同一个 API Key 请求 GET /api/v1/requests/{request_id},可查看任务是 processing、success、error 或 cancelled,以及用量和安全错误信息。该接口不重放断流前的模型输出;GLM5 不会为了重试而保存 prompt 或回答内容。要停止仍在运行的请求(流式或非流式),可请求 POST /api/v1/requests/{request_id}/cancel;它先返回 202,随后写入最终 cancelled 状态。