OpenResponses API(HTTP)
OpenClaw 的 Gateway 可提供 OpenResponses 兼容的POST /v1/responses 端点。
该端点默认禁用,需先在配置中启用。
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)。
选择 agent
无需自定义 headers:在 OpenResponsesmodel 字段中编码 agent id:
model: "openclaw:<agentId>"(例如:"openclaw:main"、"openclaw:beta")model: "agent:<agentId>"(别名)
x-openclaw-agent-id: <agentId>(默认:main)
x-openclaw-session-key: <sessionKey>用于完全控制会话路由。
启用端点
将gateway.http.endpoints.responses.enabled 设为 true:
禁用端点
将gateway.http.endpoints.responses.enabled 设为 false:
会话行为
默认该端点每个请求无状态(每次调用都会生成新的 session key)。 若请求包含 OpenResponsesuser 字符串,Gateway 会基于它派生稳定 session key,以便重复调用共享同一 agent 会话。
请求形态(已支持)
请求遵循 OpenResponses API 的 item 输入。目前支持:input:字符串或 item 数组。instructions:合并到 system prompt。tools:客户端工具定义(function tools)。tool_choice:过滤或要求客户端工具。stream:启用 SSE streaming。max_output_tokens:best-effort 输出限制(依赖 provider)。user:稳定会话路由。
max_tool_callsreasoningmetadatastoreprevious_response_idtruncation
Items(输入)
message
角色:system、developer、user、assistant。
system与developer会追加到 system prompt。- 最新的
user或function_call_outputitem 将作为“当前消息”。 - 更早的 user/assistant 消息会作为历史用于上下文。
function_call_output(回合式工具)
将工具结果发回模型:
reasoning 与 item_reference
为兼容 schema 接受,但在构建 prompt 时忽略。
Tools(客户端侧 function tools)
通过tools: [{ type: "function", function: { name, description?, parameters? } }] 提供工具。
若 agent 决定调用工具,响应会返回一个 function_call 输出 item。随后发送带 function_call_output 的跟进请求继续回合。
Images(input_image)
支持 base64 或 URL:
image/jpeg、image/png、image/gif、image/webp。
最大大小(当前):10MB。
Files(input_file)
支持 base64 或 URL:
text/plain、text/markdown、text/html、text/csv、
application/json、application/pdf。
最大大小(当前):5MB。
当前行为:
- 文件内容解码后加入 system prompt,而非 user 消息,因此仅为临时内容(不会写入会话历史)。
- PDF 会解析文本;若文本太少,会将首页渲染为图片并传给模型。
pdfjs-dist legacy build(无 worker)。现代
PDF.js build 需要浏览器 worker/DOM globals,因此不用于 Gateway。
URL 拉取默认:
files.allowUrl:trueimages.allowUrl:true- 请求带保护(DNS 解析、私网 IP 阻止、重定向上限、超时)。
文件 + 图片限制(配置)
默认值可在gateway.http.endpoints.responses 下调整:
maxBodyBytes: 20MBfiles.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
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(出错时)
用量
当底层 provider 报告 token 计数时,usage 会填充。
错误
错误使用如下 JSON 形态:401缺少/无效认证400请求体无效405方法错误