OpenResponses API(HTTP)
Moltbot 网关可提供与 OpenResponses 兼容的 POST /v1/responses 端点。该端点默认关闭,需先在配置中启用。
POST /v1/responses- 与网关共用端口(WS + HTTP 复用):
http://<gateway-host>:<port>/v1/responses
底层请求按普通网关 agent 运行执行(与 moltbot agent 同一代码路径),故路由/权限/配置与网关一致。
认证
使用网关认证配置。发送 Bearer 令牌:
Authorization: Bearer <token>
说明:gateway.auth.mode="token" 时使用 gateway.auth.token(或 CLAWDBOT_GATEWAY_TOKEN);gateway.auth.mode="password" 时使用 gateway.auth.password(或 CLAWDBOT_GATEWAY_PASSWORD)。
选择 Agent
无需自定义头:在 OpenResponses 的 model 字段中编码 agent id:
model: "moltbot:<agentId>"(例如"moltbot:main"、"moltbot:beta")model: "agent:<agentId>"(别名)
或通过请求头指定 Moltbot agent:
x-moltbot-agent-id: <agentId>(默认main)
进阶:x-moltbot-session-key: <sessionKey> 可完全控制会话路由。
启用端点
将 gateway.http.endpoints.responses.enabled 设为 true:
{
gateway: {
http: {
endpoints: {
responses: { enabled: true }
}
}
}
}关闭端点
将 gateway.http.endpoints.responses.enabled 设为 false:
{
gateway: {
http: {
endpoints: {
responses: { enabled: false }
}
}
}
}会话行为
默认该端点按请求无状态(每次调用生成新会话键)。若请求包含 OpenResponses 的 user 字符串,网关会据此推导稳定会话键,重复调用可共享同一 agent 会话。
请求格式(已支持)
请求遵循 OpenResponses API 的基于 item 的输入。当前支持:input(字符串或 item 对象数组)、instructions(合并进系统提示)、tools(客户端工具定义,function tools)、tool_choice(过滤或要求客户端工具)、stream(启用 SSE 流式)、max_output_tokens(尽力而为的输出限制,依赖提供商)、user(稳定会话路由)。接受但当前忽略:max_tool_calls、reasoning、metadata、store、previous_response_id、truncation。
Items(输入)
message
角色:system、developer、user、assistant。system 与 developer 追加到系统提示;最近一条 user 或 function_call_output item 作为「当前消息」;更早的 user/assistant 消息作为历史上下文。
function_call_output(按轮次工具)
将工具结果发回模型:
{
"type": "function_call_output",
"call_id": "call_123",
"output": "{\"temperature\": \"72F\"}"
}reasoning 与 item_reference
为兼容 schema 接受,但在构建提示时忽略。
工具(客户端 function tools)
通过 tools: [{ type: "function", function: { name, description?, parameters? } }] 提供。若 agent 决定调用某工具,响应会返回 function_call 输出 item;随后在跟进请求中发送 function_call_output 继续该轮。
图片(input_image)
支持 base64 或 URL 来源:
{
"type": "input_image",
"source": { "type": "url", "url": "https://example.com/image.png" }
}当前允许 MIME:image/jpeg、image/png、image/gif、image/webp。当前最大:10MB。
文件(input_file)
支持 base64 或 URL 来源:
{
"type": "input_file",
"source": {
"type": "base64",
"media_type": "text/plain",
"data": "SGVsbG8gV29ybGQh",
"filename": "hello.txt"
}
}当前允许 MIME:text/plain、text/markdown、text/html、text/csv、application/json、application/pdf。当前最大:5MB。当前行为:文件内容解码后加入系统提示而非用户消息,故为临时性(不写入会话历史);PDF 会解析文本,若文本很少则前几页会栅格化为图片传给模型。PDF 解析使用 Node 友好的 pdfjs-dist 旧版构建(无 worker)。URL 获取默认:files.allowUrl、images.allowUrl 为 true;请求受保护(DNS 解析、私网 IP 阻断、重定向上限、超时)。
文件与图片限制(配置)
默认值可在 gateway.http.endpoints.responses 下调整:
{
gateway: {
http: {
endpoints: {
responses: {
enabled: true,
maxBodyBytes: 20000000,
files: {
allowUrl: true,
allowedMimes: ["text/plain", "text/markdown", "text/html", "text/csv", "application/json", "application/pdf"],
maxBytes: 5242880,
maxChars: 200000,
maxRedirects: 3,
timeoutMs: 10000,
pdf: {
maxPages: 4,
maxPixels: 4000000,
minTextChars: 200
}
},
images: {
allowUrl: true,
allowedMimes: ["image/jpeg", "image/png", "image/gif", "image/webp"],
maxBytes: 10485760,
maxRedirects: 3,
timeoutMs: 10000
}
}
}
}
}
}省略时默认:maxBodyBytes 20MB;files.maxBytes 5MB;files.maxChars 200k;files.maxRedirects 3;files.timeoutMs 10s;files.pdf.maxPages 4;files.pdf.maxPixels 4,000,000;files.pdf.minTextChars 200;images.maxBytes 10MB;images.maxRedirects 3;images.timeoutMs 10s。
流式(SSE)
设 stream: true 接收 Server-Sent Events(SSE):Content-Type: text/event-stream;每行事件为 event: <type> 与 data: <json>;流以 data: [DONE] 结束。当前发出的事件类型:response.created、response.in_progress、response.output_item.added、response.content_part.added、response.output_text.delta、response.output_text.done、response.content_part.done、response.output_item.done、response.completed、response.failed(错误时)。
Usage
当底层提供商上报 token 计数时会填充 usage。
错误
错误使用 JSON 对象,例如:{ "error": { "message": "...", "type": "invalid_request_error" } }。常见:401 认证缺失/无效;400 请求体无效;405 方法错误。
示例
非流式:
curl -sS http://127.0.0.1:18789/v1/responses \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-H 'x-moltbot-agent-id: main' \
-d '{
"model": "moltbot",
"input": "hi"
}'流式:
curl -N http://127.0.0.1:18789/v1/responses \
-H 'Authorization: Bearer YOUR_TOKEN' \
-H 'Content-Type: application/json' \
-H 'x-moltbot-agent-id: main' \
-d '{
"model": "moltbot",
"stream": true,
"input": "hi"
}'