Cloudflare AI Gateway

Cloudflare AI Gateway 位於供應商 API 前方,讓你加入分析、快取和控制功能。針對 Anthropic,OpenClaw 會透過你的 Gateway 端點使用 Anthropic Messages API。

  • 供應商: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 發送請求時使用的供應商 API 金鑰)

Anthropic 模型請使用你的 Anthropic API 金鑰。

快速開始

  1. 設定供應商 API 金鑰和 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"

需要驗證的閘道

如果你在 Cloudflare 中啟用了 Gateway 驗證,需要加入 cf-aig-authorization 標頭(這是在供應商 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 設定)。