glm-5.4 是 GLM-5 系列新旗舰,与 GLM-5.3 不同在架构:28 层以共享权重循环两次,以计算深度换推理,难题输出 token 更少。面向复杂编程,上下文 1M token,最大输出 128K,支持工具调用和响应格式控制。
鉴权
- Base URL
https://api.dreamto.ai- Authorization
Authorization: Bearer YOUR_API_KEY- Content-Type
application/json- 模型名 (model)
glm-5.4
接入协议
为什么选这个协议
适合已有 OpenAI SDK、Chat Completions 代码或统一网关接入的用户。
接口地址
POST/v1/chat/completions
Authorization: Bearer YOUR_API_KEYContent-Type: application/json请求 / 响应 JSON
请求
{
"model": "glm-5.4",
"tools": [],
"top_p": 1,
"stream": false,
"messages": [
{
"role": "user",
"content": "你好,世界"
}
],
"max_tokens": 4096,
"temperature": 0.7,
"tool_choice": "auto",
"response_format": {
"type": "json_object"
},
"reasoning_effort": "medium",
"system_instruction": "你是一个严谨的助手。"
}响应
{
"id": "chatcmpl_example",
"model": "glm-5.4",
"usage": {
"total_tokens": 24,
"prompt_tokens": 8,
"completion_tokens": 16
},
"object": "chat.completion",
"choices": [
{
"index": 0,
"message": {
"role": "assistant",
"content": "你好,世界"
},
"finish_reason": "stop"
}
],
"created": 1710000000
}请求字段 / 响应字段
请求字段
| 字段 | 类型 | 必填 | 默认 | 可选值 / 范围 | 说明 | 示例 |
|---|---|---|---|---|---|---|
| messages | array | Y | - | - | OpenAI 兼容聊天消息数组。 | [{"role":"user","content":"你好,世界"}] |
| system_instruction | string | N | - | - | 用于约束角色、风格和回答边界。 | 你是一个严谨的助手。 |
| temperature | number | N | 0.7 | - | 控制随机性;越低越稳定。 | 0.7 |
| top_p | number | N | 1 | - | 核采样概率阈值。 | 1 |
| max_tokens | integer | N | - | - | 限制本次响应的最大输出长度。 | 4096 |
| stream | boolean | N | false | - | 是否使用流式响应。 | false |
| reasoning_effort | enum | N | medium | low, medium, high | 推理模型使用的 reasoning_effort。 | medium |
| response_format | object | N | - | - | 结构化输出格式,例如 JSON object。 | {"type":"json_object"} |
| tools | array | N | - | - | OpenAI tools/function calling 定义。 | [] |
| tool_choice | string | N | - | - | auto、none 或指定工具。 | auto |
响应字段
| 字段 | 类型 | 必填 | 默认 | 可选值 / 范围 | 说明 | 示例 |
|---|---|---|---|---|---|---|
| id | string | N | - | - | 本次请求的响应标识。 | chatcmpl_example |
| model | string | N | - | - | 实际响应的模型名称。 | glm-5.4 |
| choices[].message.content | string | N | - | - | 模型生成的主要文本内容。 | 你好,世界 |
| usage.prompt_tokens | integer | N | - | - | 请求输入消耗的 token 数。 | 8 |
| usage.completion_tokens | integer | N | - | - | 模型输出消耗的 token 数。 | 16 |
| usage.total_tokens | integer | N | - | - | 输入和输出合计 token 数。 | 24 |
| object | string | N | - | - | - | chat.completion |
| created | integer | N | - | - | - | 1710000000 |
| choices | array | N | - | - | - | [{"index":0,"message":{"role":"assistant","content":"你好,世界"},"finish_reason":"stop"}] |
| choices[] | object | N | - | - | - | {"index":0,"message":{"role":"assistant","content":"你好,世界"},"finish_reason":"stop"} |
| choices[].index | integer | N | - | - | - | 0 |
| choices[].message | object | N | - | - | - | {"role":"assistant","content":"你好,世界"} |
| choices[].message.role | string | N | - | - | - | assistant |
| choices[].finish_reason | string | N | - | - | - | stop |
| usage | object | N | - | - | - | {"total_tokens":24,"prompt_tokens":8,"completion_tokens":16} |
代码示例
cURLrequest.sh
curl -X POST "https://api.dreamto.ai/v1/chat/completions" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "glm-5.4",
"messages": [
{
"content": "你好,世界",
"role": "user"
}
],
"system_instruction": "你是一个严谨的助手。",
"temperature": 0.7,
"top_p": 1,
"max_tokens": 4096,
"stream": false,
"reasoning_effort": "medium",
"response_format": {
"type": "json_object"
},
"tools": [],
"tool_choice": "auto"
}'