Anthropic
Anthropic (Claude)
Section titled “Anthropic (Claude)”Anthropic 构建了 Claude 模型系列,并通过 API 提供访问。 在 OpenClaw 中,您可以使用 API 密钥或 setup-token 进行身份验证。
选项 A: Anthropic API 密钥
Section titled “选项 A: Anthropic API 密钥”最适合: 标准 API 访问和基于使用量的计费。 在 Anthropic 控制台中创建您的 API 密钥。
CLI 设置
Section titled “CLI 设置”openclaw onboard# 选择: Anthropic API key
# 或非交互式openclaw onboard --anthropic-api-key "$ANTHROPIC_API_KEY"{ env: { ANTHROPIC_API_KEY: "sk-ant-..." }, agents: { defaults: { model: { primary: "anthropic/claude-opus-4-5" } } },}提示缓存 (Anthropic API)
Section titled “提示缓存 (Anthropic API)”除非您设置,否则 OpenClaw 不会 覆盖 Anthropic 的默认缓存 TTL。 这仅适用于 API;订阅认证不支持 TTL 设置。
要为每个模型设置 TTL,请在模型 params 中使用 cacheControlTtl:
{ agents: { defaults: { models: { "anthropic/claude-opus-4-5": { params: { cacheControlTtl: "5m" }, // 或 "1h" }, }, }, },}OpenClaw 包含用于 Anthropic API 请求的 extended-cache-ttl-2025-04-11 beta 标志; 如果您覆盖提供商标头,请保留它(参见 /zh/docs/gateway/configuration)。
选项 B: Claude setup-token
Section titled “选项 B: Claude setup-token”最适合: 使用您的 Claude 订阅。
获取 setup-token
Section titled “获取 setup-token”Setup-token 由 Claude Code CLI 创建,而不是 Anthropic 控制台。您可以在任何机器上运行此命令:
claude setup-token将令牌粘贴到 OpenClaw(向导:Anthropic token (paste setup-token)),或在网关主机上运行:
openclaw models auth setup-token --provider anthropic如果您在另一台机器上生成了令牌,请粘贴它:
openclaw models auth paste-token --provider anthropicCLI 设置
Section titled “CLI 设置”# 在 onboarding 期间粘贴 setup-tokenopenclaw onboard --auth-choice setup-token{ agents: { defaults: { model: { primary: "anthropic/claude-opus-4-5" } } },}- 使用
claude setup-token生成 setup-token 并粘贴,或在网关主机上运行openclaw models auth setup-token。 - 如果您在 Claude 订阅上看到“OAuth token refresh failed …”,请使用 setup-token 重新认证。请参阅 /zh/docs/gateway/troubleshooting#oauth-token-refresh-failed-anthropic-claude-subscription。
- 认证详情和重用规则在 /zh/docs/concepts/oauth 中。
401 errors / token suddenly invalid
- Claude 订阅认证可能会过期或被撤销。重新运行
claude setup-token并将其粘贴到 网关主机 中。 - 如果 Claude CLI 登录位于另一台机器上,请在网关主机上使用
openclaw models auth paste-token --provider anthropic。
No API key found for provider “anthropic”
- 认证是 针对每个 agent 的。新 agent 不会继承主 agent 的密钥。
- 为该 agent 重新运行 onboarding,或在网关主机上粘贴 setup-token / API 密钥, 然后使用
openclaw models status验证。
No credentials found for profile anthropic:default
- 运行
openclaw models status查看哪个认证配置文件处于活动状态。 - 重新运行 onboarding,或为该配置文件粘贴 setup-token / API 密钥。
No available auth profile (all in cooldown/unavailable)
- 检查
openclaw models status --json中的auth.unusableProfiles。 - 添加另一个 Anthropic 配置文件或等待冷却时间结束。