Skip to main content
POST
https://console.mixroute.io
/
v1
/
responses
curl --request POST \
  --url https://console.mixroute.io/v1/responses \
  --header 'Authorization: Bearer sk-xxxxxxxxxx' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-5.2",
    "max_output_tokens": 2048,
    "input": [
      {"role": "user", "content": "请用中文简要介绍人工智能"}
    ]
  }'
{
  "id": "resp_xxx",
  "object": "response",
  "created_at": 1768271369,
  "model": "gpt-5.2",
  "status": "completed",
  "output": [
    {
      "id": "msg_xxx",
      "type": "message",
      "status": "completed",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "人工智能(AI)是计算机科学的一个分支...",
          "annotations": []
        }
      ]
    }
  ],
  "usage": {
    "input_tokens": 25,
    "output_tokens": 150,
    "total_tokens": 175
  }
}

简介

Responses API 是 OpenAI 推出的新一代对话接口,专为推理模型(o 系列、GPT-5 系列)和高级功能设计。相比传统的 Chat Completions API,Responses API 提供了更精细的推理控制、内置工具支持和多模态输入能力。

适用场景

  • 推理密集型任务:使用 o1、o3-mini、o4-mini、GPT-5 等推理模型
  • 需要联网搜索:内置 Web Search Preview 工具
  • 高级工具调用:支持 Function Call 和 Custom Tool Call
  • 多轮对话延续:通过 previous_response_id 实现对话历史管理

认证

Bearer Token,如 Bearer sk-xxxxxxxxxx

请求参数

model
string
required
模型标识,如 gpt-5.2o4-minio3-mini
input
array
required
输入消息列表
max_output_tokens
integer
最大输出 token 数
stream
boolean
是否启用流式输出
reasoning
object
推理配置,如 {"effort": "high", "summary": "detailed"}
tools
array
工具列表,支持 Web Search 和函数调用
previous_response_id
string
上一条响应的 ID,用于延续对话

基础示例

curl -X POST "https://console.mixroute.io/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -d '{
    "model": "gpt-5.2",
    "max_output_tokens": 2048,
    "input": [
      {"role": "user", "content": "请用中文简要介绍人工智能"}
    ]
  }'

高级功能

联网搜索(Web Search)

curl -X POST "https://console.mixroute.io/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -d '{
    "model": "gpt-5.2",
    "stream": true,
    "input": [
      {"role": "user", "content": "今天的新闻头条是什么?"}
    ],
    "tools": [
      {
        "type": "web_search_preview"
      }
    ]
  }'

推理控制(Reasoning)

curl -X POST "https://console.mixroute.io/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -d '{
    "model": "o4-mini",
    "stream": true,
    "reasoning": {
      "effort": "medium",
      "summary": "auto"
    },
    "max_output_tokens": 4096,
    "input": [
      {"role": "user", "content": "计算 1+2+3+...+100 的和"}
    ]
  }'
说明: summary: "auto" 会自动生成推理摘要,适合快速获取结果。

自定义函数调用

curl -X POST "https://console.mixroute.io/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -d '{
    "model": "gpt-5.2",
    "input": [
      {"role": "user", "content": "北京今天天气怎么样?"}
    ],
    "tools": [
      {
        "type": "function",
        "function": {
          "name": "get_weather",
          "description": "获取指定城市的天气信息",
          "parameters": {
            "type": "object",
            "properties": {
              "city": {
                "type": "string",
                "description": "城市名称"
              },
              "unit": {
                "type": "string",
                "enum": ["celsius", "fahrenheit"],
                "description": "温度单位"
              }
            },
            "required": ["city"]
          }
        }
      }
    ],
    "tool_choice": "auto"
  }'

多模态输入

curl -X POST "https://console.mixroute.io/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -d '{
    "model": "gpt-5.2",
    "input": [
      {
        "role": "user",
        "content": [
          {
            "type": "input_text",
            "text": "这张图片里有什么?"
          },
          {
            "type": "input_image",
            "image_url": "https://console.mixroute.io/demo/sample-image.jpg"
          }
        ]
      }
    ]
  }'

对话延续

通过 previous_response_id 实现多轮对话的上下文延续:
# 第一轮对话
curl -X POST "https://console.mixroute.io/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -d '{
    "model": "gpt-5.2",
    "input": [
      {"role": "user", "content": "我叫小明,请记住我的名字"}
    ]
  }'

# 响应中会返回 id: "resp_abc123"

# 第二轮对话(延续上下文)
curl -X POST "https://console.mixroute.io/v1/responses" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer sk-xxxxxxxxxx" \
  -d '{
    "model": "gpt-5.2",
    "previous_response_id": "resp_abc123",
    "input": [
      {"role": "user", "content": "我叫什么名字?"}
    ]
  }'

响应格式

{
  "id": "resp_xxx",
  "object": "response",
  "created_at": 1709123456,
  "model": "gpt-5.2",
  "status": "completed",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "人工智能(Artificial Intelligence,简称AI)是计算机科学的一个分支..."
        }
      ]
    }
  ],
  "usage": {
    "input_tokens": 25,
    "output_tokens": 150,
    "total_tokens": 175
  }
}

对比:Responses API vs Chat Completions API

特性Responses APIChat Completions API
推理模型支持✅ 完整支持⚠️ 有限支持
内置 Web Search✅ 原生支持❌ 不支持
推理控制✅ 精细控制❌ 不支持
对话延续previous_response_id❌ 需手动管理
多模态输入✅ 完整支持✅ 支持
适用场景推理、搜索、高级功能通用对话
curl --request POST \
  --url https://console.mixroute.io/v1/responses \
  --header 'Authorization: Bearer sk-xxxxxxxxxx' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-5.2",
    "max_output_tokens": 2048,
    "input": [
      {"role": "user", "content": "请用中文简要介绍人工智能"}
    ]
  }'
{
  "id": "resp_xxx",
  "object": "response",
  "created_at": 1768271369,
  "model": "gpt-5.2",
  "status": "completed",
  "output": [
    {
      "id": "msg_xxx",
      "type": "message",
      "status": "completed",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "人工智能(AI)是计算机科学的一个分支...",
          "annotations": []
        }
      ]
    }
  ],
  "usage": {
    "input_tokens": 25,
    "output_tokens": 150,
    "total_tokens": 175
  }
}