Anthropic (Claude)

Anthropic 构建�?Claude 模型系列并通过 API 提供访问�? �?OpenClaw 中,你可以通过 API 密钥�?setup-token 进行认证�?

选项 A:Anthropic API 密钥

**最适合�?*标准 API 访问和按使用量计费�? �?Anthropic Console 创建你的 API 密钥�?

CLI 设置

openclaw onboard
# 选择:Anthropic API 密钥

# 或非交互�?
openclaw onboard --anthropic-api-key "$ANTHROPIC_API_KEY"

配置片段

{
  env: { ANTHROPIC_API_KEY: "sk-ant-..." },
  agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
}

提示缓存(Anthropic API�?

OpenClaw 支持 Anthropic 的提示缓存功能。这�?API 专有;订阅认证不遵守缓存设置�?

配置

在模型配置中使用 cacheRetention 参数�?

�?缓存持续时间描述
none无缓�?禁用提示缓存
short5 分钟API 密钥认证的默认�?
long1 小时扩展缓存(需�?beta 标志�?
{
  agents: {
    defaults: {
      models: {
        "anthropic/claude-opus-4-6": {
          params: { cacheRetention: "long" },
        },
      },
    },
  },
}

默认�?

当使�?Anthropic API 密钥认证时,OpenClaw 自动为所�?Anthropic 模型应用 cacheRetention: "short"�? 分钟缓存)。你可以通过在配置中明确设置 cacheRetention 来覆盖此默认值�?

每个代理�?cacheRetention 覆盖

使用模型级参数作为基线,然后通过 agents.list[].params 覆盖特定代理�?

{
  agents: {
    defaults: {
      model: { primary: "anthropic/claude-opus-4-6" },
      models: {
        "anthropic/claude-opus-4-6": {
          params: { cacheRetention: "long" }, // 大多数代理的基线
        },
      },
    },
    list: [
      { id: "research", default: true },
      { id: "alerts", params: { cacheRetention: "none" } }, // 仅覆盖此代理
    ],
  },
}

缓存相关参数的配置合并顺序:

  1. agents.defaults.models["provider/model"].params
  2. agents.list[].params(匹�?id,按 key 覆盖�?

这允许一个代理在同一个模型上保持长期缓存,而另一个代理禁用缓存以避免突发/低重用流量的写入成本�?

Bedrock Claude 说明

  • Bedrock 上的 Anthropic Claude 模型(amazon-bedrock/*anthropic.claude*)在配置时接�?cacheRetention 直通�?
  • �?Anthropic Bedrock 模型在运行时被强制为 cacheRetention: "none"�?
  • Anthropic API 密钥智能默认值还会为 Claude-on-Bedrock 模型引用种子 cacheRetention: "short",当未设置明确值时�?

旧参�?

仍支持较旧的 cacheControlTtl 参数以保持向后兼容:

  • "5m" 映射�?short
  • "1h" 映射�?long

我们建议迁移到新�?cacheRetention 参数�?

OpenClaw �?Anthropic API 请求包含 extended-cache-ttl-2025-04-11 beta 标志;如果你覆盖 provider 头,请保留它(参�?/gateway/configuration)�?

1M 上下文窗口(Anthropic beta�?

Anthropic �?1M 上下文窗口是 beta 受限的。在 OpenClaw 中,为支持的 Opus/Sonnet 模型使用 params.context1m: true 为每个模型启用它�?

{
  agents: {
    defaults: {
      models: {
        "anthropic/claude-opus-4-6": {
          params: { context1m: true },
        },
      },
    },
  },
}

OpenClaw 将其映射�?Anthropic 请求上的 anthropic-beta: context-1m-2025-08-07�?

注意:Anthropic 当前在使�?OAuth/订阅令牌(sk-ant-oat-*)时拒绝 context-1m-* beta 请求。OpenClaw 自动�?OAuth 认证跳过 context1m beta 头,并保留所需�?OAuth betas�?

选项 B:Claude setup-token

**最适合�?*使用你的 Claude 订阅�?

在哪里获�?setup-token

setup-token �?Claude Code CLI 创建,而不�?Anthropic Console。你可以�?*任何机器**上运行:

claude setup-token

�?token 粘贴�?OpenClaw(向导:**Anthropic token(粘�?setup-token�?*),或在 gateway 主机上运行:

openclaw models auth setup-token --provider anthropic

如果你在不同的机器上生成�?token,请粘贴它:

openclaw models auth paste-token --provider anthropic

CLI 设置(setup-token�?

# 在入门期间粘�?setup-token
openclaw onboard --auth-choice setup-token

配置片段(setup-token�?

{
  agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
}

说明

故障排除

401 错误 / token 突然无效

  • Claude 订阅认证可能会过期或被撤销。重新运�?claude setup-token 并将其粘贴到 gateway 主机上�?
  • 如果 Claude CLI 登录在不同的机器上,�?gateway 主机上使�? openclaw models auth paste-token --provider anthropic�?

未找�?provider “anthropic” �?API 密钥

  • 认证是每个代理的。新代理不会继承主代理的密钥�?
  • 为该代理重新运行入门配置,或�?gateway 主机上粘�?setup-token / API 密钥�? 然后使用 openclaw models status 验证�?

*未找�?profile anthropic:default 的凭�?

  • 运行 openclaw models status 查看哪个 auth profile 是活动的�?
  • 重新运行入门配置,或为该 profile 粘贴 setup-token / API 密钥�?

没有可用�?auth profile(全部在冷却/不可用)

  • 检�?openclaw models status --json 中的 auth.unusableProfiles�?
  • 添加另一�?Anthropic profile 或等待冷却�?

更多:/gateway/troubleshooting �?/help/faq�?