使用 OpenAI Response API 进行图像分析
POST /v1/responses{
"id": "resp-abc123",
"object": "response",
"created": 1699896916,
"model": "gpt-4o",
"output": "The image shows a wooden boardwalk path extending through a lush green grassland.",
"usage": {
"prompt_tokens": 3500,
"completion_tokens": 245,
"total_tokens": 3745
}
}| 参数 | 类型 | 必填 | 默认值 | 范围 | 描述 |
|---|---|---|---|---|---|
model | string | 是 | - | - | 用于生成响应的模型 ID,如 gpt-4o 或 o3。 |
input | string/array | 是 | - | - | 模型的输入内容。 |
input.role | string | 是 | - | user, assistant, system, developer | 消息输入的角色。 |
input.content | string/array | 是 | - | - | 字符串时为模型的文本输入;数组时为包含不同内容类型的一个或多个输入项列表。 |
| 参数 | 类型 | 必填 | 默认值 | 范围 | 描述 |
|---|---|---|---|---|---|
stream | boolean | 否 | false | true, false | 是否以增量方式流式返回响应。默认为 false。 |
max_output_tokens | integer | 否 | - | - | 响应可生成的 token 数量的上限,包括可见输出 token 和推理 token。 |
reasoning | object | 否 | - | - | 推理模型的配置选项(仅限 gpt-5 和 o 系列模型)。 |
reasoning.effort | string | 否 | medium | none, minimal, low, medium, high, xhigh | 限制推理模型的推理努力程度。 |
reasoning.summary | string | 否 | - | auto, concise, detailed | 模型执行的推理摘要。 |
tools | array | 否 | - | - | 模型可能调用的工具列表。 |
| 参数 | 类型 | 必填 | 默认值 | 范围 / 示例 | 描述 |
|---|---|---|---|---|---|
content.type | string | 是 | — | input_text, input_image, input_file | 标识多模态输入的内容块类型。 |
content.text | string | 否 | — | - | 模型的文本输入。 |
content.file_id | string | 否 | - | - | 要发送给模型的文件 ID。 |
content.detail | string | 否 | auto | high, low, auto | 图像的详细程度。仅在 type=input_image 时需要。 |
content.image_url | string | 否 | - | - | 图像的 URL。仅在 type=input_image 时需要。 |
content.file_url | string | 否 | - | - | 文件的 URL。仅在 type=input_file 时需要。 |
content.file_data | string | 否 | - | - | 文件的内容。仅在 type=input_file 时需要。 |
content.filename | string | 否 | - | - | 文件的名称。仅在 type=input_file 时需要。 |
| 错误码 | 错误名称 | 描述 |
|---|---|---|
| 401 | Unauthorized | API key 缺失或无效 |
| 403 | Forbidden | 您的 API key 没有权限访问此资源,或请求操作的余额不足 |
| 429 | Too Many Requests | 您已超出速率限制 |
| 500 | Internal server error | 服务器内部错误 |
| 503 | Content policy violation | 内容因安全原因被阻止(实际状态码为 400) |