Responses 协议
原生支持 OpenAI Responses API(/v1/responses)——面向 agent 的新一代接口,是 Chat Completions 的后继。部分新模型(如 GPT-5.1)的能力只在 Responses 上开放。可直接使用 OpenAI SDK 的 responses.create() 或任何 Responses 兼容客户端,请求体一字不动透传到上游。
端点
POST https://api.dsesnet.com/v1/responses model 写在 body 里;流式用 "stream": true。
请求示例
{
"model": "gpt-5.1",
"input": [
{"role": "user", "content": "What is the capital of France?"}
],
"max_output_tokens": 200
} 必需的 HTTP 头
| Header | 值 | 说明 |
|---|---|---|
Authorization | Bearer gw-your-key | 网关 API Key |
Content-Type | application/json | 请求体格式 |
请求体字段
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 平台模型名,如 gpt-5.1 |
input | string 或 array | 是 | 输入内容(取代 Chat 的 messages):可为纯字符串或结构化 item 数组 |
instructions | string | 否 | 系统指令(独立字段,不放在 input 里) |
max_output_tokens | int | 否 | 最大输出 token(对应 Chat 的 max_tokens) |
reasoning | object | 否 | 推理控制,如 {"effort":"medium"} |
tools | array | 否 | 工具定义,含函数调用与内建工具(见下) |
stream | bool | 否 | 是否流式 |
previous_response_id | string | 否 | 上游侧多轮会话续接 |
响应示例
{
"id": "resp_abc123",
"object": "response",
"status": "completed",
"model": "gpt-5.1",
"output": [
{
"type": "message",
"role": "assistant",
"content": [{"type": "output_text", "text": "The capital of France is Paris."}]
}
],
"usage": {
"input_tokens": 8,
"output_tokens": 7,
"total_tokens": 15,
"input_tokens_details": {"cached_tokens": 0},
"output_tokens_details": {"reasoning_tokens": 0}
}
} 输出在 output[](有类型的 item 数组,取代 Chat 的 choices);文本在 type=="message" item 的 content[].output_text。用量在 usage:input_tokens / output_tokens(含 reasoning)/ input_tokens_details.cached_tokens / output_tokens_details.reasoning_tokens。
使用 curl
curl -X POST "https://api.dsesnet.com/v1/responses" \
-H "Authorization: Bearer gw-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.1",
"input": "Hello!",
"max_output_tokens": 100
}' 流式响应
设 "stream": true,响应为有类型的语义事件流(response.output_text.delta、response.completed 等),没有 [DONE] 哨兵,以 response.completed 事件结束(其中带完整 usage):
curl -N -X POST "https://api.dsesnet.com/v1/responses" \
-H "Authorization: Bearer gw-your-key" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-5.1",
"input": "Tell me a story",
"stream": true
}' 使用 OpenAI SDK
from openai import OpenAI
# 指向网关,使用网关 Key
client = OpenAI(
api_key="gw-your-key-here",
base_url="https://api.dsesnet.com/v1",
)
resp = client.responses.create(
model="gpt-5.1",
input="Hello!",
)
print(resp.output_text) 内建工具
Responses 支持由模型侧托管执行的内建工具(如 web_search)。在 tools 里声明即可,工具由上游执行、结果直接并入 output[]:
{
"model": "gpt-5.1",
"input": "What are today's top AI headlines?",
"tools": [{"type": "web_search"}]
} 内建工具按调用次数额外计费(叠加在 token 之上),具体单价见各模型定价。普通函数调用(type: "function")不额外收费,只按 token 计。
支持的模型
当前网关已接入 Responses 协议的模型:
gpt-5.1
完整列表和价格见 模型列表 页面。
与 Chat Completions 的区别
| 维度 | Chat Completions | Responses |
|---|---|---|
| 端点 | /v1/chat/completions | /v1/responses |
| 输入 | messages[] | input + instructions |
| 输出 | choices[].message | output[](有类型 item) |
| 上限字段 | max_tokens | max_output_tokens |
| 流式 | delta chunk + [DONE] | 语义事件,无 [DONE] |
| Token 字段 | prompt_tokens/completion_tokens | input_tokens/output_tokens |
| 内建工具 | 无 | web_search 等 |
Chat Completions 不会消失,但新模型能力优先进 Responses。三种协议共享同一套 API Key、余额和计费系统。
说明
- 请求体原样透传到上游,网关只解析响应里的
usage提取 token 数与内建工具调用次数用于计费,不修改请求内容。 - 流式响应中只有
response.completed事件包含完整usage(这是 Responses 协议标准行为)。