Skip to content
AnswerWell geo Documentation

Research · 9 min read · Answerwell

AI Inference Gateway: REST API, OpenAI Compatibility, Worker Bindings, and Billing

How Cloudflare AI Gateway routes multi-provider and Workers AI models through one API, with logging, unified credits, Workers bindings, and realtime WebSockets.

This page summarises Cloudflare documentation on AI Gateway: a control layer between your application and inference providers. It is the subject when you need one place for logging, caching, rate limiting, fallbacks, guardrails, evaluations, and billing across OpenAI, Anthropic, Workers AI, and other supported backends—without wiring a separate proxy per vendor.

AI Gateway: what it does for multi-provider inference

Section titled “AI Gateway: what it does for multi-provider inference”

AI Gateway sits between the service that calls models and the inference platform, so observability and policy apply in one place instead of per provider.

Using a forward proxy can mitigate these challenges. Positioned between the service making inference requests and the inference service platform, it serves as a single point for observability and control. By shifting features such as rate limiting, caching, and error handling to the proxy layer, organizations can apply unified configurations across services and inference service providers.

— Cloudflare, Multi-vendor AI observability and control

When DeepSeek or other providers are routed through the gateway, Cloudflare describes the same three themes: monitor (analytics and logs), control (caching, rate limiting, fallbacks), and optimize (feedback and evaluations).

— Cloudflare, AI Gateway adds DeepSeek as a Provider

Workers AI and third-party models now share one access path: the same AI binding and REST API can target models on Workers AI or supported third-party providers, with gateway features applied on the way through.

Workers AI and AI Gateway now provide a unified path for accessing models and managing inference traffic. Use the same AI binding and REST API to call models hosted on Workers AI or by supported third-party providers, with AI Gateway providing observability, logging, caching, security, and billing controls.

— Cloudflare, Workers AI and AI Gateway unify model access and billing

REST API on api.cloudflare.com: one HTTP surface for every model

Section titled “REST API on api.cloudflare.com: one HTTP surface for every model”

AI Gateway’s newer unified REST API lives on api.cloudflare.com. You call any supported model with the same authentication shape, regardless of whether the model is from OpenAI, Anthropic, Google, or Workers AI.

AI Gateway now uses the AI REST API on api.cloudflare.com. You can call any model — whether from OpenAI, Anthropic, Google, or hosted on Workers AI — through one unified API, using the same endpoints and authentication regardless of provider.

— Cloudflare, Call any AI model through AI Gateway’s new REST API

Which REST paths to use for chat, responses, and Anthropic

Section titled “Which REST paths to use for chat, responses, and Anthropic”

Four endpoints are available on the account AI REST surface:

Endpoint Role
POST /ai/run Universal endpoint for all models and modalities
POST /ai/v1/chat/completions OpenAI SDK–compatible chat
POST /ai/v1/responses OpenAI Responses API–compatible
POST /ai/v1/messages Anthropic SDK–compatible

Gateway features—logging, caching, rate limiting, and guardrails—apply automatically on these calls. With Unified Billing, third-party usage can be billed through Cloudflare without maintaining separate provider API keys for every vendor (see the billing section below).

Example (OpenAI-compatible chat completions on the unified REST API):

curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/v1/chat/completions" \
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"model": "openai/gpt-5.5",
"messages": [{"role": "user", "content": "What is Cloudflare?"}]
}'

Details and Workers AI examples are in REST API.

Default gateway and the cf-aig-gateway-id header

Section titled “Default gateway and the cf-aig-gateway-id header”

Third-party model requests route through your account’s default gateway, created automatically on first use. To force a specific gateway configuration, send the cf-aig-gateway-id header.

For Workers AI through AI Gateway on REST: use the @cf/ model prefix (for example @cf/moonshotai/kimi-k2.6) and set cf-aig-gateway-id to the gateway that should own logging and billing settings. The legacy path POST .../ai/run/@cf/{model} still works; the REST API page documents both styles.

gateway.ai.cloudflare.com: provider-specific and compat URLs

