One endpoint for the AI stack

Building AI features means wiring your application to a provider that is, by design, non-deterministic. On top of that unpredictability, you have to track multiple API keys, monitor spend across several dashboards, and keep an eye on latency and reliability for every model you call.

Cloudflare's AI Gateway was launched two years ago to bring the company's usual controls to AI traffic. Today the service is expanding with unified billing, secure key management through Cloudflare Secrets Store, dynamic routing between providers, and Data Loss Prevention (DLP) scanning. Together these features turn AI Gateway into a single control plane for model access and cost management, with a landing page at ai.cloudflare.com/gateway.

Direct access to major providers

Managing AI providers usually means juggling separate accounts, API keys, rate limits, and credit top-ups. AI Gateway now lets you connect to Anthropic, Google, Groq, OpenAI, and xAI directly through Cloudflare. That gives you access to more than 350 models across six providers through one interface.

Rather than paying each provider separately, Cloudflare now handles billing for all supported providers through your Cloudflare account. Workers Paid users can add credits and use them for inference across providers. Real-time usage statistics and credit management are available in the AI Gateway dashboard, and inference usage appears on your regular monthly Cloudflare invoice.

BLOG-2867 Image 1
Usage rates are based on the providers' current list prices. Cloudflare collects a transaction fee when you load credits into your account.

Bring your own keys with Secrets Store

If you prefer to keep your own provider accounts, the BYO Key feature still works — and it now has better access controls. AI Gateway integrates with Cloudflare's Secrets Store so that keys are stored encrypted in a central location rather than in plain text. Secrets Store uses a two-level key hierarchy with AES encryption, and low-latency access is provided through the Quicksilver global configuration key-value store.

Keys can be managed in the AI Gateway dashboard, Secrets Store dashboard, API, or via Wrangler. By scoping a secret to AI Gateway, only AI Gateway can read it — the key cannot be used as a Workers binding or anywhere else on the Cloudflare platform.

Requests no longer need to carry the actual provider key in the header. Instead, a request can reference the secret stored in Secrets Store:

BLOG-2867 Image 2
curl -X POST https://gateway.ai.cloudflare.com/v1/<ACCOUNT_ID>/my-gateway/anthropic/v1/messages \
 --header 'cf-aig-authorization: CLOUDFLARE_AI_GATEWAY_TOKEN \
 --header 'anthropic-version: 2023-06-01' \
 --header 'Content-Type: application/json' \
 --data  '{"model": "claude-3-opus-20240229", "messages": [{"role": "user", "content": "What is Cloudflare?"}]}'
import Anthropic from '@anthropic-ai/sdk';

const anthropic = new Anthropic({
  apiKey: "CLOUDFLARE_AI_GATEWAY_TOKEN",
  baseURL: "https://gateway.ai.cloudflare.com/v1/<ACCOUNT_ID>/my-gateway/anthropic",
});

const message = await anthropic.messages.create({
  model: 'claude-3-opus-20240229',
  messages: [{role: "user", content: "What is Cloudflare?"}],
  max_tokens: 1024
});

This setup supports role-based access control. An administrator can, for example, give security administrators full control over secret lifecycle while developers receive only deploy permissions for Worker or AI Gateway bindings. All changes are logged via Cloudflare audit logging, so who did what and when is always visible. Updating a key in Secrets Store propagates automatically to every AI Gateway that references it, and reduces the risk of a key leaking via a shared deployment.

Unified request and response format

Different providers use slightly different request and response shapes. AI Gateway acts as an automatic translation layer, letting you send the same request format regardless of the underlying provider or model. This makes experimenting with models across providers more straightforward on the developer side as well.

import OpenAI from "openai";
const client = new OpenAI({
  apiKey: "YOUR_PROVIDER_API_KEY", // Provider API key
  // NOTE: the OpenAI client automatically adds /chat/completions to the end of the URL, you should not add it yourself.
  baseURL:
    "https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat",
});

const response = await client.chat.completions.create({
  model: "google-ai-studio/gemini-2.0-flash",
  messages: [{ role: "user", content: "What is Cloudflare?" }],
});

console.log(response.choices[0].message.content);

Adding logic with Dynamic Routes

The Cloudflare Workers mantra — intercept HTTP traffic and customize behavior based on attributes — now applies to AI traffic. Dynamic Routes lets you define actions on a request based on its characteristics or on a percentage split.

The intended uses mirror common gateway patterns:

  • Rate limit free-tier users by requests per second or dollar spend.
  • Run A/B tests by splitting traffic 50/50 between two models.
  • Chain models, for instance to run a guardrail or prompt-enrichment step before the main model call.

In the AI Gateway dashboard, you can set up if/else rules on request attributes. Once a route is defined, you pass its name as the model in your request JSON and AI Gateway handles the rest of the routing.

BLOG-2867 Image 3
import OpenAI from "openai";

const cloudflareToken = "CF_AIG_TOKEN";
const accountId = "{account_id}";
const gatewayId = "{gateway_id}";
const baseURL = `https://gateway.ai.cloudflare.com/v1/${accountId}/${gatewayId}`;

const openai = new OpenAI({
  apiKey: cloudflareToken,
  baseURL,
});

try {
  const model = "dynamic/<your-dynamic-route-name>";
  const messages = [{ role: "user", content: "What is a neuron?" }];
  const chatCompletion = await openai.chat.completions.create({
    model,
    messages,
  });
  const response = chatCompletion.choices[0].message;
  console.log(response);
} catch (e) {
  console.error(e);
}

DLP scanning in the gateway firewall

Earlier in 2025, Cloudflare introduced Guardrails for AI Gateway. The security surface now extends to DLP scanning. With DLP enabled, AI Gateway checks outgoing requests against DLP profiles and lets you either block or flag the contents. Free Zero Trust accounts get access to built-in profiles for categories such as Financial Information and Social Security, Insurance, Tax and Identifier Numbers. Upgraded Zero Trust accounts can define custom profiles for business-specific sensitive text.

BLOG-2867 Image 4

Administrators can choose between fully blocking or alerting on a match, so false positives do not have to stand in users' way. Every AI Gateway log now records which DLP profiles matched and the action taken.

BLOG-2867 Image 5

The roadmap

Cloudflare frames AI Gateway as an extension of the role it plays for general internet traffic: interconnectivity, observability, security and programmable actions. These features are the first in a series of releases that build toward that vision.

Developer documentation is available at developers.cloudflare.com/ai-gateway, with a quick start guide for getting started. Enterprise customers can request a consultation through Cloudflare's site.

BLOG-2867 Image 6