Appearance
Anthropic(Claude)
Anthropic 是 Claude 系列模型的开发商。在 OpenClaw 中可以通过 API 密钥或 setup-token(Claude 订阅)两种方式认证。
方案 A:Anthropic API 密钥(推荐)
适合:标准 API 访问,按用量计费。
在 Anthropic Console 创建 API 密钥。
向导配置
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" } } },
}方案 B:Claude setup-token(订阅账户)
适合:使用 Claude 订阅(Pro/Team/Enterprise)而非 API 付费。
警告:Anthropic setup-token 仅在技术层面与 OpenClaw 兼容。Anthropic 曾限制 Claude Code 以外的订阅使用。请自行核查 Anthropic 当前条款,风险自担。
获取 setup-token
setup-token 由 Claude Code CLI 生成,可在任意机器上运行:
bash
claude setup-token将生成的 token 粘贴到 Gateway 主机上的 OpenClaw:
bash
openclaw models auth setup-token --provider anthropic
# 或者在另一台机器生成后手动粘贴
openclaw models auth paste-token --provider anthropic向导配置
bash
openclaw onboard --auth-choice setup-token配置文件
json5
{
agents: { defaults: { model: { primary: "anthropic/claude-opus-4-6" } } },
}Claude 4.6 模型与思考模式
Claude 4.6 模型在 OpenClaw 中默认使用 adaptive(自适应)思考模式:
- 每次消息临时切换:
/think:low、/think:high、/think:off - 在模型参数中固定:
json5
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-6": {
params: { thinking: "low" },
},
},
},
},
}Prompt 缓存(API 模式专属)
注意:prompt 缓存仅在 API 密钥认证时有效,订阅 token 不支持缓存设置。
cacheRetention 值 | 缓存时长 | 说明 |
|---|---|---|
"short"(默认) | 5 分钟 | API 密钥认证时自动启用 |
"long" | 1 小时 | 需要 beta 标志 |
"none" | 不缓存 | 关闭缓存 |
json5
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-6": {
params: { cacheRetention: "long" },
},
},
},
},
}按 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 不缓存
],
},
}1M 上下文窗口(Beta)
部分 Opus/Sonnet 模型支持 100 万 Token 的上下文窗口(Beta 功能):
json5
{
agents: {
defaults: {
models: {
"anthropic/claude-opus-4-6": {
params: { context1m: true },
},
},
},
},
}限制:
- 需要 API 密钥计费账户,或已启用"Extra Usage"的订阅账户
- 使用 OAuth/订阅 token(
sk-ant-oat-*)时,OpenClaw 自动跳过 1M 上下文 beta 头
常见 Claude 模型
| 模型 ID | 说明 |
|---|---|
anthropic/claude-opus-4-6 | 最强推理能力 |
anthropic/claude-sonnet-4-5 | 性能与成本均衡 |
故障排除
401 错误 / token 突然失效:
- 订阅 token 可能已过期或被吊销
- 在 Gateway 主机上重新运行
claude setup-token并粘贴
"No API key found for provider anthropic":
- 认证是按 Agent 的,新 Agent 不继承主 Agent 的密钥
- 对该 Agent 重新执行 onboarding,或在 Gateway 主机上粘贴 token/API 密钥
- 验证:
openclaw models status
"No credentials found for profile anthropic:default":
- 运行
openclaw models status查看当前激活的认证配置 - 重新 onboarding 或粘贴对应配置文件的 token/API 密钥
订阅用量限制(429):
- 运行
openclaw models status --json查看auth.unusableProfiles - 考虑添加第二个 Anthropic API 密钥配置作为备用