Responses API
文本输入使用 input,输出长度使用 max_output_tokens。
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型名称,使用 GET /v1/models 返回的值。 |
input | string | array | 是 | 文本输入,可以是字符串或结构化输入项数组。 |
instructions | string | 否 | 为模型提供的系统级指令。 |
max_output_tokens | integer | 否 | 限制输出 token 数量。 |
stream | boolean | 否 | 是否以事件流返回增量结果,默认 false。 |
stream_options | object | 否 | 事件流选项。 |
temperature | number | 否 | 采样温度;数值越高,输出随机性越强。 |
top_p | number | 否 | 核采样参数,通常与 temperature 二选一调整。 |
reasoning | object | 否 | 推理配置,例如推理强度。 |
text | object | 否 | 文本输出格式配置。 |
tools | array | 否 | 可供模型调用的工具定义。 |
tool_choice | string | object | 否 | 控制是否自动调用工具或指定工具。 |
truncation | string | 否 | 上下文超出限制时的截断策略。 |
previous_response_id | string | 否 | 关联上一轮响应,实现多轮上下文衔接。 |
metadata | object | 否 | 附加到响应的业务元数据。 |
store | boolean | 否 | 是否保存响应。 |
user | string | 否 | 用于标识终端用户的业务标识。 |
响应参数
| 字段 | 类型 | 说明 |
|---|---|---|
id | string | 本次响应的唯一 ID。 |
object | string | 响应对象类型,通常为 response。 |
created_at | integer | 响应创建时间,Unix 时间戳。 |
status | string | 响应状态,例如 in_progress、completed 或 failed。 |
model | string | 实际处理请求的模型名称。 |
output | array | 输出项列表,文本消息的 type 为 message。 |
output[].id | string | 输出项 ID。 |
output[].role | string | 输出消息角色,通常为 assistant。 |
output[].status | string | 输出项状态。 |
output[].content | array | 消息内容列表。 |
output[].content[].type | string | 文本内容类型,通常为 output_text。 |
output[].content[].text | string | 生成的文本内容。 |
usage | object | null | token 用量信息。 |
usage.input_tokens | integer | 输入 token 数量。 |
usage.output_tokens | integer | 输出 token 数量。 |
usage.total_tokens | integer | 输入与输出 token 总数。 |
error | object | null | 失败时的错误信息。 |
incomplete_details | object | null | 响应未完成时的原因说明。 |
调用示例
cURL
非流式请求:
curl "https://api.example.com/v1/responses" \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-pro",
"instructions": "你是一个简洁、准确的助手。",
"input": "请用一句话介绍你自己",
"temperature": 0.7,
"max_output_tokens": 512
}'流式请求:
curl --no-buffer "https://api.example.com/v1/responses" \
-H "Authorization: Bearer <YOUR_API_KEY>" \
-H "Content-Type: application/json" \
-d '{
"model": "deepseek-v4-pro",
"input": "列出三个提高代码可读性的建议",
"stream": true,
"max_output_tokens": 512
}'响应示例
非流式响应:
{
"id": "resp_example",
"object": "response",
"created_at": 1710000000,
"status": "completed",
"model": "deepseek-v4-pro",
"output": [
{
"type": "message",
"id": "msg_example",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "我是一个文本生成助手。",
"annotations": []
}
]
}
],
"usage": {
"input_tokens": 24,
"output_tokens": 12,
"total_tokens": 36
}
}流式响应以事件逐段返回,文本增量位于 response.output_text.delta 事件的 delta 字段:
event: response.output_text.delta
data: {"type":"response.output_text.delta","delta":"我是","output_index":0,"content_index":0}
event: response.output_text.delta
data: {"type":"response.output_text.delta","delta":"一个文本生成助手。","output_index":0,"content_index":0}Last updated on