Appearance
Responses
创建模型响应(兼容 OpenAI Responses API)。
POST /v1/responses请求地址:https://www.sky-ze.com/v1
与 Chat Completions 的区别
| Chat Completions | Responses | |
|---|---|---|
| 路径 | /v1/chat/completions | /v1/responses |
| 输入 | messages 消息数组 | input,字符串或消息数组 |
| 系统提示词 | messages 中 role: system | 独立的 instructions 字段 |
| 输出上限 | max_tokens | max_output_tokens |
| 返回结构 | choices[].message.content | output[] 数组,按 type 区分推理/正文/工具调用 |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | ✓ | 模型 ID,见 文本模型与计费 |
input | string / array | ✓ | 输入内容。字符串按单轮用户消息处理;数组格式为消息列表(同 messages) |
instructions | string | 系统级指令,等价于 Chat Completions 的 role: system | |
max_output_tokens | integer | 最大输出 token 数 | |
temperature | number | 采样温度 0~2 | |
stream | boolean | 是否流式输出,默认 false | |
tools | array | Function call 工具定义 | |
tool_choice | string/object | 工具选择策略 |
非流式调用
curl
bash
curl https://www.sky-ze.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "glm-5.3",
"instructions": "你是一个有帮助的助手。",
"input": "用一句话介绍量子计算。",
"max_output_tokens": 2000
}'响应
json
{
"id": "chatcmpl-xxx",
"object": "response",
"created_at": 1717008000,
"status": "completed",
"model": "GLM-5.3",
"output": [
{
"type": "reasoning",
"id": "chatcmpl-xxx_reasoning_0",
"status": "completed",
"summary": [
{"type": "summary_text", "text": "用户在问量子计算,需要用一句话概括……"}
]
},
{
"type": "message",
"id": "chatcmpl-xxx_msg_0",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "量子计算是一种利用量子力学原理进行信息处理的新型计算方式。"
}
]
}
],
"usage": {
"prompt_tokens": 28,
"completion_tokens": 18,
"total_tokens": 46
}
}取正文:
output是数组,需要按type === "message"过滤后取content[0].text。推理模型还会返回type === "reasoning"的条目,其summary[0].text为推理摘要。
流式输出
bash
curl https://www.sky-ze.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "glm-5.3",
"input": "讲个笑话",
"stream": true,
"max_output_tokens": 2000
}'响应为 SSE 事件流,每个事件包含 event: 名称与 data: JSON。主要事件类型:
| 事件 | 说明 |
|---|---|
response.created | 响应开始,返回完整的 response 骨架 |
response.output_item.added | 新增一个输出条目(推理或正文) |
response.reasoning_summary_text.delta | 推理摘要增量 |
response.output_text.delta | 正文增量,取 delta 字段拼接 |
response.completed | 响应结束,返回完整结果与 usage |
event: response.output_text.delta
data: {"type":"response.output_text.delta","delta":"三个","output_index":1,...}
event: response.output_text.delta
data: {"type":"response.output_text.delta","delta":"字","output_index":1,...}
event: response.completed
data: {"type":"response.completed","response":{...}}Function Calling
bash
curl https://www.sky-ze.com/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer your-api-key" \
-d '{
"model": "glm-5.3",
"input": "北京今天天气怎么样?",
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "获取指定城市的天气",
"parameters": {
"type": "object",
"properties": {
"city": {"type": "string", "description": "城市名称"}
},
"required": ["city"]
}
}
],
"max_output_tokens": 2000
}'模型决定调用工具时,output 中会出现 type: "function_call" 的条目:
json
{
"type": "function_call",
"name": "get_weather",
"arguments": "{\"city\": \"北京\"}",
"status": "completed"
}注意:Responses API 的
tools定义与 Chat Completions 不同 —— 函数字段平铺在顶层(name/description/parameters),不再包一层function对象。