OpenAI Chat Completions(HTTP)
OpenClaw 的 Gateway 可以提供一個小型、與 OpenAI 相容的 Chat Completions 端點。 此端點預設為停用。請先在設定中啟用。 請先在設定中啟用。 請先在設定中啟用。POST /v1/chat/completions- 與 Gateway 使用相同的連接埠(WS + HTTP 多工):
http://<gateway-host>:<port>/v1/chat/completions
openclaw agent 相同的程式碼路徑),因此路由、權限與設定都會符合你的 Gateway。
驗證
Uses the Gateway auth configuration. 傳送 Bearer 權杖:Authorization: Bearer <token>
- 當
gateway.auth.mode="token"時,請使用gateway.auth.token(或OPENCLAW_GATEWAY_TOKEN)。 - 當
gateway.auth.mode="password"時,請使用gateway.auth.password(或OPENCLAW_GATEWAY_PASSWORD)。 - 如果設定了
gateway.auth.rateLimit且驗證失敗次數過多,端點會回傳429並附帶Retry-After。
選擇代理程式
不需要自訂標頭:在 OpenAI 的model 欄位中編碼代理程式 ID:
model: "openclaw:<agentId>"(例如:"openclaw:main"、"openclaw:beta")model: "agent:<agentId>"(別名)
x-openclaw-agent-id: <agentId>(預設:main)
x-openclaw-session-key: <sessionKey>以完整控制工作階段路由。
Enabling the endpoint
將gateway.http.endpoints.chatCompletions.enabled 設為 true:
停用端點
將gateway.http.endpoints.chatCompletions.enabled 設為 false:
Session behavior
By default the endpoint is stateless per request (a new session key is generated each call). If the request includes an OpenAIuser string, the Gateway derives a stable session key from it, so repeated calls can share an agent session.
串流(SSE)
將stream: true 設定為接收 Server-Sent Events(SSE):
Content-Type: text/event-stream- 每一行事件為
data: <json> - 串流以
data: [DONE]結束