Cloudflare AI Gateway 位于提供方 API 之前,让你可以添加分析、缓存和控制功能。对于 Anthropic,OpenClaw 通过你的 Gateway 端点使用 Anthropic Messages API。
| Property | Value |
|---|
| Provider | cloudflare-ai-gateway |
| Base URL | https://gateway.ai.cloudflare.com/v1/<account_id>/<gateway_id>/anthropic |
| Default model | cloudflare-ai-gateway/claude-sonnet-4-6 |
| API key | CLOUDFLARE_AI_GATEWAY_API_KEY(你用于通过 Gateway 发起请求的提供方 API key) |
对于通过 Cloudflare AI Gateway 路由的 Anthropic 模型,请将你的 Anthropic API key 作为提供方密钥使用。
当 Anthropic Messages 模型启用 thinking 时,OpenClaw 会在通过 Cloudflare AI Gateway 发送负载之前移除尾随的 assistant prefill turns。
Anthropic 会拒绝在 extended thinking 下进行 response prefilling,而普通的
non-thinking prefill 仍然可用。
Getting started
设置提供方 API key 和 Gateway 详情
运行 onboarding 并选择 Cloudflare AI Gateway 认证选项:openclaw onboard --auth-choice cloudflare-ai-gateway-api-key
这会提示你输入 account ID、gateway ID 和 API key。 设置默认模型
将模型添加到你的 OpenClaw 配置中:{
agents: {
defaults: {
model: { primary: "cloudflare-ai-gateway/claude-sonnet-4-6" },
},
},
}
验证模型可用
openclaw models list --provider cloudflare-ai-gateway
Non-interactive example
对于脚本或 CI 环境,请在命令行中传入所有值:
openclaw onboard --non-interactive \
--mode local \
--auth-choice cloudflare-ai-gateway-api-key \
--cloudflare-ai-gateway-account-id "your-account-id" \
--cloudflare-ai-gateway-gateway-id "your-gateway-id" \
--cloudflare-ai-gateway-api-key "$CLOUDFLARE_AI_GATEWAY_API_KEY"
Advanced configuration
如果你在 Cloudflare 中启用了 Gateway 认证,请添加 cf-aig-authorization 标头。这是额外添加的,不同于你的提供方 API key。{
models: {
providers: {
"cloudflare-ai-gateway": {
headers: {
"cf-aig-authorization": "Bearer <cloudflare-ai-gateway-token>",
},
},
},
},
}
cf-aig-authorization 标头用于对 Cloudflare Gateway 本身进行认证,而提供方 API key(例如你的 Anthropic key)用于对上游提供方进行认证。
如果 Gateway 作为守护进程运行(launchd/systemd),请确保 CLOUDFLARE_AI_GATEWAY_API_KEY 对该进程可用。仅在交互式 shell 中导出的密钥不会帮助 launchd/systemd 守护进程,除非该环境也被导入其中。请将密钥设置在 ~/.openclaw/.env 中,或通过 env.shellEnv 设置,以确保 gateway 进程可以读取它。
Model selection
选择提供方、模型引用和故障切换行为。
Troubleshooting
常规故障排查和 FAQ。