Skip to content

鉴权

OpenClaw 支持对模型提供方使用 OAuth 与 API keys。对于 Anthropic 账号,建议使用 API key。如果你使用 Claude 订阅访问,则使用 claude setup-token 创建的长期 token。

完整的 OAuth 流程与存储布局见:/concepts/oauth

推荐的 Anthropic 配置(API key)

如果你直接使用 Anthropic,请使用 API key。

  1. 在 Anthropic Console 创建 API key。
  2. 把它放到 gateway host(运行 openclaw gateway 的机器)上。
bash
export ANTHROPIC_API_KEY="..."
openclaw models status
  1. 如果 Gateway 在 systemd/launchd 下运行,优先把 key 放到 ~/.openclaw/.env,以便守护进程读取:
bash
cat >> ~/.openclaw/.env <<'EOF'
ANTHROPIC_API_KEY=...
EOF

然后重启 daemon(或重启你的 Gateway 进程),并重新检查:

bash
openclaw models status
openclaw doctor

如果你不想自己管理环境变量,onboarding 向导也可以为 daemon 存储 API keys:openclaw onboard

关于环境变量继承(env.shellEnv~/.openclaw/.env、systemd/launchd)见 Help

Anthropic:setup-token(订阅鉴权)

对于 Anthropic,推荐路径仍是 API key。如果你使用 Claude 订阅,也支持 setup-token 流程。请在 gateway host 上运行:

bash
claude setup-token

然后将其粘贴到 OpenClaw:

bash
openclaw models auth setup-token --provider anthropic

如果 token 是在另一台机器上创建的,可以手动粘贴:

bash
openclaw models auth paste-token --provider anthropic

如果你看到 Anthropic 错误,例如:

This credential is only authorized for use with Claude Code and cannot be used for other API requests.

……请改用 Anthropic API key。

手动录入 token(任意 provider;写入 auth-profiles.json + 更新 config):

bash
openclaw models auth paste-token --provider anthropic
openclaw models auth paste-token --provider openrouter

便于自动化的检查(过期/缺失时退出 1,即将过期时退出 2):

bash
openclaw models status --check

可选的 ops 脚本(systemd/Termux)文档: /automation/auth-monitoring

claude setup-token 需要交互式 TTY。

检查模型鉴权状态

bash
openclaw models status
openclaw doctor

控制使用哪一份凭据

按 session(聊天命令)

使用 /model <alias-or-id>@<profileId> 将当前 session 固定到某个 provider 凭据(profile id 示例:anthropic:defaultanthropic:work)。

使用 /model(或 /model list)打开简洁的选择器;使用 /model status 查看完整视图(候选列表 + 下一个 auth profile,以及在已配置时的 provider endpoint 细节)。

按 agent(CLI 覆盖)

为某个 agent 显式设置 auth profile 的优先顺序覆盖(存储在该 agent 的 auth-profiles.json 中):

bash
openclaw models auth order get --provider anthropic
openclaw models auth order set --provider anthropic anthropic:default
openclaw models auth order clear --provider anthropic

使用 --agent <id> 指定某个 agent;省略则使用配置的默认 agent。

排障

“No credentials found”

如果缺少 Anthropic token profile,请在 gateway host 上运行 claude setup-token,然后重新检查:

bash
openclaw models status

Token 即将过期/已过期

运行 openclaw models status 确认哪个 profile 即将过期。如果 profile 缺失,请重新运行 claude setup-token 并再次粘贴 token。

依赖要求

  • Claude Max 或 Pro 订阅(用于 claude setup-token
  • 已安装 Claude Code CLI(claude 命令可用)