Responses API
OpenAI 的新一代有狀態端點,內建工具、網頁搜尋、檔案搜尋與多步驟任務支援——逐步取代 Chat Completions。
建立 Response
POST /v1/responses请求REQUEST
POST
https://console.dotouch.ltd/v1/responses响应RESPONSE
填写参数并发送请求,响应会显示在这里
請求
curl https://console.dotouch.ltd/v1/responses \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-token" \
-d '{
"model": "gpt-4o-mini",
"input": "Describe the Responses API in one sentence"
}'
請求主體參數
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
model | string | 是 | 模型名稱 |
input | string / array | 是 | 輸入文字,或訊息/內容塊陣列 |
stream | boolean | 否 | 串流輸出(事件類型更豐富) |
instructions | string | 否 | 系統層級指令 |
previous_response_id | string | 否 | 傳入上一次的 Response ID 即可延續多輪對話,無需重送歷史 |
tools | array | 否 | 工具:function、web_search_preview 等 |
temperature / top_p | number | 否 | 取樣參數 |
max_output_tokens | number | 否 | 最大輸出 token 數 |
metadata | object | 否 | 自訂鍵值組(最多 16 組) |
store | boolean | 否 | 是否保存結果,供 previous_response_id 引用 |
input 為陣列的範例(含圖片):
{
"model": "gpt-4o-mini",
"input": [
{
"role": "user",
"content": [
{ "type": "input_text", "text": "Describe this image" },
{ "type": "input_image", "image_url": "https://example.com/cat.jpg" }
]
}
]
}
回應
{
"id": "resp_abc123",
"object": "response",
"created_at": 1730000000,
"status": "completed",
"model": "gpt-4o-mini",
"output": [
{
"type": "message",
"id": "msg_abc123",
"role": "assistant",
"status": "completed",
"content": [
{
"type": "output_text",
"text": "The Responses API is OpenAI's next-generation stateful endpoint…",
"annotations": []
}
]
}
],
"usage": {
"input_tokens": 12,
"output_tokens": 30,
"total_tokens": 42
}
}
要取出文字,可迭代 output 中 type: "message" 的項目並讀取 content[].text;SDK 也提供 resp.output_text 捷徑屬性。
查詢 Response
GET /v1/responses/{response_id}curl https://console.dotouch.ltd/v1/responses/resp_abc123 \
-H "Authorization: Bearer sk-your-token"
回傳完整的 Response 物件。以 store: false 建立的回應無法查詢。
壓縮上下文
POST /v1/responses/compact把長對話壓縮成摘要——適合長時間執行的 Agent,可減少後續請求的 token 消耗:
curl https://console.dotouch.ltd/v1/responses/compact \
-H "Content-Type: application/json" \
-H "Authorization: Bearer sk-your-token" \
-d '{
"model": "gpt-4o-mini",
"input": [ ...long message array... ]
}'
| 參數 | 類型 | 必填 | 說明 |
|---|---|---|---|
model | string | 是 | 用於壓縮的模型 |
input | array | 是 | 要壓縮的訊息陣列 |
instructions | string | 否 | 摘要的自訂指令 |
回傳壓縮後的摘要物件,可放進下一次請求的 input。
備註
WebSocket 存取方式(wss://.../v1/responses 搭配 response.create 事件)取決於閘道對 WS 的轉傳支援——REST + SSE 仍是用戶端整合的主要路徑,此處不另說明。