API 参考
Responses
POST /v1/responses 接口:内置工具、推理参数与响应结构。
Responses 是 OpenAI 的新一代统一接口,FIM Gate 提供同格式的转发。相比 Chat Completions,它用更灵活的 input 取代 messages,并支持网页搜索等内置工具和推理强度参数。
端点
| 项目 | 值 |
|---|---|
| 方法与路径 | POST /v1/responses |
| Base URL | https://api.gate.fim.ai/v1 |
| 鉴权 | Authorization: Bearer $FIM_API_KEY |
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 模型 ID,如 gpt-4.1、o3-mini |
input | string / array | 是 | 输入内容:纯字符串,或由带 role 的消息对象组成的数组 |
instructions | string | 否 | 系统级指令,作用类似 system 提示词 |
stream | boolean | 否 | 设为 true 启用 SSE 流式事件输出 |
max_output_tokens | integer | 否 | 输出 token 上限(含推理 token) |
temperature | number | 否 | 采样温度,0–2 |
top_p | number | 否 | 核采样阈值,0–1 |
tools | array | 否 | 工具列表,支持内置工具(如 {"type": "web_search_preview"})和自定义函数 |
tool_choice | string / object | 否 | 工具调用策略 |
reasoning | object | 否 | 推理模型专用,如 {"effort": "low" | "medium" | "high"} 控制思考强度 |
消息数组形式的 input 中,多模态内容块类型为 input_text 和 input_image(注意与 Chat Completions 的 text / image_url 命名不同)。
文本请求
curl https://api.gate.fim.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $FIM_API_KEY" \
-d '{
"model": "gpt-4.1",
"input": "用三句话讲一个关于灯塔的睡前故事"
}'响应结构:
{
"id": "resp_abc123",
"object": "response",
"created_at": 1765500000,
"status": "completed",
"model": "gpt-4.1",
"output": [
{
"id": "msg_def456",
"type": "message",
"role": "assistant",
"content": [
{
"type": "output_text",
"text": "海边有一座老灯塔……",
"annotations": []
}
]
}
],
"usage": {
"input_tokens": 18,
"output_tokens": 74,
"total_tokens": 92
}
}生成的文本位于 output 数组中 type: "message" 项的 content[].text。
status 字段
| 取值 | 含义 |
|---|---|
completed | 正常完成 |
incomplete | 输出被截断,原因见 incomplete_details.reason(如 max_output_tokens 表示达到输出上限) |
failed | 请求失败 |
图像输入
curl https://api.gate.fim.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $FIM_API_KEY" \
-d '{
"model": "gpt-4.1",
"input": [
{
"role": "user",
"content": [
{"type": "input_text", "text": "这张图里有什么?"},
{"type": "input_image", "image_url": "https://example.com/photo.jpg"}
]
}
]
}'注意 input_image 的 image_url 直接是字符串,不像 Chat Completions 那样嵌套 {"url": ...} 对象。
内置工具:网页搜索
声明 web_search_preview 工具后,模型可自行联网检索再作答:
curl https://api.gate.fim.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $FIM_API_KEY" \
-d '{
"model": "gpt-4.1",
"tools": [{"type": "web_search_preview"}],
"input": "总结今天的一条科技新闻"
}'使用搜索时,output 数组会先出现 type: "web_search_call" 项,随后才是带引用标注(annotations)的 message 项。
OpenAI 的 deep-research 系列模型(如 o3-deep-research、o4-mini-deep-research)必须携带网页搜索或 MCP 工具才能运行,否则会直接报错。
推理参数
对推理模型可通过 reasoning.effort 控制思考投入:
curl https://api.gate.fim.ai/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer $FIM_API_KEY" \
-d '{
"model": "o3-mini",
"input": "9.11 和 9.9 哪个大?给出推理过程",
"reasoning": {"effort": "high"}
}'effort 越高,模型思考越充分,消耗的推理 token 也越多。OpenAI 推理模型不返回思考过程原文,只在 usage 中体现推理 token 用量。
使用提示
- 推理模型慎设
max_output_tokens:推理 token 计入上限,过小会得到status: "incomplete"且incomplete_details.reason为max_output_tokens的空结果。 - 深度研究类任务耗时较长,建议开启
stream并适当放宽客户端超时。