身份验证 (Authentication)
OpenClaw 支持模型提供商的 OAuth 和 API 密钥。对于 Anthropic 帐户,我们建议使用 API 密钥。对于 Claude 订阅访问,请使用由 claude setup-token 创建的长效令牌。
有关完整的 OAuth 流程和存储布局,请参阅 /docs/concepts/oauth。
推荐的 Anthropic 设置 (API 密钥)
Section titled “推荐的 Anthropic 设置 (API 密钥)”如果您直接使用 Anthropic,请使用 API 密钥。
- 在 Anthropic 控制台中创建一个 API 密钥。
- 将其放在 Gateway 主机(运行
openclaw gateway的机器)上。
export ANTHROPIC_API_KEY="..."openclaw models status- 如果 Gateway 在 systemd/launchd 下运行,首选将其放在
~/.openclaw/.env中,以便守护进程可以读取它:
cat >> ~/.openclaw/.env <<'EOF'ANTHROPIC_API_KEY=...EOF然后重启守护进程(或重启您的 Gateway 进程)并重新检查:
openclaw models statusopenclaw doctor如果您不想自己管理环境变量,入职向导可以存储供守护进程使用的 API 密钥:openclaw onboard。
有关环境继承(env.shellEnv, ~/.openclaw/.env, systemd/launchd)的详细信息,请参阅 帮助。
Anthropic: setup-token (订阅认证)
Section titled “Anthropic: setup-token (订阅认证)”对于 Anthropic,推荐的路径是 API 密钥。如果您使用的是 Claude 订阅,也支持 setup-token 流程。在 Gateway 主机 上运行它:
claude setup-token然后将其粘贴到 OpenClaw 中:
openclaw models auth setup-token --provider anthropic如果令牌是在另一台机器上创建的,请手动粘贴:
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 密钥。
手动输入令牌(任何提供商;写入 auth-profiles.json + 更新配置):
openclaw models auth paste-token --provider anthropicopenclaw models auth paste-token --provider openrouter自动化友好的检查(过期/丢失时退出 1,即将过期时退出 2):
openclaw models status --check可选的操作脚本(systemd/Termux)记录在这里: /docs/automation/auth-monitoring
claude setup-token需要交互式 TTY。
检查模型认证状态
Section titled “检查模型认证状态”openclaw models status