Gateway 運行手冊
使用此頁面進行 Gateway 服務的初始啟動 (day-1) 和後續營運 (day-2)。
以症狀為先導的診斷,提供精確的指令階梯和日誌特徵。
以任務為導向的設定指南 + 完整設定參考。
SecretRef 合約、執行時期快照行為,以及遷移/重新載入作業。
精確的 secrets apply 目標/路徑規則以及僅參照的 auth-profile 行為。
5 分鐘本地啟動
Section titled “5 分鐘本地啟動”啟動 Gateway
Terminal window openclaw gateway --port 18789# debug/trace mirrored to stdioopenclaw gateway --port 18789 --verbose# force-kill listener on selected port, then startopenclaw gateway --force驗證服務健康狀態
Terminal window openclaw gateway statusopenclaw statusopenclaw logs --follow健康的基準:
Runtime: running、Connectivity probe: ok和Capability: ...符合您的預期。當您需要讀取範圍的 RPC 證明而不僅僅是連線能力時,請使用openclaw gateway status --require-rpc。驗證通道就緒狀態
Terminal window openclaw channels status --probe當 Gateway 可連線時,這會對每個帳戶執行即時通道探測和選用的稽核。 如果 Gateway 無法連線,CLI 將退回到僅包含設定的通道摘要, 而非即時探測輸出。
執行時期模型
Section titled “執行時期模型”- 一個持續運作的程序,用於路由、控制平面和通道連線。
- 單一多工連接埠用於:
- WebSocket 控制/RPC
- HTTP API (
/v1/models,/v1/embeddings,/v1/chat/completions,/v1/responses,/tools/invoke) - 外掛程式 HTTP 路由,例如選用的
/api/v1/admin/rpc - 控制 UI 與 hooks
- 預設綁定模式:
loopback。 - 預設需要驗證。共享金鑰設定使用
gateway.auth.token/gateway.auth.password(或OPENCLAW_GATEWAY_TOKEN/OPENCLAW_GATEWAY_PASSWORD),而非本機迴路 的反向代理設定可以使用gateway.auth.mode: "trusted-proxy"。
OpenAI 相容端點
Section titled “OpenAI 相容端點”OpenClaw 目前最高效力的相容性介面為:
GET /v1/modelsGET /v1/models/{id}POST /v1/embeddingsPOST /v1/chat/completionsPOST /v1/responses
為何此組合很重要:
- 大多數 Open WebUI、LobeChat 和 LibreChat 整合會先探測
/v1/models。 - 許多 RAG 和記憶管線預期使用
/v1/embeddings。 - 代理程式原生用戶端越來越傾向於使用
/v1/responses。
規劃備註:
/v1/models是代理程式優先的:它會回傳openclaw、openclaw/default和openclaw/<agentId>。openclaw/default是一個穩定的別名,永遠對應到已設定的預設代理程式。- 當您想要覆寫後端提供者/模型時,請使用
x-openclaw-model;否則,所選代理程式的正常模型和嵌入設定將維持控管。
所有這些都運行在主 Gateway 埠上,並使用與 Gateway HTTP API 其餘部分相同的受信任操作員認證邊界。
管理員 HTTP RPC (POST /api/v1/admin/rpc) 是一個獨立的預設關閉外掛程式路由,供無法使用 WebSocket RPC 的主機工具使用。請參閱 Admin HTTP RPC。
連接埠和綁定優先順序
Section titled “連接埠和綁定優先順序”| 設定 | 解析順序 |
|---|---|
| Gateway 連接埠 | --port → OPENCLAW_GATEWAY_PORT → gateway.port → 18789 |
| 綁定模式 | CLI/override → gateway.bind → loopback |
已安裝的 Gateway 服務會將解析出的 --port 記錄在監督器元數據中。變更 gateway.port 後,請執行 openclaw doctor --fix 或 openclaw gateway install --force,以便 launchd/systemd/schtasks 在新連接埠上啟動程序。
Gateway 啟動時,在針對非回環連線植入本機 Control UI 來源時,會使用相同的有效連接埠和綁定。例如,--bind lan --port 3000 會在執行時期驗證執行前植入 http://localhost:3000 和 http://127.0.0.1:3000。請將任何遠端瀏覽器來源(例如 HTTPS 代理 URL)明確新增至 gateway.controlUi.allowedOrigins。
gateway.reload.mode | 行為 |
|---|---|
off | 不重載設定 |
hot | 僅套用熱安全變更 |
restart | 需要重載時重新啟動 |
hybrid(預設值) | 安全時熱套用,必要時重新啟動 |
操作員命令集
Section titled “操作員命令集”openclaw gateway statusopenclaw gateway status --deep # adds a system-level service scanopenclaw gateway status --jsonopenclaw gateway installopenclaw gateway restartopenclaw gateway stopopenclaw secrets reloadopenclaw logs --followopenclaw doctorgateway status --deep 是用於額外的服務探索(LaunchDaemons/systemd 系統單位/schtasks),而非更深入的 RPC 健康探測。
多個 Gateway(同一主機)
Section titled “多個 Gateway(同一主機)”大多數安裝應該在每台機器上執行一個 Gateway。單一 Gateway 可以代管多個代理和通道。
只有當您刻意需要隔離或救援機器人時,才需要多個 Gateway。
有用的檢查:
openclaw gateway status --deepopenclaw gateway probe預期事項:
- 當過時的 launchd/systemd/schtasks 安裝仍然存在時,
gateway status --deep可能會回報Other gateway-like services detected (best effort)並列印清理提示。 - 當多個目標回應時,
gateway probe可能會警告multiple reachable gateways。 - 如果這是有意為之,請針對每個 Gateway 隔離連接埠、設定/狀態和工作區根目錄。
每個執行個體的檢查清單:
- 唯一的
gateway.port - 唯一的
OPENCLAW_CONFIG_PATH - 唯一的
OPENCLAW_STATE_DIR - 唯一的
agents.defaults.workspace
範例:
OPENCLAW_CONFIG_PATH=~/.openclaw/a.json OPENCLAW_STATE_DIR=~/.openclaw-a openclaw gateway --port 19001OPENCLAW_CONFIG_PATH=~/.openclaw/b.json OPENCLAW_STATE_DIR=~/.openclaw-b openclaw gateway --port 19002詳細設定:/gateway/multiple-gateways。
首選:Tailscale/VPN。 備援:SSH 通道。
ssh -N -L 18789:127.0.0.1:18789 user@host然後將用戶端本機連線至 ws://127.0.0.1:18789。
請參閱:Remote Gateway、Authentication、Tailscale。
監督與服務生命週期
Section titled “監督與服務生命週期”在生產環境般的可靠性要求下,請使用監督執行。
openclaw gateway installopenclaw gateway statusopenclaw gateway restartopenclaw gateway stop使用 openclaw gateway restart 進行重啟。請勿將 openclaw gateway stop 與 openclaw gateway start 串接作為重啟的替代方案。
在 macOS 上,gateway stop 預設使用 launchctl bootout —— 這會從目前的啟動階段中移除 LaunchAgent 而不永久停用,因此 KeepAlive 自動恢復機制在意外崩潰後仍能運作,且 gateway start 能乾淨地重新啟用。若要跨重新啟動永久抑制自動重生,請傳入 --disable:openclaw gateway stop --disable。
LaunchAgent 標籤為 ai.openclaw.gateway (預設) 或 `ai.openclaw.
(命名設定檔)。openclaw doctor` 會稽核並修復服務設定偏移。
openclaw gateway installsystemctl --user enable --now openclaw-gateway[-].service openclaw gateway status
若要在登出後保持運作,請啟用 linger:
```bashsudo loginctl enable-linger當您需要自訂安裝路徑時的手動使用者單元範例:
```ini[Unit]Description=OpenClaw GatewayAfter=network-online.targetWants=network-online.target
[Service]ExecStart=/usr/local/bin/openclaw gateway --port 18789Restart=alwaysRestartSec=5TimeoutStopSec=30TimeoutStartSec=30SuccessExitStatus=0 143KillMode=control-group
[Install]WantedBy=default.targetopenclaw gateway installopenclaw gateway status --jsonopenclaw gateway restartopenclaw gateway stop原生 Windows 受控啟動使用名為 OpenClaw Gateway 的已排程任務
(或針對命名設定檔使用 `OpenClaw Gateway (
))。如果建立已排程任務 被拒絕,OpenClaw 會退而使用每位使用者的啟動資料夾啟動器, 該啟動器指向狀態目錄中的 gateway.cmd`。
針對多用戶/永遠在線的主機,使用系統單元。
sudo systemctl daemon-reloadsudo systemctl enable --now openclaw-gateway[-].service
使用與用戶單元相同的服務主體,但將其安裝在`/etc/systemd/system/openclaw-gateway[-].service下,並在您的openclaw二進制文件位於其他位置時調整ExecStart=`。
不要同時讓 openclaw doctor --fix 為相同的配置檔案/端口安裝用戶級別的網關服務。當 Doctor 發現系統級別的 OpenClaw 網關服務時,它會拒絕該自動安裝;當系統單元擁有生命週期時,請使用 OPENCLAW_SERVICE_REPAIR_POLICY=external。
開發設定檔快速路徑
Section titled “開發設定檔快速路徑”openclaw --dev setupopenclaw --dev gateway --allow-unconfiguredopenclaw --dev status預設值包括隔離的狀態/配置和基礎網關端口 19001。
協定快速參考(操作員檢視)
Section titled “協定快速參考(操作員檢視)”- 第一個客戶端框架必須是
connect。 - 網關返回
hello-ok快照(presence、health、stateVersion、uptimeMs、限制/策略)。 hello-ok.features.methods/events是一個保守的發現列表,不是 每個可調用的輔助路由的生成轉儲。- 請求:
req(method, params)→res(ok/payload|error)。 - 常見事件包括
connect.challenge、agent、chat、session.message、session.operation、session.tool、sessions.changed、presence、tick、health、heartbeat、配對/批准生命週期事件 以及shutdown。
Agent 執行分為兩個階段:
- 立即接受的確認(
status:"accepted") - 最終完成響應(
status:"ok"|"error"),中間穿插流式agent事件。
查看完整協議文檔:Gateway Protocol。
- 打開 WS 並發送
connect。 - 預期帶有快照的
hello-ok響應。
openclaw gateway statusopenclaw channels status --probeopenclaw health事件不會重播。出現序列間隙時,請在繼續之前重新整理狀態(health、system-presence)。
常見失敗特徵
Section titled “常見失敗特徵”| 特徵 | 可能問題 |
|---|---|
refusing to bind gateway ... without auth | 非回送連線綁定且沒有有效的閘道驗證路徑 |
another gateway instance is already listening / EADDRINUSE | 連接埠衝突 |
Gateway start blocked: set gateway.mode=local | 設定為遠端模式,或損毀的設定中缺少本地模式標記 |
連線期間的 unauthorized | 客戶端與 Gateway 之間的驗證不符 |
如需完整的診斷階梯,請使用 Gateway Troubleshooting。
- 當 Gateway 無法使用時,Gateway 協定客戶端會快速失敗(沒有隱含的直接通道後備)。
- 無效或非連線的第一幀會被拒絕並關閉。
- 在 Socket 關閉之前,正常關閉會發出
shutdown事件。
相關: