Skip to content

Commit ab409ed

Browse files
committed
feat: improve aig getting started, fix redirects
1 parent 68077f9 commit ab409ed

File tree

9 files changed

+71
-163
lines changed

9 files changed

+71
-163
lines changed

public/__redirects

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,11 @@
163163
/ai-gateway/integration/vercel-ai-sdk/ /ai-gateway/integrations/vercel-ai-sdk/ 301
164164
/ai-gateway/integration/aig-workers-ai-binding/ /ai-gateway/integrations/aig-workers-ai-binding/ 301
165165
/ai-gateway/integration/ /ai-gateway/integrations/ 301
166-
/ai-gateway/providers/open-router/ /ai-gateway/providers/openrouter/ 301
167-
/ai-gateway/providers/universal/ /ai-gateway/universal/ 301
168-
/ai-gateway/configuration/websockets-api/ /ai-gateway/websockets-api/ 301
169-
/ai-gateway/configuration/websockets-api/non-realtime-api/ /ai-gateway/websockets-api/non-realtime-api/ 301
170-
/ai-gateway/configuration/websockets-api/realtime-api/ /ai-gateway/websockets-api/realtime-api/ 301
166+
/ai-gateway/providers/open-router/ /ai-gateway/usage/providers/openrouter/ 301
167+
/ai-gateway/providers/universal/ /ai-gateway/usage/universal/ 301
168+
/ai-gateway/configuration/websockets-api/ /ai-gateway/usage/websockets-api/ 301
169+
/ai-gateway/configuration/websockets-api/non-realtime-api/ /ai-gateway/usage/websockets-api/non-realtime-api/ 301
170+
/ai-gateway/configuration/websockets-api/realtime-api/ /ai-gateway/usage/websockets-api/realtime-api/ 301
171171
/ai-gateway/configuration/caching/ /ai-gateway/features/caching/ 301
172172
/ai-gateway/configuration/rate-limiting/ /ai-gateway/features/rate-limiting/ 301
173173
/ai-gateway/configuration/custom-metadata/ /ai-gateway/observability/custom-metadata/ 301

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: configuration
3-
title: Authentication
3+
title: Authenticated Gateway
44
sidebar:
55
order: 7
66
head: []

src/content/docs/ai-gateway/configuration/bring-your-own-keys.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,8 @@ The keys are stored securely with [Secret Store](/secrets-store/) and allows for
2222

2323
### Prerequisites
2424

25-
- An active Cloudflare account with AI Gateway enabled
26-
- Valid API keys for the AI providers you want to use
27-
- Appropriate permissions to manage AI Gateway settings
25+
- Ensure your gateway is [authenticated](/ai-gateway/configuration/authentication/)
26+
- Appropriate permissions to create and deploy secrets on Secret Store
2827

2928
### Configure API keys
3029

@@ -44,7 +43,7 @@ The keys are stored securely with [Secret Store](/secrets-store/) and allows for
4443
Once you've configured your API keys in the dashboard:
4544

4645
1. **Remove API keys from your code**: Delete any hardcoded API keys or environment variables
47-
2. **Update request headers**: Remove authorization headers from your requests
46+
2. **Update request headers**: Remove provider authorization headers from your requests, you still need to pass `cf-aig-authorization`
4847
3. **Test your integration**: Verify that requests work without including API keys
4948

5049
## Example

src/content/docs/ai-gateway/features/dynamic-routing/index.mdx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ sidebar:
1010

1111
import { CardGrid, LinkTitleCard, YouTube } from "~/components";
1212

13+
:::caution
14+
Dynamic routing is in closed beta. Request for access
15+
:::
16+
1317
## Introduction
1418

1519
Dynamic routing enables you to create request routing flows through a **visual interface** or a **JSON-based configuration**. Instead of hard-coding a single model, with Dynamic Routing you compose a small flow that evaluates conditions, enforces quotas, and chooses models with fallbacks. You can iterate without touching application code—publish a new route version and you’re done. With dynamic routing, you can easily implement advanced use cases such as

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

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,86 +13,82 @@ import {
1313
Render,
1414
TabItem,
1515
Tabs,
16+
Badge,
1617
} from "~/components";
1718

