Anthropic (Claude)
Anthropic 开发了 Claude 模型系列,并通过 API 提供访问。 在 Clawdbot 中,您可以使用 API 密钥认证,或复用 Claude Code CLI 凭证 (setup-token 或 OAuth)。
方式 A:Anthropic API 密钥
适用场景: 标准 API 访问,按量计费。 在 Anthropic Console 中创建 API 密钥。
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" } } }
}Prompt 缓存(Anthropic API)
Clawdbot 不会覆盖 Anthropic 的默认缓存 TTL,除非您手动设置。 此功能仅适用于 API 密钥;Claude Code CLI OAuth 会忽略 TTL 设置。
按模型设置 TTL,使用 cacheControlTtl:
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-5": {
params: { cacheControlTtl: "5m" } // 或 "1h"
}
}
}
}
}Clawdbot 在 Anthropic API 请求中包含 extended-cache-ttl-2025-04-11 beta 标志; 如果您覆盖了供应商 headers,请保留此标志(详见 /gateway/configuration)。
方式 B:Claude Code CLI(setup-token 或 OAuth)
适用场景: 使用您的 Claude 订阅或已有的 Claude Code CLI 登录。
获取 setup-token
setup-token 由 Claude Code CLI 生成,不是在 Anthropic Console 中创建。可在任何机器上运行:
claude setup-token将 token 粘贴到 Clawdbot(向导中选择 Anthropic token (paste setup-token)),或在网关主机上运行:
openclaw models auth setup-token --provider anthropic如果您在另一台机器上生成了 token,粘贴它:
openclaw models auth paste-token --provider anthropicCLI 配置
# 复用 Claude Code CLI OAuth 凭证(如果已登录)
openclaw onboard --auth-choice claude-cli配置示例
{
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-5" } } }
}说明
- 使用
claude setup-token生成 token 并粘贴,或在网关主机上运行openclaw models auth setup-token。 - 如果看到 "OAuth token refresh failed ..." 错误(Claude 订阅),请重新用 setup-token 认证或在网关主机上重新同步 Claude Code CLI OAuth。详见 /gateway/troubleshooting#oauth-token-refresh-failed-anthropic-claude-subscription。
- Clawdbot 将
auth.profiles["anthropic:claude-cli"].mode设为"oauth",使配置文件同时接受 OAuth 和 setup-token 凭证。旧配置中的"token"在加载时会自动迁移。 - 认证详情和复用规则见 /concepts/oauth。
故障排除
401 错误 / token 突然失效
- 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 or anthropic:claude-cli
- 运行
openclaw models status查看当前活跃的认证配置。 - 重新运行 onboarding,或为该配置粘贴 setup-token / API 密钥。
No available auth profile (all in cooldown/unavailable)
- 检查
openclaw models status --json中的auth.unusableProfiles。 - 添加另一个 Anthropic 配置或等待冷却结束。
更多内容:/gateway/troubleshooting 和 /help/faq。