鉴权
OpenClaw 支持对模型提供方使用 OAuth 与 API keys。对于 Anthropic 账号,建议使用 API key。如果你使用 Claude 订阅访问,则使用 claude setup-token 创建的长期 token。
完整的 OAuth 流程与存储布局见:/concepts/oauth。
推荐的 Anthropic 配置(API key)
如果你直接使用 Anthropic,请使用 API key。
- 在 Anthropic Console 创建 API key。
- 把它放到 gateway host(运行
openclaw gateway的机器)上。
export ANTHROPIC_API_KEY="..."
openclaw models status- 如果 Gateway 在 systemd/launchd 下运行,优先把 key 放到
~/.openclaw/.env,以便守护进程读取:
cat >> ~/.openclaw/.env <<'EOF'
ANTHROPIC_API_KEY=...
EOF然后重启 daemon(或重启你的 Gateway 进程),并重新检查:
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 上运行:
claude setup-token然后将其粘贴到 OpenClaw:
openclaw models auth setup-token --provider anthropic如果 token 是在另一台机器上创建的,可以手动粘贴:
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):
openclaw models auth paste-token --provider anthropic
openclaw models auth paste-token --provider openrouter便于自动化的检查(过期/缺失时退出 1,即将过期时退出 2):
openclaw models status --check可选的 ops 脚本(systemd/Termux)文档: /automation/auth-monitoring
claude setup-token需要交互式 TTY。
检查模型鉴权状态
openclaw models status
openclaw doctor控制使用哪一份凭据
按 session(聊天命令)
使用 /model <alias-or-id>@<profileId> 将当前 session 固定到某个 provider 凭据(profile id 示例:anthropic:default、anthropic:work)。
使用 /model(或 /model list)打开简洁的选择器;使用 /model status 查看完整视图(候选列表 + 下一个 auth profile,以及在已配置时的 provider endpoint 细节)。
按 agent(CLI 覆盖)
为某个 agent 显式设置 auth profile 的优先顺序覆盖(存储在该 agent 的 auth-profiles.json 中):
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,然后重新检查:
openclaw models statusToken 即将过期/已过期
运行 openclaw models status 确认哪个 profile 即将过期。如果 profile 缺失,请重新运行 claude setup-token 并再次粘贴 token。
依赖要求
- Claude Max 或 Pro 订阅(用于
claude setup-token) - 已安装 Claude Code CLI(
claude命令可用)