Cloudflare AI Gateway

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 key:CLOUDFLARE_AI_GATEWAY_API_KEY(通过 Gateway 代理请求时使用的 provider API key)

对于 Anthropic 模型,请使用你的 Anthropic API key。

快速开始

  1. 设置 provider API key 与 Gateway 信息:
openclaw onboard --auth-choice cloudflare-ai-gateway-api-key
  1. 设置默认模型:
{
  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 头(这与 provider API key 并存)。

{
  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 注入)。