跳转到内容

Anthropic

Anthropic 构建了 Claude 模型家族。OpenClaw 支持两种认证方式:

  • API 密钥 — 通过使用量计费直接访问 Anthropic API (anthropic/* 模型)
  • Claude CLI — 在同一主机上复用现有的 Claude CLI 登录

最适用于: 标准 API 访问和基于使用量的计费。

  1. 获取您的 API 密钥

    API Console 中创建一个 Anthropic 密钥。

  2. 运行新手引导

    Terminal window
    openclaw onboard
    # choose: Anthropic API key

    或者直接传入密钥:

    Terminal window
    openclaw onboard --anthropic-api-key "$ANTHROPIC_API_KEY"
  3. 验证模型是否可用

    Terminal window
    openclaw models list --provider anthropic
{
env: { ANTHROPIC_API_KEY: "sk-ant-..." },
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
}

在未设置显式思考级别时,Claude 4.6 模型在 OpenClaw 中默认为 adaptiveOpenClaw 思考模式。

使用 /think:<level> 或在模型参数中覆盖每条消息的设置:

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

OpenClaw 支持 Anthropic 的提示缓存功能,适用于 API 密钥认证。

缓存持续时间描述
"short"(默认)5 分钟针对 API 密钥认证自动应用
"long"1 小时扩展缓存
"none"无缓存禁用提示缓存
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-6": {
params: { cacheRetention: "long" },
},
},
},
},
}
Per-agent cache overrides

使用模型级参数作为基准,然后通过 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,按键覆盖)

这允许一个代理保持长寿命缓存,而同一模型上的另一个代理为突发/低复用流量禁用缓存。

Bedrock Claude notes
  • Bedrock 上的 Anthropic Claude 模型(amazon-bedrock/*anthropic.claude*)在配置时接受 cacheRetentionAnthropic 透传。
  • 非 Anthropic Bedrock 模型在运行时被强制使用 cacheRetention: "none"API。
  • API 密钥智能默认值还会在未设置显式值时为 Bedrock 上的 Claude 引用设定 cacheRetention: "short"
Fast mode

OpenClaw 的共享 /fast 切换开关支持直接的 Anthropic 流量(通往 api.anthropic.com 的 API 密钥和 OAuth)。

CommandMaps to
/fast onservice_tier: "auto"
/fast offservice_tier: "standard_only"
{
agents: {
defaults: {
models: {
"anthropic/claude-sonnet-4-6": {
params: { fastMode: true },
},
},
},
},
}
Media understanding (image and PDF)

捆绑的 Anthropic 插件注册了图像和 PDF 理解功能。OpenClaw 会根据配置的 Anthropic 身份验证自动解析媒体能力 — 不需要 额外的配置。

PropertyValue
Default 模型claude-opus-4-7
Supported inputImages, PDF documents

当图像或 PDF 附加到对话时,OpenClaw 会自动 通过 Anthropic 媒体理解提供商进行路由。

1M context window (beta)

Anthropic 的 1M 上下文窗口处于 beta 封测状态。请针对每个模型启用它:

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

OpenClaw 会将其映射到请求中的 anthropic-beta: context-1m-2025-08-07

params.context1m: true 也适用于符合条件的 Opus 和 Sonnet CLI 的 Claude CLI 后端 (claude-cli/*),从而扩展这些 API 会话的运行时 上下文窗口,以匹配直接 Anthropic 的行为。

Claude Opus 4.7 1M context

anthropic/claude-opus-4.7 及其 claude-cli 变体默认具有 1M 上下文 窗口 —— 无需 params.context1m: true

401 错误 / 令牌突然失效

Anthropic 令牌认证会过期且可能被撤销。对于新设置,请改用 Anthropic API 密钥。

No API key found for 提供商 "anthropic"

Anthropic 身份验证是针对每个代理 的 —— 新代理不会继承主代理的密钥。请为该代理重新运行新手引导 (或在网关主机上配置 API 密钥),然后使用 openclaw models status 进行验证。

No credentials found for profile "anthropic:default"

运行 openclaw models status 以查看哪个身份验证配置文件处于活动状态。重新运行新手引导,或为该配置文件路径配置 API 密钥。

No available auth profile (all in cooldown)

检查 openclaw models status --json 获取 auth.unusableProfilesAnthropicAnthropicAnthropic。Anthropic 的速率限制冷却期可能与模型范围有关,因此同级的 Anthropic 模型可能仍然可用。添加另一个 Anthropic 配置文件或等待冷却期结束。

Model selection

选择提供商、模型引用以及故障转移行为。

CLI backends

Claude CLI 后端设置和运行时详情。

Prompt caching

提示缓存如何在各个提供商之间工作。

OAuth and auth

认证详情和凭证重用规则。