Section titled “gateway.ai.cloudflare.com: provider-specific and compat URLs”

Many guides still route traffic by changing the base URL to https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/..., with the provider segment in the path (for example deepseek/chat/completions or cerebras/chat/completions). You authenticate with the upstream provider’s API key; gateway behaviour is tied to that gateway ID.

DeepSeek example pattern from the changelog:

curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/deepseek/chat/completions \
--header 'content-type: application/json' \
--header 'Authorization: Bearer DEEPSEEK_TOKEN' \
--data '{
"model": "deepseek-chat",
"messages": [{"role": "user", "content": "What is Cloudflare?"}]
}'

— Cloudflare, AI Gateway adds DeepSeek as a Provider

Provider additions such as Cerebras, Cartesia, and ElevenLabs follow the same “update the base URL” model; see AI Gateway adds Cerebras, ElevenLabs, and Cartesia as new providers.

OpenAI Compatible endpoint: switch providers without changing SDK shape

Section titled “OpenAI Compatible endpoint: switch providers without changing SDK shape”

The OpenAI Compatible endpoint keeps request and response formats aligned with OpenAI’s chat completions API so you can swap providers by changing model and apiKey, while pointing the OpenAI client at the gateway compat base URL.

Users can now use an OpenAI Compatible endpoint in AI Gateway to easily switch between providers, while keeping the exact same request and response formats. We’re launching now with the chat completions endpoint, with the embeddings endpoint coming up next.

— Cloudflare, AI Gateway adds OpenAI compatible endpoint

Supported providers listed for this unified compat surface include Anthropic, OpenAI, Groq, Mistral, Cohere, Perplexity, Workers AI, Google AI Studio, Google Vertex AI, xAI, DeepSeek, Cerebras, Baseten, and Parallel—see Unified API (OpenAI compat).

import OpenAI from "openai";
const client = new OpenAI({
apiKey: "YOUR_PROVIDER_API_KEY",
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?" }],
});

The compat endpoint can be combined with the Universal Endpoint so fallbacks across providers still return one standardized format (AI Gateway adds OpenAI compatible endpoint).

The ai-gateway-provider package (v3.0.0) adds AI SDK v6 support for routing multiple providers—including Anthropic, Azure, AWS Bedrock, Google Vertex, and Perplexity—through AI Gateway (Agents SDK and ai-gateway-provider changelog).

Get started with default: first call without creating a gateway

Section titled “Get started with default: first call without creating a gateway”

You can start with gateway ID default; Cloudflare creates a gateway on the first request.

You can now start using AI Gateway with a single API call — no setup required. Use default as your gateway ID, and AI Gateway creates one for you automatically on the first request.

— Cloudflare, Get started with AI Gateway automatically

Create an API token with AI Gateway - Read, AI Gateway - Edit, and Workers AI - Read, then call the compat chat completions URL with cf-aig-authorization and a Workers AI model id, as in Get started with AI Gateway automatically.

Worker Bindings: run, getLog, and patchLog from Workers

Section titled “Worker Bindings: run, getLog, and patchLog from Workers”

Worker binding methods let a Worker talk to AI Gateway without hand-rolling REST auth for every call.

We have released new Workers bindings API methods, allowing you to connect Workers applications to AI Gateway directly. These methods simplify how Workers calls AI services behind your AI Gateway configurations, removing the need to use the REST API and manually authenticate.

— Cloudflare, AI Gateway Introduces New Worker Binding Methods

After you add an AI binding in Wrangler configuration, you can:

  • run — execute universal requests to any AI Gateway provider
  • getLog — retrieve detailed log information
  • patchLog — send feedback and update metadata on a log

Human feedback for evaluations uses the same binding pattern; see Add human feedback using Worker Bindings.

For Workers AI prepaid credits via binding, pass the gateway ID as the third argument to env.AI.run() (Unified Billing).

Realtime WebSockets API: low-latency speech and live models

Section titled “Realtime WebSockets API: low-latency speech and live models”

Realtime WebSockets API keeps a persistent connection for conversational and speech workloads.

