本页是模型提供方认证参考(API 密钥、OAuth、Claude CLI 复用以及 Anthropic setup-token)。关于网关连接认证(token、password、trusted-proxy),请参见 Configuration 和 Trusted Proxy Auth。
env/file/exec 提供方),请参见 Secrets Management。
有关 models status --probe 使用的凭据资格/原因码规则,请参见
Auth Credential Semantics。
推荐设置(API 密钥,任意提供方)
如果你运行的是长期存在的网关,请先为你选择的提供方使用 API 密钥。 对于 Anthropic 而言,API 密钥认证仍然是最可预测的服务端设置,但 OpenClaw 也支持复用本地 Claude CLI 登录。- 在你的提供方控制台中创建一个 API 密钥。
- 将其放到网关主机上(运行
openclaw gateway的机器)。
- 如果 Gateway 运行在 systemd/launchd 下,建议将密钥放入
~/.openclaw/.env,这样守护进程就可以读取它:
openclaw onboard。
有关环境继承(env.shellEnv、~/.openclaw/.env、systemd/launchd)的详细信息,请参见 帮助。
Anthropic:Claude CLI 与 token 兼容性
Anthropic setup-token 认证在 OpenClaw 中仍然可用,作为受支持的 token 路径。Anthropic 员工后来告诉我们,OpenClaw 风格的 Claude CLI 使用现在 再次被允许,因此除非 Anthropic 发布新政策,OpenClaw 会将 Claude CLI 复用 和claude -p 的使用视为该集成的授权方式。当主机上可用 Claude CLI 复用时,
那现在是首选路径。
对于长期运行的网关主机,Anthropic API 密钥仍然是最可预测的
设置。如果你想在同一台主机上复用已有的 Claude 登录,请在 onboarding/configure 中使用
Anthropic Claude CLI 路径。
Claude CLI 复用的推荐主机设置:
- 先在网关主机上把 Claude Code 自身登录到 Anthropic。
- 告诉 OpenClaw 将 Anthropic 模型选择切换到本地
claude-cli后端,并存储匹配的 OpenClaw 认证配置文件。
claude 不在 PATH 中,请先安装 Claude Code,或者将
agents.defaults.cliBackends.claude-cli.command 设置为真实的二进制路径。
Manual token entry (any provider; writes the per-agent SQLite auth store + updates config):
auth-profiles.json files used this canonical shape:
openclaw-agent.sqlite. If an older install still has auth-profiles.json, auth-state.json, or a flat auth profile file such as { "openrouter": { "apiKey": "..." } }, run openclaw doctor --fix to import it into SQLite; doctor keeps timestamped backups beside the original JSON files. Endpoint details such as baseUrl, api, model ids, headers, and timeouts belong under models.providers.<id> in openclaw.json or models.json, not in auth profiles.
External auth routes such as Bedrock auth: "aws-sdk" are also not credentials. If you want a named Bedrock route, put auth.profiles.<id>.mode: "aws-sdk" in openclaw.json; do not write type: "aws-sdk" into the auth profile store. openclaw doctor --fix moves legacy AWS SDK markers from the credential store into config metadata.
静态凭据也支持 Auth profile 引用:
api_key凭据可以使用keyRef: { source, provider, id }token凭据可以使用tokenRef: { source, provider, id }- OAuth 模式的 profile 不支持 SecretRef 凭据;如果
auth.profiles.<id>.mode设置为"oauth",则该 profile 的基于 SecretRef 的keyRef/tokenRef输入会被拒绝。
1,即将过期时退出 2):
- 探测行可能来自 auth profile、环境凭据或
models.json。 - 如果显式的
auth.order.<provider>省略了已存储的 profile,探测会将该 profile 报告为excluded_by_auth_order,而不是尝试它。 - 如果存在认证,但 OpenClaw 无法为该提供方解析出可探测的模型候选项,
探测会报告
status: no_model。 - 限流冷却可以按模型范围生效。某个 profile 因一个模型进入冷却状态, 仍可能可用于同一提供方上的另一个兄弟模型。
Anthropic 说明
Anthropic 的claude-cli 后端现已重新支持。
- Anthropic 员工告诉我们,这条 OpenClaw 集成路径现在再次被允许。
- 因此,除非 Anthropic 发布新政策,OpenClaw 会将 Claude CLI 复用和
claude -p的使用视为 Anthropic 后端运行的授权方式。 - 对于长期运行的网关主机以及明确的服务端计费控制,Anthropic API 密钥仍然是最可预测的选择。
检查模型认证状态
API 密钥轮换行为(网关)
某些提供方在 API 调用遇到提供方限流时,支持使用备用密钥重试请求。- 优先级顺序:
OPENCLAW_LIVE_<PROVIDER>_KEY(单个覆盖)<PROVIDER>_API_KEYS<PROVIDER>_API_KEY<PROVIDER>_API_KEY_*
- Google 提供方还额外包括
GOOGLE_API_KEY作为后备。 - 使用前会对相同的密钥列表去重。
- OpenClaw 仅在限流错误时用下一个密钥重试(例如
429、rate_limit、quota、resource exhausted、Too many concurrent requests、ThrottlingException、concurrency limit reached,或workers_ai ... quota limit exceeded)。 - 非限流错误不会使用备用密钥重试。
- 如果所有密钥都失败,则返回最后一次尝试的最终错误。
网关运行时移除提供方认证
当通过 Gateway 控制平面移除提供方认证时,OpenClaw 会删除 该提供方已保存的认证 profile,并中止其所选模型提供方与被移除提供方匹配的 活动聊天或代理运行。被中止的运行会发出 带有stopReason: "auth-revoked" 的常规聊天取消和生命周期事件,
因此已连接的客户端可以显示该运行是因为凭据被移除而停止的。
移除已保存的认证不会在提供方侧吊销密钥。若需要在提供方侧使密钥失效,
请在提供方仪表板中轮换或吊销该密钥。
控制使用哪一个凭据
OpenAI and legacy openai-codex ids
OpenAI API-key profiles and ChatGPT/Codex OAuth profiles both use the canonical
provider id openai. New config should use openai:* profile ids and
auth.order.openai.
If you see openai-codex in older config, auth profile ids, or
auth.order.openai-codex, treat it as legacy migration input. Do not create new
openai-codex profiles. Run:
openai-codex:* profile ids and
auth.order.openai-codex entries to the canonical openai auth route. For
OpenAI-specific model/runtime routing, see OpenAI.
During login (CLI)
Useopenclaw models auth login --provider <id> --profile-id <profileId> for
providers that support named auth profiles during login.
--force when a saved provider profile is stuck, expired, or tied to the
wrong account and the normal login command keeps reusing it. --force deletes
the saved auth profiles for that provider in the selected agent directory, then
runs the same provider auth flow again. It does not revoke credentials at the
provider; rotate or revoke them in the provider dashboard when you need
provider-side invalidation.
Per-session (chat command)
使用/model <alias-or-id>@<profileId> 为当前会话固定某个特定的提供方凭据(示例 profile id:anthropic:default、anthropic:work)。
使用 /model(或 /model list)可获得紧凑选择器;使用 /model status 可查看完整视图(候选项 + 下一个 auth profile,以及已配置时的提供方端点细节)。
按代理(CLI 覆盖)
Set an explicit auth profile order override for an agent (stored in that agent’s SQLite auth state):--agent <id> 可针对特定代理;省略则使用已配置的默认代理。
当你调试顺序问题时,openclaw models status --probe 会将被省略的
已存储 profile 显示为 excluded_by_auth_order,而不是静默跳过它们。
当你调试冷却问题时,请记住限流冷却可能只绑定到某个模型 id,
而不是整个提供方 profile。
If you change auth order or profile pinning for a chat that is already running,
send /new or /reset in that chat to start a fresh session. Existing
sessions can keep their current model/profile selection until reset.
Troubleshooting
“未找到凭据”
如果 Anthropic profile 丢失,请在网关主机上配置 Anthropic API 密钥, 或者设置 Anthropic setup-token 路径,然后重新检查:Token 即将过期/已过期
运行openclaw models status 以确认是哪个 profile 即将过期。如果某个
Anthropic token profile 丢失或已过期,请通过 setup-token 刷新该设置,或者迁移到 Anthropic API 密钥。