18-
In this guide, you will learn how to create your first AI Gateway. You can create multiple gateways to control different applications.
19+
In this guide, you will learn how to create and use your first AI Gateway.
1920

20-
## Prerequisites
21+
<Render file="create-gateway" />
2122

22-
Before you get started, you need a Cloudflare account.
23+
### Authenticated gateway
2324

24-
<LinkButton variant="primary" href="https://dash.cloudflare.com/sign-up">
25-
Sign up
26-
</LinkButton>
25+
When you enable authentication on gateway each request is required to include a valid cloudflare token, adding an extra layer of security. We recommend using an authenticated gateway when storing logs to prevent unauthorized access and protect against invalid requests that can inflate log storage usage and make it harder to find the data you need. [Learn more](/ai-gateway/configuration/authentication/).
2726

28-
## Create gateway
27+
## Provider Authentication
2928

30-
Then, create a new AI Gateway.
29+
Authenticate with your upstream provider using one of the following options:
3130

32-
<Render file="create-gateway" />
31+
- **BYOK (Store Keys):** Store your credentials in Cloudflare and AI Gateway will include them at runtime. See [BYOK](/ai-gateway/configuration/bring-your-own-keys/).
32+
- **Request headers:** Include your provider key in the request headers as you normally would (e.g., `Authorization: Bearer <PROVIDER_API_KEY>`).
33+
34+
## Integration Options
3335

34-
## Choosing gateway authentication
36+
### Unified API (OpenAI-Compatible) Endpoint
3537

36-
When setting up a new gateway, you can choose between an authenticated and unauthenticated gateway. Enabling an authenticated gateway requires each request to include a valid authorization token, adding an extra layer of security. We recommend using an authenticated gateway when storing logs to prevent unauthorized access and protect against invalid requests that can inflate log storage usage and make it harder to find the data you need. Learn more about setting up an [Authenticated Gateway](/ai-gateway/configuration/authentication/).
38+
<Badge text="recommended" variant="success" size="small" />
39+
<br />
40+
<br />
41+
42+
The easiest way to get started with AI Gateway is through our OpenAI-compatible `/chat/completions` endpoint. This allows you to use existing OpenAI SDKs and tools with minimal code changes while gaining access to multiple AI providers.
43+
44+
```txt
45+
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions
46+
```
3747

38-
## Send a request
48+
**Key benefits:**
3949

40-
#### Chat completions endpoint
50+
- Drop-in replacement for OpenAI API
51+
- Works with existing OpenAI SDKs and other OpenAI compliant clients
52+
- Switch between providers by changing the `model` parameter
53+
- Dynamic Routing - Define complex routing scenarios requiring conditional logic, conduct A/B tests, set rate / budget limits etc
4154

42-
<Tabs syncKey="aiGatewayGetStarted">
43-
<TabItem label="OpenAI SDK">
55+
#### Example:
4456

45-
```js
57+
```javascript
4658
import OpenAI from "openai";
59+
4760
const client = new OpenAI({
48-
apiKey: "YOUR_PROVIDER_API_KEY", // Provider API key
49-
// NOTE: the OpenAI client automatically adds /chat/completions to the end of the URL, you should not add it yourself.
61+
apiKey: "YOUR_PROVIDER_API_KEY",
5062
baseURL:
5163
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat",
5264
});
5365

66+
// Use different providers by changing the model parameter
5467
const response = await client.chat.completions.create({
55-
model: "google-ai-studio/gemini-2.0-flash",
56-
messages: [{ role: "user", content: "What is Cloudflare?" }],
68+
model: "google-ai-studio/gemini-2.0-flash", // or "openai/gpt-4o", "anthropic/claude-3-haiku"
69+
messages: [{ role: "user", content: "Hello, world!" }],
5770
});
58-
console.log(response.choices[0].message.content);
5971
```
6072

61-
</TabItem>
62-
<TabItem label="AI Gateway API">
63-
```bash
64-
curl -X POST https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions \
65-
--header 'Authorization: Bearer {GOOGLE_GENERATIVE_AI_API_KEY}' \
66-
--header 'Content-Type: application/json' \
67-
--data '{
68-
"model": "google-ai-studio/gemini-2.5-flash",
69-
"messages": [
70-
{
71-
"role": "user",
72-
"content": "What is Cloudflare?"
73-
}
74-
]
75-
}'
76-
````
77-
78-
</TabItem>
79-
</Tabs>
80-
81-
There are multiple other ways to send a request to AI Gateway check out the [usage](/ai-gateway/usage/) section for more details.
73+
[Learn more about OpenAI compatibility →](/ai-gateway/usage/chat-completion/)
8274

