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 令牌:Authorization: Bearer <token>
- 当
gateway.auth.mode="token"时,使用gateway.auth.token(或OPENCLAW_GATEWAY_TOKEN)。 - 当
gateway.auth.mode="password"时,使用gateway.auth.password(或OPENCLAW_GATEWAY_PASSWORD)。
选择智能体
无需自定义头:在 OpenResponsesmodel 字段中编码智能体 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:
会话行为
默认情况下,端点每个请求都是无状态的(每次调用生成新的会话键)。 如果请求包含 OpenResponsesuser 字符串,Gateway 网关会从中派生稳定的会话键,这样重复调用可以共享智能体会话。
请求结构(支持的)
请求遵循 OpenResponses API,使用基于 item 的输入。当前支持:input:字符串或 item 对象数组。instructions:合并到系统提示中。tools:客户端工具定义(函数工具)。tool_choice:过滤或要求客户端工具。stream:启用 SSE 流式传输。max_output_tokens:尽力而为的输出限制(取决于提供商)。user:稳定的会话路由。
max_tool_callsreasoningmetadatastoreprevious_response_idtruncation
Item(输入)
message
角色:system、developer、user、assistant。
system和developer追加到系统提示。- 最近的
user或function_call_outputitem 成为”当前消息”。 - 较早的 user/assistant 消息作为上下文历史包含。
function_call_output(基于回合的工具)
将工具结果发送回模型:
reasoning 和 item_reference
为了 schema 兼容性而接受,但在构建提示时忽略。
工具(客户端函数工具)
使用tools: [{ type: "function", function: { name, description?, parameters? } }] 提供工具。
如果智能体决定调用工具,响应返回一个 function_call 输出 item。然后你发送带有 function_call_output 的后续请求以继续回合。
图像(input_image)
支持 base64 或 URL 来源:
image/jpeg、image/png、image/gif、image/webp。
最大大小(当前):10MB。
文件(input_file)
支持 base64 或 URL 来源:
text/plain、text/markdown、text/html、text/csv、application/json、application/pdf。
最大大小(当前):5MB。
当前行为:
- 文件内容被解码并添加到系统提示,而不是用户消息,所以它保持临时性(不持久化在会话历史中)。
- PDF 被解析提取文本。如果发现的文本很少,前几页会被栅格化为图像并传递给模型。
pdfjs-dist legacy 构建(无 worker)。现代 PDF.js 构建期望浏览器 worker/DOM 全局变量,因此不在 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
流式传输(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(出错时)
用量
当底层提供商报告令牌计数时,usage 会被填充。
错误
错误使用如下 JSON 对象:401缺少/无效认证400无效请求体405错误的方法