Skip to content

Commit 37bb2ae

Browse files
[AI Gateway] Add setting to require provider credentials (#33229)
* AIG-1532: Document gateway-level BYOK requirement * AIG-1532: Clarify BYOK-only billing behavior * AIG-1532: Add BYOK-only changelog * [AI Gateway] Address review feedback * [AI Gateway] Clarify BYOK documentation * [AI Gateway] Refine BYOK headings
1 parent 90fd802 commit 37bb2ae

5 files changed

Lines changed: 66 additions & 8 deletions

File tree

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
---
2+
title: Prevent Unified Billing fallback for BYOK third-party providers
3+
description: Prevent third-party provider requests from falling back to Unified Billing when provider credentials are unavailable.
4+
date: 2026-09-14
5+
---
6+
7+
AI Gateway can now require credentials for third-party provider requests. Credentials must accompany the request or be stored on the gateway. This setting prevents fallback to Unified Billing with Cloudflare-managed credentials.
8+
9+
Turn on **Require provider credentials** in your gateway settings. To use the API, set `byok_only` to `true` in the request body of a [`PUT` request to update the gateway](/api/resources/ai_gateway/methods/update/):
10+
11+
```json
12+
{
13+
"byok_only": true
14+
}
15+
```
16+
17+
To require provider credentials for one third-party request, set the `cf-aig-no-wholesale` header to `true`. This header cannot relax the gateway setting.
18+
19+
Requests without applicable credentials then return an HTTP `400` response. Workers AI requests remain allowed, and the setting does not change their configured billing mode.
20+
21+
For configuration details and request-level controls, refer to [Prevent Unified Billing fallback for BYOK third-party providers](/ai-gateway/features/unified-billing/#prevent-unified-billing-fallback-for-byok-third-party-providers).

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

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ 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 |
33-
| Workers AI billing | Standard billing |
27+
| Setting | Default value |
28+
| ---------------------------- | ---------------- |
29+
| Authentication | On |
30+
| Log collection | On |
31+
| Caching | Off (TTL of 0) |
32+
| Rate limiting | Off |
33+
| Require provider credentials | Off |
34+
| Workers AI billing | Standard billing |
3435

3536
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.
3637

@@ -66,6 +67,10 @@ To use prepaid AI Gateway credits for Workers AI requests:
6667

6768
Workers AI requests routed through this gateway will deduct from your AI Gateway credit balance in real time.
6869

70+
### Prevent Unified Billing fallback for BYOK third-party providers
71+
72+
To prevent Unified Billing fallback for third-party provider requests, turn on **Require provider credentials**. Refer to [Prevent Unified Billing fallback for BYOK third-party providers](/ai-gateway/features/unified-billing/#prevent-unified-billing-fallback-for-byok-third-party-providers) for dashboard and API instructions.
73+
6974
## Retry requests
7075

7176
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: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ products:
1111
- ai-gateway
1212
---
1313

14-
import { DashButton, Render, TabItem, Tabs } from "~/components";
14+
import { DashButton, Render, Steps, TabItem, Tabs } from "~/components";
1515

1616
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

@@ -70,6 +70,32 @@ On requests routed through Unified Billing endpoints (for example, `env.AI.run()
7070
The `cf-aig-byok-alias` header selects a non-default alias only on [direct provider-passthrough](/ai-gateway/usage/providers/) requests.
7171
:::
7272

73+
## Prevent Unified Billing fallback for BYOK third-party providers
74+
75+
Turn on **Require provider credentials** to prevent Unified Billing fallback for third-party providers. Third-party provider requests must use credentials supplied with the request or stored on the gateway. Requests without applicable credentials return an HTTP `400` response instead of using Cloudflare-managed credentials.
76+
77+
<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">
78+
79+
<Steps>
80+
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/) and go to **AI** > **AI Gateway**.
81+
82+
<DashButton url="/?to=/:account/ai/ai-gateway" />
83+
84+
2. Select your gateway.
85+
3. Go to **Settings** and turn on **Require provider credentials**.
86+
4. Confirm the change.
87+
</Steps>
88+
89+
</TabItem> <TabItem label="API">
90+
91+
Send a [`PUT` request](/api/resources/ai_gateway/methods/update/) to update the gateway. Include `byok_only: true` in the request body.
92+
93+
</TabItem> </Tabs>
94+
95+
To require provider credentials for one third-party provider request, set the `cf-aig-no-wholesale` header to `true`. This header can prevent Unified Billing fallback but cannot relax the gateway setting. If **Require provider credentials** is on, setting the header to `false` has no effect.
96+
97+
Workers AI requests do not use provider credentials. This setting does not block these requests or change the gateway's configured Workers AI billing mode.
98+
7399
## Use Unified Billing
74100

75101
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.

src/content/docs/ai-gateway/glossary.mdx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,5 @@ Settings in AI Gateway can be configured at two levels: **Request** and **Gatewa
2424
Act as the default if no headers are set at the request level.
2525

2626
This hierarchy ensures consistent behavior, prioritizing the most specific configurations. Use request-level headers for fine-tuned control, and gateway settings for general defaults.
27+
28+
Some restrictive settings are additive. The `cf-aig-no-wholesale` header can require provider credentials for a third-party provider request, but it cannot turn off **Require provider credentials** when that gateway setting is on.

src/content/glossary/ai-gateway.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ entries:
6161
general_definition: |-
6262
A response header returned when a [DLP policy](/ai-gateway/features/dlp/set-up-dlp/#dlp-response-header) matches a request or response. Contains JSON with the action taken (Flag or Block), matched policy IDs, matched profile IDs, and detection entry IDs.
6363
64+
- term: cf-aig-no-wholesale
65+
general_definition: |-
66+
Prevents [Unified Billing fallback](/ai-gateway/features/unified-billing/#prevent-unified-billing-fallback-for-byok-third-party-providers) for a third-party provider request when set to `true`. The request must use provider credentials supplied with the request or stored on the gateway.
67+
6468
# Deprecated headers
6569
- term: cf-cache-ttl
6670
general_definition: |-

0 commit comments

Comments
 (0)