83-
## View analytics
75+
### Provider-Specific Endpoints
8476

85-
Now that you have sent your first request to AI Gateway, you can view analytics for requests going through your gateway.
77+
For direct integration with specific AI providers, use dedicated endpoints that maintain the original provider's API schema while adding AI Gateway features.
8678

87-
<Render file="analytics-overview" /> <br />
88-
89-
<Render file="analytics-dashboard" />
90-
91-
:::note[Note]
79+
```txt
80+
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/{provider}
81+
```
9282

93-
The cost metric is an estimation based on the number of tokens sent and received in requests. While this metric can help you monitor and predict cost trends, refer to your provider's dashboard for the most accurate cost details.
83+
**Available providers:**
9484

95-
:::
85+
- [OpenAI](/ai-gateway/usage/providers/openai/) - GPT models and embeddings
86+
- [Anthropic](/ai-gateway/usage/providers/anthropic/) - Claude models
87+
- [Google AI Studio](/ai-gateway/usage/providers/google-ai-studio/) - Gemini models
88+
- [Workers AI](/ai-gateway/usage/providers/workersai/) - Cloudflare's inference platform
89+
- [AWS Bedrock](/ai-gateway/usage/providers/bedrock/) - Amazon's managed AI service
90+
- [Azure OpenAI](/ai-gateway/usage/providers/azureopenai/) - Microsoft's OpenAI service
91+
- [and more...](/ai-gateway/usage/providers/)
9692

9793
## Next steps
9894

src/content/docs/ai-gateway/usage/chat-completion.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
title: OpenAI Compatibility
2+
title: Unified API (OpenAI compat)
33
pcx_content_type: reference
44
tags:
55
- AI

src/content/docs/ai-gateway/usage/index.mdx

Lines changed: 3 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -3,101 +3,8 @@ title: Using AI Gateway
33
pcx_content_type: get-started
44
sidebar:
55
order: 3
6+
group:
7+
hideIndex: true
68
---
79