This new capability allows developers to establish persistent, low-latency connections between their applications and AI models, enabling natural, real-time conversational AI experiences, including speech-to-speech interactions.

— Cloudflare, AI Gateway launches Realtime WebSockets API

It supports OpenAI’s Realtime API, Google Gemini Live API, and real-time text/speech with Cartesia and ElevenLabs. Connections use wss://gateway.ai.cloudflare.com/v1/<account_id>/<gateway>/openai?model=... with both cf-aig-authorization (Cloudflare) and provider Authorization headers, plus provider-specific headers such as OpenAI-Beta: realtime=v1 (AI Gateway launches Realtime WebSockets API).

Unified Billing: one credit balance for Workers AI and providers

Section titled “Unified Billing: one credit balance for Workers AI and providers”

Unified Billing loads prepaid credits in the dashboard and spends them on Workers AI and supported third-party providers through AI Gateway, with one Cloudflare bill.

Unified Billing allows users to call Workers AI and connect to various AI providers (such as OpenAI, Anthropic, and Google AI Studio) and receive a single Cloudflare bill.

— Cloudflare, Unified Billing

A 5% fee applies when purchasing credits (for example, $100 of credits costs $105). Provider per-token pricing is pass-through without markup. Rare negative balances can be settled against the payment method on file at month start (Unified Billing).

By default, Workers AI uses Standard billing on the account. To charge Workers AI through gateway credits, open the gateway in the dashboard, set Workers AI Billing to Unified billing, and save (Manage gateways). Routed requests then deduct credits in real time (Workers AI and AI Gateway unify model access and billing).

Frontier Workers AI models billed with prepaid credits get 50 requests per minute per account per model, versus 20 under standard Workers AI billing, for models including @cf/moonshotai/kimi-k2.6, @cf/moonshotai/kimi-k2.7-code, and @cf/zai-org/glm-5.2. Prepaid credits can also unlock some frontier models without a Workers Paid plan (Workers AI and AI Gateway unify model access and billing, Workers AI pricing — Pay with AI Gateway credits).

Workers AI behind the gateway is summarised in Workers AI provider usage.

Common mistakes when routing inference through AI Gateway

Section titled “Common mistakes when routing inference through AI Gateway”
  • Wrong host for your integration — SDK compat and provider-path URLs use gateway.ai.cloudflare.com; the unified multi-provider REST API uses api.cloudflare.com with cf-aig-gateway-id when you need a non-default gateway (REST API, Call any AI model through AI Gateway’s new REST API).
  • Expecting custom domains on the new REST API — not supported yet on api.cloudflare.com endpoints (Custom domains).
  • Workers AI without @cf/ or gateway header — gateway-routed Workers AI REST calls need the @cf/ prefix and cf-aig-gateway-id for the gateway whose billing mode you configured (REST API).
  • Unified billing not enabled on the gateway — credits apply only when the gateway’s Workers AI billing setting is Unified billing and requests hit that gateway ID (Manage gateways).
  • Mixing auth headers on WebSockets — realtime connections typically need both Cloudflare (cf-aig-authorization) and provider bearer tokens (AI Gateway launches Realtime WebSockets API).

For ongoing product changes, see the AI Gateway changelog.

  1. Create a Cloudflare API token with AI Gateway - Read, AI Gateway - Edit, and Workers AI - Read (as in Get started with AI Gateway automatically).
  2. Send one test request to default on the OpenAI Compatible URL or to POST /ai/v1/chat/completions on api.cloudflare.com, and confirm a normal model response (REST API).
  3. In the dashboard under AI → AI Gateway, open the gateway that received traffic and confirm logs or analytics for that call (Unified Billing describes the AI Gateway dashboard entry point).
  4. If you use Workers AI credits, verify Workers AI Billing is Unified billing on that gateway and that usage deducts from Credits Available (Manage gateways).
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page does not match your gateway behaviour or the linked Cloudflare docs, email yimasynthetic@gmail.com with the page URL and the exact sentence you think is wrong or unclear.