跳轉到主要內容
POST
/
v1
/
responses
curl --request POST \
  --url https://toapis.com/v1/responses \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-5.3-codex-official",
    "instructions": "你是一個專業的代碼助手",
    "input": "用 Python 寫一個快速排序"
  }'
{
  "id": "resp_abc123",
  "object": "response",
  "status": "completed",
  "model": "gpt-5.3-codex-official",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "```python\ndef quicksort(arr):\n    if len(arr) <= 1:\n        return arr\n    pivot = arr[len(arr) // 2]\n    left = [x for x in arr if x < pivot]\n    middle = [x for x in arr if x == pivot]\n    right = [x for x in arr if x > pivot]\n    return quicksort(left) + middle + quicksort(right)\n```"
        }
      ]
    }
  ],
  "usage": {
    "input_tokens": 25,
    "output_tokens": 80,
    "total_tokens": 105
  }
}
Responses API 是 OpenAI 推出的新一代 Agentic 接口,相比 Chat Completions 提供更強大的能力:
  • 函數調用(Function Calling):模型可調用自定義函數
  • 內置工具web_search_preview(聯網搜索)等開箱即用
  • 服務端多輪上下文:通過 previous_response_id 自動維護對話歷史,無需客戶端傳完整消息
  • 推理力度控制:通過 reasoning.effort 精確調節思考深度
標註爲 Responses Only 的模型(如 gpt-5-pro-officialgpt-5.3-codex-official)僅支持此 API,不支持 Chat Completions。完整模型列表請參閱 模型一覽

Authorizations

Authorization
string
必填
使用 Bearer Token 認證
Authorization: Bearer YOUR_API_KEY
獲取 API Key:訪問 API Key 管理頁面

Body

model
string
必填
模型名稱示例:"gpt-5-pro-official""gpt-5.3-codex-official""gpt-5.2-official"
input
string | object[]
必填
用戶輸入,支持兩種格式:
  • 字符串:簡單文本輸入
  • 消息數組:多輪對話格式
instructions
string
系統指令,指導模型行爲(等同於 Chat Completions 中的 system message)
stream
boolean
預設值:false
是否啓用流式輸出
max_output_tokens
integer
生成內容的最大 token 數量
temperature
number
預設值:1
採樣溫度,範圍 0 ~ 2
top_p
number
預設值:1
核採樣概率閾值,範圍 0 ~ 1
previous_response_id
string
上一次響應的 ID,用於服務端自動拼接多輪上下文,無需客戶端傳完整歷史消息
reasoning
object
推理配置
tools
object[]
可用工具列表
tool_choice
string
預設值:"auto"
工具選擇策略:autononerequired

Response

id
string
響應的唯一標識符(可用作 previous_response_id
object
string
固定爲 response
status
string
響應狀態:completedfailedin_progress
output
object[]
輸出項列表,可能包含多種類型:
  • message:文本回復,包含 content[].text
  • function_call:函數調用請求,包含 namearguments
  • reasoning:推理過程(當 reasoning.effortnone 時出現)
  • web_search_call:聯網搜索調用記錄
usage
object
token 消耗統計
  • usage.input_tokens:輸入 token 數
  • usage.output_tokens:輸出 token 數
  • usage.output_tokens_details.reasoning_tokens:推理 token 數
  • usage.total_tokens:總 token 數
curl --request POST \
  --url https://toapis.com/v1/responses \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '{
    "model": "gpt-5.3-codex-official",
    "instructions": "你是一個專業的代碼助手",
    "input": "用 Python 寫一個快速排序"
  }'
{
  "id": "resp_abc123",
  "object": "response",
  "status": "completed",
  "model": "gpt-5.3-codex-official",
  "output": [
    {
      "type": "message",
      "role": "assistant",
      "content": [
        {
          "type": "output_text",
          "text": "```python\ndef quicksort(arr):\n    if len(arr) <= 1:\n        return arr\n    pivot = arr[len(arr) // 2]\n    left = [x for x in arr if x < pivot]\n    middle = [x for x in arr if x == pivot]\n    right = [x for x in arr if x > pivot]\n    return quicksort(left) + middle + quicksort(right)\n```"
        }
      ]
    }
  ],
  "usage": {
    "input_tokens": 25,
    "output_tokens": 80,
    "total_tokens": 105
  }
}