跳转到内容

Anthropic

Anthropic 构建了 Claude 模型系列,并通过 API 提供访问。 在 OpenClaw 中,您可以使用 API 密钥或 setup-token 进行身份验证。

最适合: 标准 API 访问和基于使用量的计费。 在 Anthropic 控制台中创建您的 API 密钥。

Terminal window
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" } } },
}

除非您设置,否则 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)。

最适合: 使用您的 Claude 订阅。

Setup-token 由 Claude Code CLI 创建,而不是 Anthropic 控制台。您可以在任何机器上运行此命令:

Terminal window
claude setup-token

将令牌粘贴到 OpenClaw(向导:Anthropic token (paste setup-token)),或在网关主机上运行:

Terminal window
openclaw models auth setup-token --provider anthropic

如果您在另一台机器上生成了令牌,请粘贴它:

Terminal window
openclaw models auth paste-token --provider anthropic
Terminal window
# 在 onboarding 期间粘贴 setup-token
openclaw onboard --auth-choice setup-token
{
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-5" } } },
}

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 配置文件或等待冷却时间结束。

更多信息:/zh/docs/gateway/troubleshooting/zh/docs/help/faq