Skip to content

Responses ​

创建模型响应(兼容 OpenAI Responses API)。

POST /v1/responses

请求地址:https://www.sky-ze.com/v1

与 Chat Completions 的区别 ​

Chat CompletionsResponses
路径/v1/chat/completions/v1/responses
输入messages 消息数组input,字符串或消息数组
系统提示词messages 中 role: system独立的 instructions 字段
输出上限max_tokensmax_output_tokens
返回结构choices[].message.contentoutput[] 数组,按 type 区分推理/正文/工具调用

请求参数 ​

参数类型必填说明
modelstring✓模型 ID,见 文本模型与计费
inputstring / array✓输入内容。字符串按单轮用户消息处理;数组格式为消息列表(同 messages)
instructionsstring系统级指令,等价于 Chat Completions 的 role: system
max_output_tokensinteger最大输出 token 数
temperaturenumber采样温度 0~2
streamboolean是否流式输出,默认 false
toolsarrayFunction call 工具定义
tool_choicestring/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 对象。

天绛白泽 | Token工厂