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
  }
}