OpenAI Responses
通过 OpenAI Responses API 调用模型,这是 OpenAI 推出的新一代 API 格式,支持更丰富的多模态输入、内置工具调用和对话上下文管理。
在线体验
快速开始
第 1 步: 获取您的 API Key(在 控制台 创建)。
第 2 步: 发送请求:
bash
curl -X POST "https://open.dieyuyun.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxx" \
-d '{
"model": "deepseek-v4-flash",
"input": "简要介绍一下人工智能的历史"
}'python
from openai import OpenAI
client = OpenAI(
api_key="sk-xxx",
base_url="https://open.dieyuyun.com/v1"
)
response = client.responses.create(
model="deepseek-v4-flash",
input="简要介绍一下人工智能的历史"
)
print(response.output[0].content[0].text)javascript
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: 'sk-xxx',
baseURL: 'https://open.dieyuyun.com/v1',
})
const response = await client.responses.create({
model: 'deepseek-v4-flash',
input: '简要介绍一下人工智能的历史',
})
console.log(response.output[0].content[0].text)第 3 步: 从 output[0].content[0].text 获取模型回复。
请求端点
| 项目 | 值 |
|---|---|
| 方法 | POST |
| 路径 | /v1/responses |
/v1/responses/compact(上下文压缩) | |
| Base URL | https://open.dieyuyun.com |
| 兼容协议 | OpenAI Responses API |
认证
所有请求均需在请求头中携带 Bearer Token:
http
Authorization: Bearer sk-xxx支持模型
| 模型 | 提供商 | 上下文长度 | 说明 |
|---|---|---|---|
| deepseek-v4-flash | DeepSeek | 1M | 极速响应、低成本,适合高频调用 |
| deepseek-v4-pro | DeepSeek | 1M | 复杂推理、高质量输出 |
| qwen3.7-max | 通义千问 | 1M | 通义千问旗舰模型 |
TIP
完整模型列表请在 控制台 查看。Responses API 的模型支持范围可能与 Chat Completions 有所不同。
标准请求字段
| 字段 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| model | string | 是 | — | 模型标识符,如 deepseek-v4-flash |
| input | string / array | 是 | — | 输入内容,支持简单字符串或结构化消息数组 |
| instructions | string | 否 | — | 系统指令(等同于 system 提示词) |
| previous_response_id | string | 否 | — | 关联前一次响应的 ID,实现多轮对话 |
| stream | boolean | 否 | false | 是否启用流式输出 |
| stream_options | object | 否 | — | 流式配置 |
| tools | array | 否 | — | 工具定义列表 |
| tool_choice | string / object | 否 | auto | 工具调用策略 |
| temperature | number | 否 | 1 | 控制输出随机性 |
| top_p | number | 否 | 1 | 核采样参数 |
| max_output_tokens | integer | 否 | — | 最大输出 Token 数 |
| reasoning | object | 否 | — | 推理配置(仅推理模型) |
| parallel_tool_calls | boolean | 否 | true | 是否允许并行工具调用 |
输入格式
Responses API 的 input 字段支持两种格式:
简单字符串:
json
{
"model": "deepseek-v4-flash",
"input": "你好"
}结构化数组(支持多模态):
json
{
"model": "deepseek-v4-flash",
"input": [
{
"role": "user",
"content": [
{ "type": "input_text", "text": "这张图片里有什么?" },
{ "type": "input_image", "image_url": "https://example.com/photo.jpg" }
]
}
]
}输入内容类型
| 类型 | 说明 | 字段 |
|---|---|---|
| input_text | 文本输入 | text |
| input_image | 图片输入 | image_url 或 image_file |
| input_file | 文件输入 | file |
请求示例
多模态输入
bash
curl -X POST "https://open.dieyuyun.com/v1/responses" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-xxx" \
-d '{
"model": "deepseek-v4-flash",
"input": [
{
"role": "user",
"content": [
{"type": "input_text", "text": "这张图片里有什么?"},
{"type": "input_image", "image_url": "https://example.com/photo.jpg"}
]
}
]
}'python
from openai import OpenAI
client = OpenAI(
api_key="sk-xxx",
base_url="https://open.dieyuyun.com/v1"
)
response = client.responses.create(
model="deepseek-v4-flash",
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": "这张图片里有什么?"},
{"type": "input_image", "image_url": "https://example.com/photo.jpg"}
]
}
]
)
print(response.output[0].content[0].text)javascript
import OpenAI from 'openai'
const client = new OpenAI({
apiKey: 'sk-xxx',
baseURL: 'https://open.dieyuyun.com/v1',
})
const response = await client.responses.create({
model: 'deepseek-v4-flash',
input: [
{
role: 'user',
content: [
{ type: 'input_text', text: '这张图片里有什么?' },
{ type: 'input_image', image_url: 'https://example.com/photo.jpg' },
],
},
],
})
console.log(response.output[0].content[0].text)多轮对话(使用 previous_response_id)
json
// 第一次请求
{
"model": "deepseek-v4-flash",
"instructions": "你是一个技术助手。",
"input": "什么是机器学习?"
}
// 第二次请求 - 引用前一次响应
{
"model": "deepseek-v4-flash",
"previous_response_id": "resp_abc123",
"input": "它和深度学习有什么区别?"
}带工具调用
json
{
"model": "deepseek-v4-flash",
"instructions": "你是一个有用的助手。",
"input": "北京今天天气怎么样?",
"tools": [
{
"type": "function",
"name": "get_weather",
"description": "获取指定城市的天气信息",
"parameters": {
"type": "object",
"properties": {
"city": {
"type": "string",
"description": "城市名称"
}
},
"required": ["city"]
}
}
]
}流式输出
python
from openai import OpenAI
client = OpenAI(
api_key="sk-xxx",
base_url="https://open.dieyuyun.com/v1"
)
stream = client.responses.create(
model="deepseek-v4-flash",
input="写一个 Python 快速排序算法",
stream=True
)
for event in stream:
if hasattr(event, 'delta') and event.delta:
print(event.delta, end="", flush=True)响应格式
成功响应
json
{
"id": "resp_abc123",
"object": "response",
"created_at": 1712345678,
"status": "completed",
"model": "deepseek-v4-flash",
"output": [
{
"id": "msg_abc123",
"type": "message",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "人工智能的历史可以追溯到 20 世纪 50 年代。1956 年达特茅斯会议被认为是 AI 作为独立学科的诞生标志...",
"annotations": []
}
]
}
],
"parallel_tool_calls": true,
"tools": [],
"usage": {
"input_tokens": 8,
"output_tokens": 256,
"total_tokens": 264
}
}响应字段说明
| 字段 | 说明 |
|---|---|
| id | 响应唯一标识 |
| object | 固定为 response |
| status | 状态:completed、in_progress、failed |
| output | 输出内容数组(替代 Chat Completions 的 choices) |
| output[].type | 输出类型:message、tool_call |
| output[].content[].type | 内容类型:output_text |
| output[].content[].text | 模型回复文本 |
| output[].content[].annotations | 注解信息 |
| usage.input_tokens | 输入 Token 数 |
| usage.output_tokens | 输出 Token 数 |
| usage.total_tokens | 总 Token 数 |
流式 SSE 事件
流式输出返回以下事件类型:
data: {"type":"response.created","response":{"id":"resp_abc123",...}}
data: {"type":"response.output_text.delta","delta":"人工"}
data: {"type":"response.output_text.delta","delta":"智能"}
data: {"type":"response.output_text.delta","delta":"的历史"}
data: {"type":"response.output_text.done","text":"人工智能的历史..."}
data: {"type":"response.completed","response":{"id":"resp_abc123","status":"completed",...}}错误响应
json
{
"error": {
"message": "Invalid input: expected string or array",
"type": "invalid_request_error",
"param": "input",
"code": "invalid_input"
}
}详见 错误码。
兼容性说明
| 特性 | 本平台 | OpenAI Responses API |
|---|---|---|
| 响应格式 | 完全兼容 | 原生协议 |
| 多模态输入 | 支持 text / image / file | 原生支持 |
| previous_response_id | 支持 | 原生支持 |
| 工具调用(function) | 支持 | 原生支持 |
| 内置工具(web/file) | 取决于上游路由 | 原生支持 |
| 流式输出 | 支持 | 原生支持 |
| /responses/compact | 支持 | 原生支持 |
| 端点路径 | /v1/responses | /v1/responses |
TIP
Responses API 使用 output 数组替代 Chat Completions 的 choices 数组,使用 input 替代 messages。如果您的应用已经使用 Chat Completions API,无需迁移,两种格式均可正常使用。
最佳实践
- 选择合适的 API 格式:Responses API 适合需要多模态输入和内置上下文管理的场景;传统 Chat Completions 适合简单对话场景。
- 利用
previous_response_id:通过引用前一次响应 ID 实现多轮对话,无需手动管理消息历史。 - 使用
instructions替代system:Responses API 使用instructions字段设定系统行为。 - 结合
/responses/compact使用:对于长对话,使用 compact 端点压缩上下文,节省 Token 消耗。 - 注意 SDK 版本:Responses API 需要较新版本的 OpenAI SDK(Python >= 1.50.0,Node.js >= 4.50.0)。
速率限制
详见 速率限制。
相关文档
- 通用对话接口(流式) - 使用 OpenAI Chat Completions 协议
- 通用对话接口(非流式) - 非流式对话
- 管理 API Key - 创建和配置 API Key