Skip to content

Commit 3ac62a2

Browse files
authored
[Workers AI, AI Gateway] Document unified billing (#32561)
* [Workers AI] Document unified AI Gateway billing * [AI Gateway] Clarify standard Workers AI billing * [AI Gateway] Update unified billing changelog date
1 parent 1c2598f commit 3ac62a2

12 files changed

Lines changed: 118 additions & 28 deletions

File tree

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
---
2+
title: Workers AI and AI Gateway unify model access and billing
3+
description: Call Workers AI and third-party models through shared APIs, observability, and prepaid billing.
4+
products:
5+
- ai-gateway
6+
- workers-ai
7+
date: 2026-08-07
8+
---
9+
10+
import { TypeScriptExample } from "~/components";
11+
12+
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.
13+
14+
## Unified entrypoints and observability
15+
16+
The [AI binding](/ai-gateway/usage/worker-binding-methods/) supports both Workers AI and third-party models through `env.AI.run()`. The [REST API](/ai-gateway/usage/rest-api/) provides shared `/ai/` endpoints with Cloudflare authentication across providers.
17+
18+
Route a Workers AI request through AI Gateway by specifying a gateway ID. Use `default` to automatically create a gateway on the first authenticated request, or specify an existing gateway to separate applications and workloads:
19+
20+
<TypeScriptExample>
21+
22+
```ts
23+
const response = await env.AI.run(
24+
"@cf/zai-org/glm-5.2",
25+
{
26+
messages: [{ role: "user", content: "What is the capital of France?" }],
27+
},
28+
{
29+
gateway: { id: "default" },
30+
},
31+
);
32+
```
33+
34+
</TypeScriptExample>
35+
36+
Requests routed through AI Gateway can be logged and included in analytics for request volume, errors, latency, token usage, and costs. You can also configure controls such as caching, rate limiting, and request retries on the gateway.
37+
38+
## Unified billing and higher rate limits
39+
40+
You can now use prepaid [AI Gateway credits](/ai-gateway/features/unified-billing/) to pay for Workers AI inference. This provides one credit balance for Workers AI and supported third-party model providers. To use credits for Workers AI, set the gateway's [Workers AI billing setting](/ai-gateway/configuration/manage-gateway/#configure-workers-ai-billing) to **Unified billing**. Workers AI requests routed through that gateway deduct from your credit balance in real time.
41+
42+
Prepaid credits also provide access to the following Workers AI frontier models without requiring the Workers Paid plan. Each frontier Workers AI model has a rate limit of 50 requests per minute per account, per model when billed with AI Gateway credits, compared to 20 requests per minute through standard Workers AI billing:
43+
44+
- [`@cf/moonshotai/kimi-k2.6`](/workers-ai/models/kimi-k2.6/)
45+
- [`@cf/moonshotai/kimi-k2.7-code`](/workers-ai/models/kimi-k2.7-code/)
46+
- [`@cf/zai-org/glm-5.2`](/workers-ai/models/glm-5.2/)
47+
48+
These limits are designed for typical agentic and coding workloads, where requests to frontier models can take longer to complete.
49+
50+
For details, refer to [Workers AI limits](/workers-ai/platform/limits/), [Workers AI pricing](/workers-ai/platform/pricing/), [Unified Billing](/ai-gateway/features/unified-billing/), and the [AI Gateway model catalog](/ai/models/).

‎src/content/docs/ai-gateway/configuration/manage-gateway.mdx‎

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ The request that triggers auto-creation must be authenticated. When using the [R
2424

2525
The auto-created default gateway uses the following settings:
2626

27-
| Setting | Default value |
28-
| -------------- | -------------- |
29-
| Authentication | On |
30-
| Log collection | On |
31-
| Caching | Off (TTL of 0) |
32-
| Rate limiting | Off |
27+
| Setting | Default value |
28+
| ------------------ | ---------------- |
29+
| Authentication | On |
30+
| Log collection | On |
31+
| Caching | Off (TTL of 0) |
32+
| Rate limiting | Off |
33+
| Workers AI billing | Standard billing |
3334

3435
After creation, you can edit the default gateway settings like any other gateway. If you delete the default gateway, sending a new authenticated request to the `default` gateway ID auto-creates it again.
3536

@@ -51,6 +52,20 @@ For more details about what settings are available for editing, refer to [Config
5152

5253
:::
5354

55+
### Configure Workers AI billing
56+
57+
By default, Workers AI requests use **Standard billing**, which charges your Cloudflare account at the end of each billing cycle.
58+
59+
To use prepaid AI Gateway credits for Workers AI requests:
60+
61+
1. [Load credits](/ai-gateway/features/unified-billing/#load-credits) into your Cloudflare account.
62+
2. In the Cloudflare dashboard, go to **AI** > **AI Gateway** and select your gateway.
63+
3. Go to **Settings** and find **Workers AI Billing**.
64+
4. Select **Unified billing**.
65+
5. Select **Save**.
66+
67+
Workers AI requests routed through this gateway will deduct from your AI Gateway credit balance in real time.
68+
5469
## Retry requests
5570

5671
You can configure your gateway to automatically retry failed requests to upstream providers. This is useful when you do not control the client and cannot implement client-side retries or backoff logic.

‎src/content/docs/ai-gateway/features/unified-billing.mdx‎

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ products:
1313

1414
import { DashButton, Render, TabItem, Tabs } from "~/components";
1515

16-
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.
16+
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. 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.
1717

1818
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.
1919

@@ -25,6 +25,7 @@ In rare instances, your credit balance may go negative. If this happens, Cloudfl
2525

2626
- Ensure your Cloudflare account has [sufficient credits loaded](#load-credits).
2727
- Ensure you have [authenticated](/ai-gateway/configuration/authentication/) your AI Gateway.
28+
- To use credits for Workers AI, set your gateway's **Workers AI Billing** setting to **Unified billing**.
2829

2930
## Load credits
3031

@@ -73,9 +74,7 @@ The `cf-aig-byok-alias` header selects a non-default alias only on [direct provi
7374

7475
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.
7576

76-
:::note
77-
Workers AI models (models prefixed with `@cf/`) routed through AI Gateway are not charged via Unified Billing. These models are billed through [Workers AI pricing](/workers-ai/platform/pricing/) instead. Unified Billing only applies to third-party provider models (such as OpenAI, Anthropic, and Google AI Studio).
78-
:::
77+
To use credits for Workers AI, [configure the gateway's Workers AI billing setting](/ai-gateway/configuration/manage-gateway/#configure-workers-ai-billing) as **Unified billing**. Workers AI requests routed through that gateway deduct from your prepaid credit balance in real time. In the AI binding, include the gateway ID in the third argument to `env.AI.run()`. For REST API requests, include the `cf-aig-gateway-id` header. Prepaid credits provide access to Workers AI models that otherwise require the Workers Paid plan and provide [higher rate limits for frontier models](/workers-ai/platform/limits/#frontier-models).
7978

8079
### AI binding
8180

‎src/content/docs/ai-gateway/get-started.mdx‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_
4949
}'
5050
```
5151

52+
The `cf-aig-gateway-id: default` header routes this Workers AI request through your account's default gateway. If the gateway does not exist, AI Gateway creates it on the first authenticated request. Routing through the gateway provides unified logging, analytics, caching, rate limiting, and security controls. The auto-created gateway uses **Standard billing** by default. To pay with prepaid AI Gateway credits, [set its Workers AI billing setting to **Unified billing**](/ai-gateway/configuration/manage-gateway/#configure-workers-ai-billing).
53+
5254
:::note
5355
For third-party models, you do not need to specify a gateway — AI Gateway uses `default` as the gateway ID and automatically creates it on the first authenticated request. Workers AI requests always require the `cf-aig-gateway-id` header. For more details, refer to [Default gateway](/ai-gateway/configuration/manage-gateway/#default-gateway).
5456
:::
@@ -65,7 +67,7 @@ You can also create gateways manually with a custom name and configuration throu
6567

6668
Authenticate with your upstream AI provider using one of the following options:
6769

68-
- **Unified Billing:** Use the AI Gateway billing to pay for and authenticate your inference requests. Refer to [Unified Billing](/ai-gateway/features/unified-billing/).
70+
- **Unified Billing:** Use prepaid AI Gateway credits for Workers AI and supported third-party model providers. Refer to [Unified Billing](/ai-gateway/features/unified-billing/).
6971
- **BYOK (Store Keys):** Store your own provider API Keys with Cloudflare, and AI Gateway will include them at runtime. Refer to [BYOK](/ai-gateway/configuration/bring-your-own-keys/).
7072
- **Request headers:** Include your provider API Key in the request headers as you normally would (for example, `Authorization: Bearer <OPENAI_API_KEY>`).
7173

‎src/content/docs/ai-gateway/usage/providers/workersai.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ products:
1212

1313
import { TypeScriptExample } from "~/components";
1414

15-
Use AI Gateway for analytics, caching, and security on requests to [Workers AI](/workers-ai/).
15+
Use AI Gateway as a unified control layer for [Workers AI](/workers-ai/) requests, with analytics, logging, caching, security, and prepaid billing. To use prepaid [AI Gateway credits](/ai-gateway/features/unified-billing/), set the gateway's [Workers AI billing setting](/ai-gateway/configuration/manage-gateway/#configure-workers-ai-billing) to **Unified billing**. Requests to frontier models billed with prepaid credits receive [higher rate limits](/workers-ai/platform/limits/#frontier-models).
1616

1717
## REST API
1818

‎src/content/docs/ai-gateway/usage/rest-api.mdx‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ products:
1212

1313
The REST API lets you call any model — whether hosted on Cloudflare or by a third-party provider like OpenAI, Anthropic, or Google — through the same Cloudflare API, with all AI Gateway features — logging, caching, rate limiting, and more — applied automatically.
1414

15-
No provider SDKs or API keys are needed. Authentication and billing are handled through your Cloudflare account. Third-party models are billed via [Unified Billing](/ai-gateway/features/unified-billing/), while Workers AI models follow [Workers AI pricing](/workers-ai/platform/pricing/).
15+
No provider SDKs or API keys are needed. Authentication and billing are handled through your Cloudflare account. Third-party models are billed via [Unified Billing](/ai-gateway/features/unified-billing/). Workers AI models can use prepaid AI Gateway credits or [Workers AI billing](/workers-ai/platform/pricing/).
1616

1717
## Endpoints
1818

@@ -38,7 +38,7 @@ All `/accounts/{account_id}/ai/*` endpoints require the Workers AI permission. T
3838
The `AI Gateway` permissions apply to the `/accounts/{account_id}/ai-gateway/*` endpoints, which manage gateway configuration, logs, and routes.
3939

4040
:::note
41-
Ensure your Cloudflare account has [sufficient credits loaded](/ai-gateway/features/unified-billing/#load-credits) before calling third-party models.
41+
Ensure your Cloudflare account has [sufficient credits loaded](/ai-gateway/features/unified-billing/#load-credits) before calling third-party models or using prepaid credits for Workers AI.
4242
:::
4343

4444
## Model naming
@@ -109,6 +109,7 @@ The existing Workers AI endpoint with the model ID in the URL path also continue
109109
# and `wrangler auth token` to get an auth token to replace $CLOUDFLARE_API_TOKEN.
110110
curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_ID/ai/run/@cf/moonshotai/kimi-k2.6" \
111111
--header "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
112+
--header "cf-aig-gateway-id: default" \
112113
--header "Content-Type: application/json" \
113114
--data '{
114115
"messages": [
@@ -120,6 +121,8 @@ curl -X POST "https://api.cloudflare.com/client/v4/accounts/$CLOUDFLARE_ACCOUNT_
120121
}'
121122
```
122123

124+
To use prepaid AI Gateway credits for Workers AI, use the model-in-path endpoint shown above, set the gateway's [Workers AI billing setting](/ai-gateway/configuration/manage-gateway/#configure-workers-ai-billing) to **Unified billing**, and include its ID in the `cf-aig-gateway-id` header. Requests to frontier models billed with prepaid credits receive [higher rate limits](/workers-ai/platform/limits/#frontier-models).
125+
123126
## `/ai/v1/chat/completions` — OpenAI compatible
124127

125128
Uses the standard OpenAI chat completions format. The `model` field uses the same `author/model` naming. This endpoint is compatible with the OpenAI SDK and other OpenAI-compatible clients.

‎src/content/docs/ai-gateway/usage/worker-binding-methods.mdx‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ const resp = await env.AI.run(
6464

6565
</TypeScriptExample>
6666

67+
To use prepaid [AI Gateway credits](/ai-gateway/features/unified-billing/), set the gateway's [Workers AI billing setting](/ai-gateway/configuration/manage-gateway/#configure-workers-ai-billing) to **Unified billing** and specify that gateway in the binding request. Prepaid credits provide access to Workers AI models that otherwise require the Workers Paid plan and provide [higher rate limits for frontier models](/workers-ai/platform/limits/#frontier-models).
68+
6769
**Third-party model:**
6870

6971
<TypeScriptExample>
@@ -96,14 +98,14 @@ Browse available models in the [model catalog](/ai/models/).
9698

9799
The third argument to `env.AI.run()` accepts a `gateway` object with the following parameters:
98100

99-
| Parameter | Type | Default | Description |
100-
| ------------ | --------- | ---------- | ------------------------------------------------------------------------------------------------ |
101+
| Parameter | Type | Default | Description |
102+
| ------------ | --------- | ---------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
101103
| `id` | `string` | _required_ | Name of your [AI Gateway](/ai-gateway/get-started/). Must be in the same account as your Worker. Use `"default"` to automatically create a gateway on the first authenticated request. Refer to [Default gateway](/ai-gateway/configuration/manage-gateway/#default-gateway) for details. |
102-
| `skipCache` | `boolean` | `false` | Skip the [cache](/ai-gateway/features/caching/) for this request. |
103-
| `cacheTtl` | `number` || [Cache TTL](/ai-gateway/features/caching/) in seconds. |
104-
| `cacheKey` | `string` || Custom [cache key](/ai-gateway/features/caching/) for this request. |
105-
| `collectLog` | `boolean` || Whether to [collect logs](/ai-gateway/observability/logging/) for this request. |
106-
| `metadata` | `object` || [Custom metadata](/ai-gateway/observability/custom-metadata/) to attach to the log entry. |
104+
| `skipCache` | `boolean` | `false` | Skip the [cache](/ai-gateway/features/caching/) for this request. |
105+
| `cacheTtl` | `number` || [Cache TTL](/ai-gateway/features/caching/) in seconds. |
106+
| `cacheKey` | `string` || Custom [cache key](/ai-gateway/features/caching/) for this request. |
107+
| `collectLog` | `boolean` || Whether to [collect logs](/ai-gateway/observability/logging/) for this request. |
108+
| `metadata` | `object` || [Custom metadata](/ai-gateway/observability/custom-metadata/) to attach to the log entry. |
107109

108110
## `env.AI.aiGatewayLogId`
109111

@@ -197,5 +199,3 @@ const anthropic = createAnthropic({
197199
baseURL: await env.AI.gateway("my-gateway").getUrl("anthropic"),
198200
});
199201
```
200-
201-

‎src/content/docs/workers-ai/platform/ai-gateway.mdx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
pcx_content_type: navigation
33
title: AI Gateway
4-
description: Use AI Gateway to manage, monitor, and cache your Workers AI requests.
4+
description: Route Workers AI through a unified control layer for observability, billing, caching, security, and routing.
55
external_link: /ai-gateway/
66
sidebar:
77
order: 5

‎src/content/docs/workers-ai/platform/limits.mdx‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,18 @@ Rate limits are default per task type, with some per-model limits defined as fol
5959
- [@cf/qwen/qwen1.5-14b-chat-awq](/workers-ai/models/qwen1.5-14b-chat-awq/) is 150 requests per minute
6060
- [@cf/tinyllama/tinyllama-1.1b-chat-v1.0](/workers-ai/models/tinyllama-1.1b-chat-v1.0/) is 720 requests per minute
6161

62+
#### Frontier models
63+
64+
The following limits apply per account, per model:
65+
66+
| Model | Standard Workers AI billing | Prepaid AI Gateway credits |
67+
| ------------------------------------------------------------------- | --------------------------- | -------------------------- |
68+
| [@cf/moonshotai/kimi-k2.6](/workers-ai/models/kimi-k2.6/) | 20 requests per minute | 50 requests per minute |
69+
| [@cf/moonshotai/kimi-k2.7-code](/workers-ai/models/kimi-k2.7-code/) | 20 requests per minute | 50 requests per minute |
70+
| [@cf/zai-org/glm-5.2](/workers-ai/models/glm-5.2/) | 20 requests per minute | 50 requests per minute |
71+
72+
To receive the elevated limit, load [prepaid AI Gateway credits](/ai-gateway/features/unified-billing/) and set the gateway's [Workers AI billing setting](/ai-gateway/configuration/manage-gateway/#configure-workers-ai-billing) to **Unified billing**. These limits are designed for typical agentic and coding workloads, where requests to frontier models can take longer to complete.
73+
6274
### [Text-to-Image](/workers-ai/models/)
6375

6476
- 720 requests per minute

0 commit comments

Comments
 (0)