8-
import { Render, Badge } from "~/components";
9-
10-
AI Gateway provides multiple ways to integrate with AI providers, offering flexibility and advanced features like caching, analytics, rate limiting, and fallbacks. Choose the integration method that best fits your needs.
11-
12-
## Integration Options
13-
14-
### OpenAI-Compatible Endpoint <Badge text="recommended" variant="success" size="small" />
15-
16-
The easiest way to get started with AI Gateway is through our OpenAI-compatible `/chat/completions` endpoint. This allows you to use existing OpenAI SDKs and tools with minimal code changes while gaining access to multiple AI providers.
17-
18-
```txt
19-
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat/chat/completions
20-
```
21-
22-
**Key benefits:**
23-
24-
- Drop-in replacement for OpenAI API
25-
- Works with existing OpenAI SDKs and other OpenAI compliant clients
26-
- Switch between providers by changing the `model` parameter
27-
- No schema modifications required
28-
- Dynamic Routing - Define complex routing scenarios requiring conditional logic, conduct A/B tests, set rate / budget limits etc
29-
30-
[Learn more about OpenAI compatibility →](/ai-gateway/usage/chat-completion/)
31-
32-
### Provider-Specific Endpoints
33-
34-
For direct integration with specific AI providers, use dedicated endpoints that maintain the original provider's API schema while adding AI Gateway features.
35-
36-
```txt
37-
https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/{provider}
38-
```
39-
40-
**Available providers:**
41-
42-
- [OpenAI](/ai-gateway/usage/providers/openai/) - GPT models and embeddings
43-
- [Anthropic](/ai-gateway/usage/providers/anthropic/) - Claude models
44-
- [Google AI Studio](/ai-gateway/usage/providers/google-ai-studio/) - Gemini models
45-
- [Workers AI](/ai-gateway/usage/providers/workersai/) - Cloudflare's inference platform
46-
- [AWS Bedrock](/ai-gateway/usage/providers/bedrock/) - Amazon's managed AI service
47-
- [Azure OpenAI](/ai-gateway/usage/providers/azureopenai/) - Microsoft's OpenAI service
48-
- [and more...](/ai-gateway/usage/providers/)
49-
50-
### WebSockets API <Badge text="beta" variant="tip" size="small" />
51-
52-
For real-time applications requiring persistent connections, AI Gateway offers WebSockets support. This enables streaming responses and continuous communication with AI providers.
53-
54-
```txt
55-
wss://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/
56-
```
57-
58-
**Key benefits:**
59-
60-
- Single persistent connection
61-
- Real-time streaming responses
62-
- Support for providers without native WebSocket support
63-
- Reduced connection overhead
64-
65-
[Learn more about WebSockets API →](/ai-gateway/usage/websockets-api/)
66-
67-
## Quick Start Examples
68-
69-
### Using OpenAI SDK with Multiple Providers
70-
71-
```javascript
72-
import OpenAI from "openai";
73-
74-
const client = new OpenAI({
75-
apiKey: "YOUR_PROVIDER_API_KEY",
76-
baseURL:
77-
"https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/compat",
78-
});
79-
80-
// Use different providers by changing the model parameter
81-
const response = await client.chat.completions.create({
82-
model: "google-ai-studio/gemini-2.0-flash", // or "openai/gpt-4o", "anthropic/claude-3-haiku"
83-
messages: [{ role: "user", content: "Hello, world!" }],
84-
});
85-
```
86-
87-
## Choosing the Right Integration
88-
89-
| Use Case | Recommended Approach |
90-
| ------------------------------- | --------------------------- |
91-
| **Getting started quickly** | OpenAI-Compatible Endpoint |
92-
| **Existing OpenAI integration** | OpenAI-Compatible Endpoint |
93-
| **Provider-specific features** | Provider-Specific Endpoints |
94-
| **Real-time/streaming apps** | WebSockets API |
95-
96-
## Next Steps
97-
98-
1. **[Set up your first gateway](/ai-gateway/get-started/)** if you haven't already
99-
2. **Choose your integration method** based on your requirements
100-
3. **Configure advanced features** like [caching](/ai-gateway/features/caching/), [rate limiting](/ai-gateway/features/rate-limiting/), and [analytics](/ai-gateway/observability/)
101-
4. **Explore provider-specific documentation** for detailed implementation guides
102-
103-
For more advanced configuration options, see the [Configuration](/ai-gateway/configuration/) section.
10+
##

src/content/docs/ai-gateway/usage/providers/index.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
22
pcx_content_type: navigation
3-
title: Model providers
3+
title: Provider specific
44
sidebar:
55
group:
66
hideIndex: true

src/content/partials/ai-gateway/create-gateway.mdx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
{}
33
---
44

5-
import { TabItem, Tabs } from "~/components";
5+
import { TabItem, Tabs, LinkButton } from "~/components";
66

7-
<Tabs syncKey="dashPlusAPI"> <TabItem label="Dashboard">
7+
<Tabs syncKey="dashPlusAPI">
8+
<TabItem label="Dashboard">
89

9-
To set up an AI Gateway in the dashboard:
10+
<LinkButton href="https://dash.cloudflare.com/?to=/:account/ai/ai-gateway#create">
11+
Create a Gateway
12+
</LinkButton>
1013

1114
1. Log into the [Cloudflare dashboard](https://dash.cloudflare.com/) and select your account.
1215
2. Go to **AI** > **AI Gateway**.
@@ -19,7 +22,6 @@ To set up an AI Gateway in the dashboard:
1922
To set up an AI Gateway using the API:
2023

2124
1. [Create an API token](/fundamentals/api/get-started/create-token/) with the following permissions:
22-
2325
- `AI Gateway - Read`
2426
- `AI Gateway - Edit`
2527

0 commit comments

Comments
 (0)