OpenResponses API(HTTP)
OpenClaw 的网关可以提供与 OpenResponses 兼容的POST /v1/responses 端点。
此端点默认处于禁用状态。请先在配置中将其启用。
POST /v1/responses- 与网关使用相同端口(WS + HTTP 多路复用):
http://<gateway-host>:<port>/v1/responses
openclaw agent 使用相同的代码路径),因此路由/权限/配置与您的网关保持一致。
身份验证
使用网关的身份验证配置。发送一个 Bearer 令牌:Authorization: Bearer <token>
- 当
gateway.auth.mode="token"时,使用gateway.auth.token(或OPENCLAW_GATEWAY_TOKEN)。 - 当
gateway.auth.mode="password"时,使用gateway.auth.password(或OPENCLAW_GATEWAY_PASSWORD)。
选择代理
无需自定义标头:将代理 ID 编码到 OpenResponses 的model 字段中:
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:
会话行为
默认情况下,该端点是每个请求无状态的(每次调用都会生成一个新的会话密钥)。 如果请求包含 OpenResponses 的user 字符串,网关会从中派生出一个稳定的会话密钥,因此重复调用可以共享同一个代理会话。
请求格式(支持)
请求遵循 OpenResponses API,并采用基于项目的输入。当前支持的功能包括:input:字符串或项目对象数组。instructions:合并到系统提示中。tools:客户端工具定义(函数工具)。tool_choice:筛选或要求客户端工具。stream:启用 SSE 流式传输。max_output_tokens:尽力而为的输出限制(取决于提供商)。user:稳定的会话路由。
max_tool_callsreasoningmetadatastoreprevious_response_idtruncation
项目(输入)
message
角色:system, developer, user, assistant。
system和developer会被附加到系统提示中。- 最近的
user或function_call_output项目将成为“当前消息”。 - 较早的用户/助手消息会被纳入上下文历史中。
function_call_output(基于回合的工具)
将工具结果返回给模型:
reasoning 和 item_reference
为兼容性目的被接受,但在构建提示时会被忽略。
工具(客户端函数工具)
通过tools: [{ type: "function", function: { name, description?, parameters? } }] 提供工具。
如果代理决定调用某个工具,响应会返回一个 function_call 输出项。然后您可以通过 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 旧版构建(无需 worker)。现代的 PDF.js 构建需要浏览器 worker/DOM 全局变量,因此未在网关中使用。
URL 获取的默认设置:
files.allowUrl:trueimages.allowUrl:true- 请求受到保护(DNS 解析、私有 IP 阻止、重定向限制、超时)。
文件和图片限制(配置)
默认值可在gateway.http.endpoints.responses 下进行调整:
maxBodyBytes: 20MBfiles.maxBytes: 5MBfiles.maxChars: 20万files.maxRedirects: 3files.timeoutMs: 10秒files.pdf.maxPages: 4files.pdf.maxPixels: 4,000,000files.pdf.minTextChars: 200images.maxBytes: 10MBimages.maxRedirects: 3images.timeoutMs: 10秒
流式传输(SSE)
设置stream: true 以接收服务器发送事件(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方法错误。