Anthropic(Claude)
Anthropic 构建 Claude 模型系列并通过 API 提供访问。在 OpenClaw 中,你可以通过 API 密钥或 setup-token 进行认证。
选项 A:Anthropic API 密钥
最适合: 标准 API 访问和按量计费。在 Anthropic 控制台创建你的 API 密钥。
CLI 设置
bash
openclaw onboard
# 选择:Anthropic API 密钥
# 或非交互式
openclaw onboard --anthropic-api-key "$ANTHROPIC_API_KEY"配置片段
json5
{
env: { ANTHROPIC_API_KEY: "sk-ant-..." },
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-5" } } }
}提示缓存(Anthropic API)
OpenClaw 不会覆盖 Anthropic 的默认缓存 TTL,除非你设置它。这是 仅 API;订阅认证不遵守 TTL 设置。
要设置每个模型的 TTL,在模型的 params 中使用 cacheControlTtl:
json5
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-5": {
params: { cacheControlTtl: "5m" } // 或 "1h"
}
}
}
}
}OpenClaw 为 Anthropic API 请求包含 extended-cache-ttl-2025-04-11 beta 标志;如果你覆盖提供商头,请保留它(见 /gateway/configuration)。
选项 B:Claude setup-token
最适合: 使用你的 Claude 订阅。
在哪里获取 setup-token
Setup-token 由 Claude Code CLI 创建,而不是 Anthropic 控制台。你可以在任何机器上运行:
bash
claude setup-token将令牌粘贴到 OpenClaw(向导:Anthropic 令牌(粘贴 setup-token)),或在网关上运行:
bash
openclaw models auth setup-token --provider anthropic如果你在另一台机器上生成了令牌,粘贴它:
bash
openclaw models auth paste-token --provider anthropicCLI 设置
bash
# 在入职期间粘贴 setup-token
openclaw onboard --auth-choice setup-token配置片段
json5
{
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 重新认证。见 /gateway/troubleshooting#oauth-token-refresh-failed-anthropic-claude-subscription。
- 认证详情 + 重用规则在 /concepts/oauth 中。
故障排除
401 错误 / 令牌突然无效
- Claude 订阅认证可能过期或被撤销。重新运行
claude setup-token并粘贴到网关主机上。 - 如果 Claude CLI 登录在另一台机器上,在网关上使用
openclaw models auth paste-token --provider anthropic。
未找到提供商 "anthropic" 的 API 密钥
- 认证是每个智能体的。新智能体不继承主智能体的密钥。
- 为该智能体重新运行入职,或在网关上粘贴 setup-token / API 密钥,然后用
openclaw models status验证。
未找到配置文件 anthropic:default 的凭证
- 运行
openclaw models status查看哪个认证配置文件处于活动状态。 - 重新运行入职,或为该配置文件粘贴 setup-token / API 密钥。
无可用认证配置文件(全部在冷却/不可用)
- 检查
openclaw models status --json中的auth.unusableProfiles。 - 添加另一个 Anthropic 配置文件或等待冷却。
更多内容:/gateway/troubleshooting 和 /help/faq。