Responses
使用 POST /v1/responses 调用 OpenAI Responses 风格接口。它适合新的文本工作流:单一 input 字段、多模态 content parts、结构化输出、工具调用,以及基于 response items 的返回结构。
接口地址
https://api.inoneapi.com/v1/responses
curl https://api.inoneapi.com/v1/responses \
-H "Authorization: Bearer $INONEAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "openai/gpt-4.1-mini",
"input": [
{
"role": "user",
"content": [
{ "type": "input_text", "text": "写一个三点网关检查清单。" }
]
}
],
"temperature": 0.2,
"max_output_tokens": 300
}'
参数
| 字段 | 类型 | 必填 | 说明 |
|---|---|---|---|
| model | string | 是 | 已启用 Responses 能力的 InOneAPI 公共模型 ID。 |
| input | string/array | 是 | 用户输入,可以是纯文本,也可以是消息风格 item 数组。 |
| instructions | string | 否 | 系统级行为指引,适合放长期角色、政策或输出要求。 |
| temperature | number | 否 | 采样随机性,范围取决于实际路由。 |
| top_p | number | 否 | 另一种采样控制。通常和 temperature 二选一调整。 |
| max_output_tokens | number | 否 | 生成输出 token 上限。 |
| stream | boolean | 否 | 为 true 时,在映射支持的情况下返回 Responses 事件流。 |
| tools | array | 否 | 函数等工具定义,是否可用取决于模型。 |
| tool_choice | string/object | 否 | 控制工具调用自动、必选或指定名称。 |
| response_format | object | 否 | 支持模型可用于 JSON object 或 schema 输出。 |
| metadata | object | 否 | 业务侧追踪元数据,不要放密钥。 |
输入结构
input 数组可以包含 user、assistant 或 tool-result item。内容通常是带类型的 content parts。
[
{
"role": "user",
"content": [
{ "type": "input_text", "text": "总结这个请求。" }
]
}
]
响应
Responses 返回 output 数组,而不是 Chat Completions 的 choices。文本通常位于 output[*].content[*].text,类型为 output_text。
{
"id": "resp_...",
"object": "response",
"created_at": 1760000000,
"status": "completed",
"model": "openai/gpt-4.1-mini",
"output": [
{
"type": "message",
"role": "assistant",
"content": [
{ "type": "output_text", "text": "- 检查认证\n- 检查路由\n- 检查计费" }
]
}
],
"usage": {
"input_tokens": 20,
"output_tokens": 15,
"total_tokens": 35
}
}
流式与 Trace
启用流式后,应按事件增量处理,直到收到最终完成事件。保存 X-Gateway-Trace-ID 并关联业务请求 ID,便于检查耗时、路由、重试和 token 诊断。
兼容说明
Responses 不是 Chat Completions 的直接替代。如果客户端读取 choices[0].message,继续使用 Chat Completions;如果客户端读取 output items,使用 Responses。映射可以归一化常见字段,但不支持的工具、content part 或 response format 仍会返回验证错误。