新增模型供應商
切勿輸出或持久化秘密值;憑證僅能透過 SecretRef(環境變數或檔案來源)寫入配置。切勿手動編輯磁碟上的配置檔案——所有變更皆須經由 openclaw config 進行,以確保驗證與稽核。每次操作結束時必須呈現可觀察的 Prove 結果,或準確說明無法驗證的原因。
會話內的 config_set / config_set_ref 工具操作對 models.* 與 secrets.* 路徑設有政策封鎖;請使用受信任的 shell(exec)執行以下指令。set_default_model 是唯一允許在會話內變更預設路由的操作——它會在儲存前先進行即時測試。
收集資訊
openclaw config get models --json # 首次設定前可能顯示 "Config path not found",此為正常現象
openclaw models list --agent <agentId> # 在多代理 roster 環境中需要指定 --agent
openclaw models auth list --agent <agentId>
openclaw config schema --json | jq '.properties.models' # 寫入前先確認確切的供應商路徑
openclaw plugins list # OpenAI 路由需要 codex harness 外掛;立即啟用/安裝,不要在驗證步驟才處理
如果目標供應商的 harness 外掛遺失或停用,請在此處修復(openclaw plugins enable codex 或 openclaw plugins install @openclaw/codex),以免 Prove 步驟延遲;啟用外掛後閘道器會熱重載自動生效。
決定驗證合約類型:API 金鑰供應商需在 models.providers.<id>.apiKey 上設定 SecretRef;訂閱/OAuth 供應商(ChatGPT/Codex、Claude 訂閱)則使用 openclaw models auth login --provider <id>,且不可指定 API 金鑰路徑。
變更配置
API 金鑰範例(OpenAI),金鑰由操作員預先放入權限為 0600 的檔案——先用 --dry-run 驗證,再寫入:
openclaw config set secrets.providers.openai_key_file --provider-source file --provider-path /path/to/openai.key --provider-mode singleValue --dry-run
openclaw config set secrets.providers.openai_key_file --provider-source file --provider-path /path/to/openai.key --provider-mode singleValue
openclaw config set models.providers.openai.apiKey --ref-provider openai_key_file --ref-source file --ref-id value
當閘道器行程環境變數已包含金鑰時的環境變數替代方案:
openclaw config set models.providers.openai.apiKey --ref-provider default --ref-source env --ref-id OPENAI_API_KEY
若要變更預設模型,請使用會話內的 set_default_model 操作(非預設代理需指定 agentId);它會先進行即時測試再儲存。請勿透過原始配置寫入來變更預設值。
修復
openclaw doctor --lint
doctor --lint 可能因發現問題而回傳結束碼 1:請閱讀報告並繼續其他檢查。一般 doctor 與 doctor --non-interactive 會寫入配置/狀態;在獲得批准前請勿用於診斷。若需要修復,請先取得明確許可,執行 openclaw doctor --fix --non-interactive,然後重新執行收集資訊階段的讀取指令。
驗證
適用於所有 roster 環境的測試(使用您自己的代理 ID 或任何已設定的代理):
openclaw agent --agent <agentId> --model openai/gpt-5.4 -m "Reply with exactly: PROVIDER-PROOF-OK"
單代理安裝可使用較輕量的完成測試——此指令沒有 --agent 旗標,在多代理 roster 環境中會因「無明確擁有者」而失敗,請勿在該環境重試:
openclaw infer model run --gateway --model openai/gpt-5.4 --prompt "Reply with exactly: PROVIDER-PROOF-OK"
預期收到完全匹配的回應;記錄模型 ID 與耗時。已知相依性:OpenAI 路由需在運行時依賴 codex harness 外掛——若測試報告運行時不可用,請執行 openclaw plugins install @openclaw/codex 並重新啟動閘道器,然後再次測試。
回報
說明已新增的供應商、寫入的 SecretRef 路徑(不可寫入值)、測試結果(含模型 ID 與延遲),以及預設模型是否已變更。若測試失敗,請回報確切錯誤訊息與應嘗試的下一條指令。
更多參考資訊:https://docs.openclaw.ai/providers/models 與 https://docs.openclaw.ai/providers/openai