/v1/responses
POST https://ai-api.mandao.com/v1/responses
新版内容生成请求,OpenAI Responses API 格式。推荐新项目使用此接口。
请求参数
Header 参数
| 参数名 | 类型 | 必需 | 说明 |
|---|---|---|---|
| Authorization | string | 是 | Bearer Token 认证 |
| Content-Type | string | 是 | application/json |
Body 参数 (application/json)
| 参数名 | 类型 | 必需 | 说明 |
|---|---|---|---|
| model | string | 是 | 模型 ID,支持 GPT-5 系列 |
| input | string 或 array[object] | 是 | 用户输入,支持文本或多模态 |
| instructions | string | 否 | 系统指令 |
| max_output_tokens | integer | 否 | 最大输出 token 数 |
| temperature | number | 否 | 采样温度 |
| top_p | number | 否 | 核采样参数 |
| stream | boolean | 否 | 是否流式输出 |
| tools | array | 否 | 工具定义(支持 MCP) |
| tool_choice | string/object | 否 | 工具选择策略 |
| reasoning | object | 否 | 推理配置:{"effort": "medium", "summary": "auto"} |
| previous_response_id | string | 否 | 前一次响应的 ID,用于多轮对话 |
| conversation | string/object | 否 | 会话标识 |
| truncation | string | 否 | 截断策略:auto |
| metadata | object | 否 | 附加元数据 |
| store | boolean | 否 | 是否存储请求数据 |
| user | string | 否 | 用户标识 |
| text | object | 否 | 输出文本格式配置 |
| prompt_cache_key | string | 否 | 提示缓存键 |
| prompt_cache_retention | string | 否 | 缓存保留策略 |
多模态输入格式
{
"input": [
{
"role": "user",
"content": [
{"type": "input_text", "text": "描述这张图片"},
{"type": "input_image", "image_url": "https://example.com/image.png"}
]
}
]
}
请求示例
curl --location 'https://ai-api.mandao.com/v1/responses' \
--header 'Authorization: Bearer <your-api-key>' \
--header 'Content-Type: application/json' \
--data '{
"model": "gpt-5.1",
"input": [
{
"role": "user",
"content": "写一段ESP32上的Hello World程序"
}
],
"stream": false,
"max_output_tokens": 2048
}'
返回响应
200 成功
{
"id": "resp_xxx",
"object": "response",
"created_at": 1700000000,
"status": "completed",
"model": "gpt-5.1",
"output": [
{
"type": "message",
"id": "msg_xxx",
"status": "completed",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "```cpp\nvoid setup() {...}\n```",
"annotations": []
}
]
}
],
"usage": {
"input_tokens": 20,
"output_tokens": 150,
"total_tokens": 170
}
}
错误响应
{
"error": {
"message": "错误描述",
"type": "invalid_request_error",
"code": "invalid_model"
}
}
/v1/responses/compact
POST https://ai-api.mandao.com/v1/responses/compact
压缩版 Responses 接口,用于上下文压缩/摘要场景。
注意事项
- 推荐新系统和项目优先使用
/v1/responses接口。 - 当前主要支持 GPT-5 系列模型。
- 详细参数请参考 OpenAI Responses API 文档。