設定 OpenClaw 驗證設定檔:管理 API 金鑰與 OAuth
身為開發者,最煩人的事情之一就是管理各種 API key 和登入憑證。當你同時擁有個人帳號、公司帳號,還有各種測試用的 token 時,要在不同專案間切換簡直是場災難。如果沒處理好,不是設定跑掉,就是不小心刷爆了不該用的信用卡。
這就是為什麼我們需要一套清晰的憑證管理機制,讓你專注在開發上,而不是在設定檔裡迷路。
什麼是 Auth Profile?
Section titled “什麼是 Auth Profile?”Auth profile 是一個具名的憑證紀錄(OAuth 或 API key),並與特定的 provider 綁定。這些 profile 儲存在:
~/.openclaw/agents/<agentId>/agent/auth-profiles.json常見的 Profile ID 有哪些?
Section titled “常見的 Profile ID 有哪些?”OpenClaw 使用帶有 provider 前綴的 ID,例如:
anthropic:default(通常在沒有 email 身份時使用)anthropic:<email>用於 OAuth 身份- 你自定義的 ID(例如
anthropic:work)
我可以控制優先使用哪個 Auth Profile 嗎?
Section titled “我可以控制優先使用哪個 Auth Profile 嗎?”可以。設定檔支援 profile 的選填 metadata,以及針對每個 provider 的排序規則 (auth.order.<provider>)。
如果某個 profile 處於短暫的 cooldown(頻率限制/逾時/驗證失敗)或長期的 disabled 狀態(欠費/額度不足),OpenClaw 可能會暫時跳過它。
如果要檢查狀態,可以執行 openclaw models status --json 並查看 auth.unusableProfiles。
設定每個 Agent 的排序:
# Lock rotation to a single profileopenclaw models auth order set --provider anthropic anthropic:default
# Set an explicit order (fallback within provider)openclaw models auth order set --provider anthropic anthropic:work anthropic:default
# Clear overrideopenclaw models auth order clear --provider anthropicOAuth vs API key — 有什麼區別?
Section titled “OAuth vs API key — 有什麼區別?”OpenClaw 同時支援這兩種方式:
- OAuth 通常使用訂閱制的存取權限(如果適用的話)
- API keys 則是按 token 用量計費
設定精靈明確支援 Anthropic setup-token 和 OpenAI Codex OAuth,也能幫你儲存 API keys。
OpenClaw Expert
還是卡住了?
如果這篇文件沒有解決你的情境,直接問 OpenClaw Expert,拿到可執行步驟。