OpenResponses API(HTTP)
OpenClaw 的 Gateway 可以提供 OpenResponses 相容的POST /v1/responses endpoint。
此 endpoint 預設停用。請先在設定中啟用。
POST /v1/responses- 與 Gateway 使用相同埠(WS + HTTP 多工):
http://<gateway-host>:<port>/v1/responses
openclaw agent 相同的程式碼路徑),因此路由/權限/設定與您的 Gateway 一致。
認證
使用 Gateway 認證設定。傳送 bearer token:Authorization: Bearer <token>
- 當
gateway.auth.mode="token"時,使用gateway.auth.token(或OPENCLAW_GATEWAY_TOKEN)。 - 當
gateway.auth.mode="password"時,使用gateway.auth.password(或OPENCLAW_GATEWAY_PASSWORD)。 - 若設定了
gateway.auth.rateLimit且發生太多認證失敗,endpoint 會返回帶有Retry-After的429。
安全邊界(重要)
將此 endpoint 視為 gateway 實例的完整 operator 存取介面。- 此處的 HTTP bearer 認證不是狹義的每使用者範圍模型。
- 此 endpoint 的有效 Gateway token/password 應視為擁有者/operator 憑證。
- 請求透過與受信任的 operator 操作相同的控制平面 agent 路徑執行。
- 此 endpoint 沒有獨立的非擁有者/每使用者工具邊界;一旦呼叫者通過此處的 Gateway 認證,OpenClaw 將該呼叫者視為此 gateway 的受信任 operator。
- 若目標 agent 政策允許敏感工具,此 endpoint 可以使用它們。
- 僅在 loopback/tailnet/私有 ingress 上保留此 endpoint;不要直接暴露到公共網路。
選擇 Agent
不需要自訂 header:在 OpenResponsesmodel 欄位中編碼 agent id:
model: "openclaw:<agentId>"(範例:"openclaw:main"、"openclaw:beta")model: "agent:<agentId>"(別名)
x-openclaw-agent-id: <agentId>(預設:main)
x-openclaw-session-key: <sessionKey>完全控制 session 路由。
啟用 endpoint
將gateway.http.endpoints.responses.enabled 設為 true:
停用 endpoint
將gateway.http.endpoints.responses.enabled 設為 false:
Session 行為
預設情況下,endpoint 每個請求無狀態(每次呼叫生成新的 session 鍵)。 若請求包含 OpenResponsesuser 字串,Gateway 會從中衍生穩定的 session 鍵,讓重複呼叫可以共享 agent session。
請求格式(支援項目)
請求遵循 OpenResponses API 的 item-based 輸入格式。目前支援:input:字串或 item 物件陣列。instructions:合併至系統 prompt。tools:client tool 定義(function tools)。tool_choice:篩選或要求 client tools。stream:啟用 SSE streaming。max_output_tokens:盡力而為的輸出限制(取決於供應商)。user:穩定的 session 路由。
max_tool_callsreasoningmetadatastoreprevious_response_idtruncation
Items(輸入)
message
角色:system、developer、user、assistant。
system和developer附加至系統 prompt。- 最近的
user或function_call_outputitem 成為「目前訊息」。 - 較早的 user/assistant 訊息作為上下文歷史記錄包含。
function_call_output(輪次型工具)
將工具結果回傳給模型:
reasoning 和 item_reference
為了 schema 相容性而接受,但在建立 prompt 時忽略。
Tools(client 端 function tools)
提供工具:tools: [{ type: "function", function: { name, description?, parameters? } }]。
若 agent 決定呼叫工具,回應會返回 function_call 輸出 item。然後您發送包含 function_call_output 的後續請求以繼續輪次。
圖片(input_image)
支援 base64 或 URL 來源:
image/jpeg、image/png、image/gif、image/webp、image/heic、image/heif。
最大大小(目前):10MB。
檔案(input_file)
支援 base64 或 URL 來源:
text/plain、text/markdown、text/html、text/csv、
application/json、application/pdf。
最大大小(目前):5MB。
目前行為:
- 檔案內容被解碼並加入系統 prompt,而非使用者訊息, 因此保持短暫性(不持久化在 session 歷史記錄中)。
- PDF 會進行文字解析。若找到的文字很少,前幾頁會被柵格化 為圖片並傳給模型。
pdfjs-dist 舊版構建(無 worker)。現代
PDF.js 構建需要瀏覽器 workers/DOM globals,因此不在 Gateway 中使用。
URL 取得預設值:
files.allowUrl:trueimages.allowUrl:truemaxUrlParts:8(每個請求基於 URL 的input_file+input_image部分總數)- 請求受到保護(DNS 解析、私有 IP 封鎖、重新導向上限、逾時)。
- 每個輸入類型支援選用的 hostname allowlists(
files.urlAllowlist、images.urlAllowlist)。- 完全比對 host:
"cdn.example.com" - 萬用字元子網域:
"*.assets.example.com"(不比對 apex)
- 完全比對 host:
檔案 + 圖片限制(設定)
預設值可在gateway.http.endpoints.responses 下調整:
maxBodyBytes:20MBmaxUrlParts:8files.maxBytes:5MBfiles.maxChars:200kfiles.maxRedirects:3files.timeoutMs:10sfiles.pdf.maxPages:4files.pdf.maxPixels:4,000,000files.pdf.minTextChars:200images.maxBytes:10MBimages.maxRedirects:3images.timeoutMs:10s- HEIC/HEIF
input_image來源被接受並在傳遞給供應商前正規化為 JPEG。
- URL allowlists 在取得前和重新導向跳轉時強制執行。
- 將 hostname 加入 allowlist 不會繞過私有/內部 IP 封鎖。
- 對於暴露到網路的 gateway,除了應用層面的防護外,還需套用網路出口控制。 請參閱 Security。
Streaming(SSE)
設定stream: true 以接收 Server-Sent Events(SSE):
Content-Type: text/event-stream- 每個事件行為
event: <type>和data: <json> - 串流以
data: [DONE]結束
response.createdresponse.in_progressresponse.output_item.addedresponse.content_part.addedresponse.output_text.deltaresponse.output_text.doneresponse.content_part.doneresponse.output_item.doneresponse.completedresponse.failed(發生錯誤時)
使用量
當底層供應商回報 token 數量時,usage 會被填充。
錯誤
錯誤使用如下 JSON 物件:401遺失/無效的認證400無效的請求本體405錯誤的方法