Unified Billing
Unified Billing allows users to connect to various AI providers (such as OpenAI, Anthropic, and Google AI Studio) and receive a single Cloudflare bill. To use Unified Billing, you must purchase and load credits into your Cloudflare account in the Cloudflare dashboard, which you can then spend with AI Gateway.
A 5% fee is applied to all credits purchased through Unified Billing. For example, a $100 credit purchase will result in a $105 charge. Inference pricing from providers is passed through with no markup — you pay the same per-token rates as you would directly with the provider.
- Ensure your Cloudflare account has sufficient credits loaded.
- Ensure you have authenticated your AI Gateway.
To load credits for AI Gateway:
-
In the Cloudflare dashboard, go to the AI Gateway page.
Go to AI GatewayThe Credits Available card on the top right shows how many AI gateway credits you have on your account currently.
-
In Credits Available, select Manage.
-
If your account does not have an available payment method, AI Gateway will prompt you to add a payment method to purchase credits. Add a payment method.
-
Select Top-up credits.
-
Add the amount of credits you want to purchase, then select Confirm and pay.
You can configure AI Gateway to automatically replenish your credits when they fall below a certain threshold. To configure auto top-up:
-
In the Cloudflare dashboard, go to the AI Gateway page.
Go to AI Gateway -
In Credits Available, select Manage.
-
Select Setup auto top-up credits.
-
Choose a threshold and a recharge amount for auto top-up.
When your balance falls below the set threshold, AI Gateway will automatically apply the auto top-up amount to your account.
Unified Billing works in two ways: through the AI binding or through the HTTP API. Both deduct credits from your account automatically without requiring provider API keys.
Call any model listed in the model catalog using env.AI.run(). This includes both Workers AI models and third-party models from providers like OpenAI, Anthropic, and Google.
const resp = await env.AI.run( "openai/gpt-4.1-mini", { messages: [{ role: "user", content: "What is Cloudflare?" }], }, { gateway: { id: "my-gateway" }, },);Refer to the binding reference for the full API surface.
Call a supported provider through the AI Gateway REST API without passing a provider API key.
Use the Cloudflare API to call third-party models. Pass your Cloudflare API token in the Authorization header:
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-4.1-mini", "messages": [{"role": "user", "content": "What is Cloudflare?"}] }'Refer to REST API for more details on all available endpoints.
You can also call providers directly through provider-native endpoints using the cf-aig-authorization header to authenticate:
The HTTP API supports the following providers:
Set spend limits to prevent unexpected charges on your loaded credits. You can define daily, weekly, or monthly limits. When a limit is reached, the AI Gateway automatically stops processing requests until the period resets or you increase the limit.
Zero Data Retention (ZDR) routes Unified Billing traffic through provider endpoints that do not retain prompts or responses. Enable it with the gateway-level zdr setting, which maps to ZDR-capable upstream provider configurations. This setting only applies to Unified Billing requests that use Cloudflare-managed credentials. It does not apply to BYOK or other AI Gateway requests.
ZDR does not control AI Gateway logging. To disable request/response logging in AI Gateway, update the logging settings separately in Logging.
ZDR is currently supported for:
If ZDR is enabled for a provider that does not support it, AI Gateway falls back to the standard (non-ZDR) Unified Billing configuration.
To set ZDR as the default for Unified Billing in the dashboard:
- Log into the Cloudflare dashboard ↗ and select your account.
- Go to AI > AI Gateway.
- Select your gateway.
- Go to Settings and toggle Zero Data Retention (ZDR).
To set ZDR as the default for Unified Billing using the API:
- Create an API token with the following permissions:
AI Gateway - ReadAI Gateway - Edit
- Get your Account ID.
- Send a
PUTrequest to update the gateway and includezdr: trueorzdr: falsein the request body.
Use the cf-aig-zdr header to override the gateway default for a single Unified Billing request. Set it to true to force ZDR, or false to disable ZDR for the request.
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" \ --header "cf-aig-zdr: true" \ --data '{ "model": "openai/gpt-4.1-mini", "messages": [ { "role": "user", "content": "Explain Zero Data Retention." } ] }'