Appearance
本页介绍在 OpenClaw 中使用 Anthropic Claude 模型的完整配置方法。核心提示:Anthropic 在 2026-04-04 通知 OpenClaw 用户,通过 Claude 订阅使用 OpenClaw 属于第三方工具使用,需要开启 Extra Usage(按量单独计费);推荐使用 Anthropic API Key 获得最清晰的计费路径。覆盖 API Key 配置、Prompt Caching(5 分钟/1 小时)、fast mode(service_tier)、1M 上下文 Beta 开关,以及 401 错误和认证失败的排查方法。
Anthropic(Claude)
Anthropic 构建了 Claude 模型家族,通过 API 提供访问。在 OpenClaw 中,新的 Anthropic 配置应使用 API Key。
计费重要提示:
- Anthropic API Key:按正常 Anthropic API 计费
- 通过 Claude 订阅在 OpenClaw 中使用:Anthropic 于 2026-04-04 通知 OpenClaw 用户,此路径属于第三方工具使用,需要开启 Extra Usage(按量付费,与订阅分开计费)
如需最清晰的生产路径,请使用 Anthropic API Key。
选项 A:Anthropic API Key
最适合标准 API 访问和基于用量的计费。在 Anthropic Console 中创建 API Key。
CLI 配置
bash
openclaw onboard
# 选择:Anthropic API key
# 或非交互式
openclaw onboard --anthropic-api-key "$ANTHROPIC_API_KEY"配置示例
json5
{
env: { ANTHROPIC_API_KEY: "sk-ant-..." },
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
}Thinking 默认值(Claude 4.6)
- Anthropic Claude 4.6 模型在 OpenClaw 中默认使用
adaptivethinking(未明确设置 thinking 级别时) - 可以通过
/think:<level>或 model params 覆盖:agents.defaults.models["anthropic/<model>"].params.thinking
Fast Mode(Anthropic API)
OpenClaw 的共享 /fast 开关支持直接公网 Anthropic 流量,包括 API Key 和 OAuth 认证请求(发送到 api.anthropic.com)。
/fast on→service_tier: "auto"/fast off→service_tier: "standard_only"
默认配置:
json5
{
agents: {
defaults: {
models: {
"anthropic/claude-sonnet-4-6": {
params: { fastMode: true },
},
},
},
},
}重要限制:
- OpenClaw 只为直接
api.anthropic.com请求注入 Anthropic service tier。通过代理或网关路由时,/fast不影响service_tier - 显式设置的
serviceTier或service_tier模型参数会覆盖/fast默认值
Prompt Caching(Anthropic API)
OpenClaw 支持 Anthropic Prompt Caching 功能。仅 API Key 可用,旧版 token 认证不支持缓存设置。
配置
使用 model config 中的 cacheRetention 参数:
| 值 | 缓存时长 | 说明 |
|---|---|---|
none | 不缓存 | 禁用 Prompt Caching |
short | 5 分钟 | API Key 认证的默认值 |
long | 1 小时 | 长期缓存 |
json5
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-6": {
params: { cacheRetention: "long" },
},
},
},
},
}默认行为
使用 Anthropic API Key 认证时,OpenClaw 自动对所有 Anthropic 模型应用 cacheRetention: "short"(5 分钟缓存)。可通过显式设置 cacheRetention 覆盖。
多 Agent 缓存覆盖
用 model-level params 设置基准,再通过 agents.list[].params 覆盖特定 agent:
json5
{
agents: {
defaults: {
model: { primary: "anthropic/claude-opus-4-6" },
models: {
"anthropic/claude-opus-4-6": {
params: { cacheRetention: "long" }, // 大多数 agent 的基准
},
},
},
list: [
{ id: "research", default: true },
{ id: "alerts", params: { cacheRetention: "none" } }, // 仅此 agent 禁用缓存
],
},
}Bedrock Claude 说明
- Bedrock 上的 Anthropic Claude 模型(
amazon-bedrock/*anthropic.claude*)在配置后支持cacheRetention透传。 - 非 Anthropic Bedrock 模型在运行时强制设为
cacheRetention: "none"。 - Anthropic API Key 智能默认值也会为 Claude-on-Bedrock 模型引用补种
cacheRetention: "short"(未显式设置时)。
1M 上下文窗口(Anthropic Beta)
Anthropic 的 1M 上下文窗口处于 Beta 阶段。在 OpenClaw 中,通过 params.context1m: true 按模型启用(支持部分 Opus/Sonnet 模型):
json5
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-6": {
params: { context1m: true },
},
},
},
},
}OpenClaw 将此映射到 anthropic-beta: context-1m-2025-08-07。
要求:Anthropic 必须在该凭据上允许长上下文使用(通常是 API Key 计费,或已开启 Extra Usage 的 Claude 登录路径)。否则 Anthropic 会返回 HTTP 429: rate_limit_error: Extra usage is required for long context requests。
注意:使用旧版 Anthropic token 认证(sk-ant-oat-*)时,Anthropic 当前拒绝 context-1m-* Beta 请求。OpenClaw 会记录警告并回退到标准上下文窗口。
已移除:Claude CLI 后端
内置的 Anthropic claude-cli 后端已被移除。
- Anthropic 的 2026-04-04 通知说明,OpenClaw 驱动的 Claude 登录流量是第三方工具使用,需要 Extra Usage
- 使用 API Key 进行 OpenClaw 中的 Anthropic 流量
注意
- Anthropic 公开的 Claude Code 文档仍然记录了
claude -p等直接 CLI 使用方式,但 Anthropic 向 OpenClaw 用户发出的单独通知说明:OpenClaw 的 Claude 登录路径属于第三方工具使用,需要 Extra Usage(独立于订阅的按量计费)。推荐在生产中使用 Anthropic API Key。 - Anthropic setup-token 已在 OpenClaw 中作为旧版/手动路径恢复可用,但 Anthropic 针对 OpenClaw 的计费通知依然适用,需预期 Anthropic 要求此路径开启 Extra Usage。
- 认证详情和复用规则参见 OAuth 概念。
排查问题
401 错误 / token 突然无效
旧版 Anthropic token 认证可能过期或被撤销。新配置迁移到 Anthropic API Key。
No API key found for provider "anthropic"
认证是按 agent 的,新建 agent 不继承主 agent 的 Key。为该 agent 重新运行 onboarding,或在 gateway 主机上配置 API Key,然后用 openclaw models status 验证。
No credentials found for profile anthropic:default
运行 openclaw models status 查看当前激活的 auth profile,然后重新 onboarding 或为该 profile 路径配置 API Key。
No available auth profile (all in cooldown/unavailable)
运行 openclaw models status --json 查看 auth.unusableProfiles。Anthropic 限速冷却可能是按模型的,兄弟 Anthropic 模型可能仍可用。添加另一个 Anthropic profile 或等待冷却。
更多:排查故障。
常见问题
Q: 用 Claude Pro 订阅账号登录 OpenClaw,收费会比直接用 Claude 贵吗?
A: 根据 Anthropic 2026-04-04 的公告,通过 OpenClaw 使用 Claude 订阅属于"第三方工具使用",需要开启 Extra Usage(按量计费,与订阅配额分开)。如果想要可预期的成本,建议直接用 Anthropic API Key,按 token 量计费,计费规则最透明。
Q: Prompt Caching 什么时候应该用 long(1小时)而不是 short(5分钟)?
A: 对于系统 prompt 或上下文不常变化的场景(如固定任务、长期运行的 agent),用 long 可以显著减少重复缓存写入的成本。对于内容变化频繁(如对话历史轮换快)或对成本敏感不想有缓存写入费用的场景,用 short 或 none。
Q: 1M 上下文开启后会自动使用吗,还是需要在对话中明确触发?
A: 设置 params.context1m: true 后,OpenClaw 会在所有请求中加入对应的 anthropic-beta 头,由 Anthropic 服务端根据实际 token 数决定是否激活长上下文。你不需要在对话中手动触发,但该功能对凭据有要求(需要已开启 Extra Usage 或使用 API Key 计费路径)。