Cloudflare AI Gateway Setup for Anthropic Models

Learn how to configure Cloudflare AI Gateway as a provider in OpenClaw, including authentication and model selection. This guide suits developers routing Anthropic requests through a Gateway endpoint.

Read this when

  • You want to use Cloudflare AI Gateway with OpenClaw
  • You need the account ID, gateway ID, or API key env var

Cloudflare AI Gateway acts as a layer in front of provider APIs, contributing analytics, caching, and controls. When working with Anthropic, OpenClaw routes requests through your Gateway endpoint using the Anthropic Messages API.

PropertyValue
Providercloudflare-ai-gateway
Pluginofficial external package (@openclaw/cloudflare-ai-gateway-provider)
Base URLhttps://gateway.ai.cloudflare.com/v1/<account_id>/<gateway_id>/anthropic
Default modelcloudflare-ai-gateway/claude-sonnet-4-6
API keyCLOUDFLARE_AI_GATEWAY_API_KEY (your provider API key for requests through the Gateway)

Note

When Anthropic models are routed through Cloudflare AI Gateway, supply your Anthropic API key as the provider key.

With thinking turned on for Anthropic Messages models, OpenClaw removes trailing assistant prefill turns before dispatching the payload through Cloudflare AI Gateway. Anthropic does not accept response prefilling alongside extended thinking, though standard prefill without thinking is still permitted.

Install plugin

Install the official plugin:

openclaw plugins install @openclaw/cloudflare-ai-gateway-provider

If a Gateway is already running, installation takes effect immediately; if not, it applies at the next startup. Refer to Apply changes and inspect.

Getting started

Set the provider API key and Gateway details

Launch onboarding and pick the Cloudflare AI Gateway auth option:

openclaw onboard --auth-choice cloudflare-ai-gateway-api-key

You will be asked for your account ID, gateway ID, and API key.

Set a default model

Insert the model into your OpenClaw config:

{
  agents: {
    defaults: {
      model: { primary: "cloudflare-ai-gateway/claude-sonnet-4-6" },
    },
  },
}

Verify the model is available

openclaw models list --provider cloudflare-ai-gateway

Non-interactive example

In scripted or CI environments, supply every value on the command line:

openclaw onboard --non-interactive --accept-risk --skip-health \
  --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

Authenticated gateways

Should you have turned on Gateway authentication in Cloudflare, include the cf-aig-authorization header. This comes on top of your provider API key.

{
  models: {
    providers: {
      "cloudflare-ai-gateway": {
        headers: {
          "cf-aig-authorization": "Bearer <cloudflare-ai-gateway-token>",
        },
      },
    },
  },
}

Tip

Authentication against the Cloudflare Gateway itself is handled by the cf-aig-authorization header, whereas the provider API key (your Anthropic key, for instance) handles authentication with the upstream provider.

Environment note

When the Gateway operates as a daemon (launchd/systemd), verify that CLOUDFLARE_AI_GATEWAY_API_KEY is reachable by that process.

Warning

A key exported in an interactive shell alone is of no use to a launchd/systemd daemon unless that environment is imported there too. Define the key in ~/.openclaw/.env or through env.shellEnv so the gateway process can read it.

457 words · updated Sep 18, 2026