Gateway 可提供 OpenAI 兼容的 Chat Completions 端点,默认禁用,需手动开启。

端点列表

  • POST /v1/chat/completions
  • GET /v1/models
  • GET /v1/models/{id}
  • POST /v1/embeddings
  • POST /v1/responses

所有请求底层走正常 Gateway agent run,与 openclaw agent 同一代码路径。

启用配置

{
  gateway: {
    http: {
      endpoints: {
        chatCompletions: { enabled: true },
      },
    },
  },
}

认证

  • token/password 模式:Authorization: Bearer <token-or-password>
  • trusted-proxy 模式:通过身份感知代理注入 header
  • none 模式:无需 auth header

安全边界:此端点等同于完整 operator 访问,共享密钥认证会恢复完整默认 operator scope,忽略更窄的 x-openclaw-scopes。不要暴露到公网。

Agent 优先模型合约

model 字段是 agent 目标,不是原始 provider model id:

  • model: "openclaw" → 默认 agent
  • model: "openclaw/default" → 默认 agent(稳定别名)
  • model: "openclaw/<agentId>" → 指定 agent

可选请求 header:

  • x-openclaw-model: <provider/model> — 覆盖后端模型
  • x-openclaw-session-key: <key> — 控制会话路由
  • x-openclaw-message-channel: <channel> — 设置合成入口 channel

会话行为

默认每次请求无状态(新 session key)。请求包含 user 字段时,Gateway 派生稳定 session key,重复调用可共享 agent 会话。

流式(SSE)

stream: true 启用 SSE,Content-Type: text/event-stream,以 data: [DONE] 结束。

Open WebUI 快速接入

  • Base URL:http://127.0.0.1:18789/v1
  • API key:Gateway bearer token
  • Model:openclaw/default

示例

# 非流式
curl -sS http://127.0.0.1:18789/v1/chat/completions \
  -H 'Authorization: Bearer YOUR_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{"model": "openclaw/default", "messages": [{"role":"user","content":"hi"}]}'
 
# 列出模型
curl -sS http://127.0.0.1:18789/v1/models \
  -H 'Authorization: Bearer YOUR_TOKEN'

相关