Appearance
通过 Anthropic API Key 或复用已有 Claude CLI 登录,即可在 OpenClaw 中使用 Claude 模型。运行 openclaw onboard 选择对应认证方式开始;验证模型列表用 openclaw models list --provider anthropic。注意:Claude CLI 路径当前被 Anthropic 视为允许(除非后续新政策),但生产环境推荐 API Key 以获得最可预测的计费。本页覆盖 thinking 默认值、prompt caching(short/long)、fast mode(service_tier)、1M 上下文(beta)以及常见认证错误排查。
OpenClaw 配置 Anthropic Claude:API Key、CLI 与高级选项
Anthropic 构建了 Claude 模型系列。OpenClaw 支持两种认证路径:
- API Key — 直接使用 Anthropic 公开 API,按用量计费(
anthropic/*模型) - Claude CLI — 复用同一主机上已有的 Claude CLI 登录凭据
WARNING
Anthropic 工作人员告知 OpenClaw,OpenClaw 风格的 Claude CLI 使用目前是允许的,因此 OpenClaw 将复用 Claude CLI 及 claude -p 用法视为被认可,除非 Anthropic 发布新政策。
对于长期运行的网关主机,Anthropic API Key 仍然是清晰、可预测的生产路径。
Anthropic 当前公开文档:
起步
API Key
**最佳场景:** 标准 API 访问,按用量计费。
获取 API Key
在 [Anthropic Console](https://console.anthropic.com/) 中创建 API Key。
运行 onboarding
```bash
openclaw onboard
# 选择:Anthropic API key
```
或者直接传入 Key:
```bash
openclaw onboard --anthropic-api-key "$ANTHROPIC_API_KEY"
```
验证模型可用
```bash
openclaw models list --provider anthropic
```
### 配置示例
```json5
{
env: { ANTHROPIC_API_KEY: "sk-ant-..." },
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
}
```
Claude CLI
**最佳场景:** 复用已有的 Claude CLI 登录,无需单独 API Key。
确保 Claude CLI 已安装并登录
验证:
```bash
claude --version
```
运行 onboarding
```bash
openclaw onboard
# 选择:Claude CLI
```
OpenClaw 会自动检测并复用现有 Claude CLI 凭据。
验证模型可用
```bash
openclaw models list --provider anthropic
```
INFO
关于 Claude CLI 后端的设置和运行时细节,请参考 [CLI 后端](/ai/ai-tools/openclaw/gateway/cli-backends)。
### 配置示例
推荐使用规范的 Anthropic 模型引用(`anthropic/*`)并附加 CLI 运行时覆盖:
```json5
{
agents: {
defaults: {
model: { primary: "anthropic/claude-opus-4-7" },
models: {
"anthropic/claude-opus-4-7": {
agentRuntime: { id: "claude-cli" },
},
},
},
},
}
```
旧版 `claude-cli/claude-opus-4-7` 模型引用仍然兼容,但新配置应将 provider/model 选择保持为 `anthropic/*`,并将执行后端放在 provider/model 运行时策略中。
TIP
如果希望计费路径最清晰,直接使用 Anthropic API Key。OpenClaw 也支持 [OpenAI Codex](/ai/ai-tools/openclaw/providers/openai)、[Qwen Cloud](/ai/ai-tools/openclaw/providers/qwen)、[MiniMax](/ai/ai-tools/openclaw/providers/minimax) 和 [Z.AI / GLM](/ai/ai-tools/openclaw/providers/glm) 等订阅式选项。
Thinking 默认值(Claude 4.6)
Claude 4.6 模型在未显式设置 thinking 级别时,默认使用 adaptive thinking。
可通过 /think:<level> 在会话中覆盖,或在模型参数中设置:
json5
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-6": {
params: { thinking: "adaptive" },
},
},
},
},
}Prompt caching
OpenClaw 支持 Anthropic 的 prompt caching 功能(仅 API Key 认证方式)。
| 值 | 缓存时长 | 说明 |
|---|---|---|
"short" (默认) | 5 分钟 | API Key 认证时自动应用 |
"long" | 1 小时 | 更长的缓存 |
"none" | 不缓存 | 关闭 prompt caching |
json5
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-6": {
params: { cacheRetention: "long" },
},
},
},
},
}每个 Agent 独立覆盖缓存
以模型级参数作为基准,再通过 `agents.list[].params` 覆盖特定 agent:
```json5
{
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 覆盖)
这样,一个 agent 可以保持长期缓存,而同一模型上的另一个 agent 可因突发/低复用流量而禁用缓存。
Bedrock Claude 说明
- Bedrock 上的 Anthropic Claude 模型(`amazon-bedrock/*anthropic.claude*`)在配置后支持透传 `cacheRetention`。
- 非 Anthropic 的 Bedrock 模型在运行时会被强制设为 `cacheRetention: "none"`。
- API Key 智能默认值也会为 Claude-on-Bedrock 模型引用自动补种 `cacheRetention: "short"`(当未显式设置时)。
高级配置
快速模式(Fast mode)
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 },
},
},
},
},
}
```
INFO
- 仅对直接发送到 `api.anthropic.com` 的请求注入。通过代理路由时,`service_tier` 不会受影响。
- 显式设置的 `serviceTier` 或 `service_tier` 参数会覆盖 `/fast` 的值(当两者都设置了时)。
- 对于没有 Priority Tier 容量的账户,`service_tier: "auto"` 可能解析为 `standard`。
媒体理解(图片与 PDF)
内置的 Anthropic 插件注册了图片和 PDF 理解能力。OpenClaw 会根据配置的 Anthropic 认证自动解析媒体支持——无需额外配置。
| 属性 | 值 |
| --------------- | --------------------- |
| 默认模型 | `claude-opus-4-7` |
| 支持的输入 | 图片、PDF 文档 |
当在对话中附加图片或 PDF 时,OpenClaw 会自动通过 Anthropic 媒体理解 provider 处理。
1M 上下文窗口(Beta)
Anthropic 的 1M 上下文窗口处于 Beta 阶段,需要凭据有对应权限。按模型开启:
```json5
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-6": {
params: { context1m: true },
},
},
},
},
}
```
OpenClaw 会将此映射为请求中的 `anthropic-beta: context-1m-2025-08-07`。
`params.context1m: true` 也适用于 Claude CLI 后端(`claude-cli/*`)中符合条件的 Opus 和 Sonnet 模型,从而扩展运行时上下文窗口以匹配直接 API 行为。
WARNING
需要你的 Anthropic 凭据拥有长上下文访问权限。旧版 token 认证(`sk-ant-oat-*`)会被 1M 上下文请求拒绝——OpenClaw 会记录警告并回退到标准上下文窗口。
Claude Opus 4.7 1M 上下文
`anthropic/claude-opus-4.7` 及其 `claude-cli` 变体默认拥有 1M 上下文窗口——无需设置 `params.context1m: true`。
故障排除
401 错误 / token 突然失效
Anthropic token 认证有有效期,也可能被撤销。新配置请使用 Anthropic API Key 替代。
*No API key found for provider *
Anthropic 认证是**按 agent** 的——新建 agent 不会继承主 agent 的 Key。请为该 agent 重新运行 onboarding(或在网关主机上配置 API Key),然后用 `openclaw models status` 验证。
*No credentials found for profile *
运行 `openclaw models status` 查看当前激活的 auth profile,然后重新运行 onboarding,或为该 profile 路径配置 API Key。
No available auth profile (all in cooldown)
运行 `openclaw models status --json` 查看 `auth.unusableProfiles`。Anthropic 的限速冷却可能是按模型分级的,同组的其他 Anthropic 模型可能仍可用。添加另一个 Anthropic profile 或等待冷却。
相关文档
模型选择
选择 provider、模型引用和故障转移行为。
CLI 后端
Claude CLI 后端设置和运行时细节。
Prompt 缓存
各 provider 的 prompt caching 工作原理。
OAuth 与认证
认证细节和凭据复用规则。
常见问题
OpenClaw 里用 Claude 订阅(Claude CLI)需要额外费用吗?
根据 Anthropic 当前政策,OpenClaw 风格的 Claude CLI 复用被视为允许,但未来可能调整。生产环境推荐使用 Anthropic API Key,计费最可预测。
OpenClaw 报错 "No credentials found for profile anthropic:default" 怎么处理?
运行 openclaw models status 查看当前激活的 auth profile,然后为对应 agent 重新运行 openclaw onboard 选择认证方式,或直接配置环境变量 ANTHROPIC_API_KEY。
1M 上下文开启后不生效,OpenClaw 回退到标准窗口怎么办?
检查你的 Anthropic 凭据是否拥有长上下文访问权限。旧版 token 认证(sk-ant-oat-*)会被拒绝,需改用 API Key。同时确认模型支持:claude-opus-4-6 等需要设置 params.context1m: true,而 claude-opus-4.7 默认支持 1M 窗口。