Cloudflare AI Gateway
Cloudflare AI Gateway 部署在 provider API 前面,为你提供分析、缓存和访问控制能力。对于 Anthropic 模型,OpenClaw 通过你的 Gateway 端点调用 Anthropic Messages API。
- Provider:
cloudflare-ai-gateway - Base URL:
https://gateway.ai.cloudflare.com/v1/<account_id>/<gateway_id>/anthropic - 默认模型:
cloudflare-ai-gateway/claude-sonnet-4-5 - API 密钥:
CLOUDFLARE_AI_GATEWAY_API_KEY(通过 Gateway 发请求时使用的 provider API 密钥)
对于 Anthropic 模型,使用你的 Anthropic API 密钥。
快速开始
- 设置 provider API 密钥和 Gateway 信息:
openclaw onboard --auth-choice cloudflare-ai-gateway-api-key
- 设置默认模型:
{
agents: {
defaults: {
model: { primary: "cloudflare-ai-gateway/claude-sonnet-4-5" },
},
},
}
非交互式示例
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"
需要认证的 Gateway
如果你在 Cloudflare 中启用了 Gateway 认证,需要额外添加 cf-aig-authorization header(这和 provider API 密钥是分开的)。
{
models: {
providers: {
"cloudflare-ai-gateway": {
headers: {
"cf-aig-authorization": "Bearer <cloudflare-ai-gateway-token>",
},
},
},
},
}
环境说明
如果 Gateway 以守护进程方式运行(launchd/systemd),确保 CLOUDFLARE_AI_GATEWAY_API_KEY 对该进程可见(例如放在 ~/.openclaw/.env 或通过 env.shellEnv 设置)。