Anthropic (Claude)
Anthropic 提供 Claude 模型系列。OpenClaw 支持两种认证方式:API 密钥(按量计费)和 setup-token(使用 Claude 订阅)。
方式一:API 密钥
适用于标准 API 访问和按量计费。在 Anthropic Console 中创建 API 密钥。
# 交互式设置
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" }
}
}
}方式二:setup-token(订阅)
使用 Claude 订阅进行认证。setup-token 通过 Claude Code CLI 生成,不是 Anthropic Console。
# 在任何机器上生成 setup-token
claude setup-token
# 在 Gateway 主机上粘贴
openclaw models auth paste-token --provider anthropic
# 或在 Gateway 主机上直接生成
openclaw models auth setup-token --provider anthropic配置中不需要显式的 API Key,只需指定模型:
{
agents: {
defaults: {
model: { primary: "anthropic/claude-opus-4-5" }
}
}
}提示缓存
OpenClaw 支持 Anthropic 的提示缓存功能(仅 API 密钥方式,订阅认证不支持)。 使用 API 密钥时默认启用 5 分钟缓存。
| cacheRetention | 缓存时长 | 说明 |
|---|---|---|
| none | 无 | 禁用提示缓存 |
| short | 5 分钟 | API 密钥默认值 |
| long | 1 小时 | 需要 beta 标志 |
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-5": {
params: { cacheRetention: "long" }
}
}
}
}
}常见问题
401 错误 / Token 突然失效
订阅认证可能过期或被撤销。重新运行 claude setup-token 并在 Gateway 主机上粘贴。
No API key found for provider "anthropic"
认证是按 Agent 的。新 Agent 不会继承主 Agent 的密钥。为该 Agent 重新运行引导或粘贴 Token。
OAuth token refresh failed
使用 setup-token 重新认证:openclaw models auth setup-token --provider anthropic
注意事项
- 模型引用格式为
anthropic/model-name - 使用
openclaw models status检查认证状态 - 多 Key 可用逗号分隔写在
ANTHROPIC_API_KEYS环境变量中