Skip to content

Commit 6e16f6a

Browse files
added examples and changelog
1 parent d513d58 commit 6e16f6a

File tree

2 files changed

+32
-4
lines changed

2 files changed

+32
-4
lines changed

src/content/changelogs/ai-gateway.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@ productLink: "/ai-gateway/"
55
productArea: Developer platform
66
productAreaLink: /workers/platform/changelog/platform/
77
entries:
8+
- publish_date: "2024-11-19"
9+
title: Authentication
10+
description: |-
11+
* **Configuration**: Added [Authentication](/ai-gateway/configuration/authentication/) which adds security by requiring a valid authorization token for each request.
12+
813
- publish_date: "2024-10-28"
914
title: Grok
1015
description: |-
1116
* **Providers**: Added [Grok](/ai-gateway/providers/grok/) as a new provider.
12-
17+
1318
- publish_date: "2024-10-17"
1419
title: Vercel SDK
1520
description: |-

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

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ If Authenticated Gateway is enabled but a request does not include the required
2222
3. Include the `cf-aig-authorization` header with your API token in each request for this gateway.
2323
4. Return to the settings page and toggle on Authenticated Gateway.
2424

25-
## Example request with OpenAI
25+
## Example requests with OpenAI
2626

2727
```bash
2828
curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/completions \
@@ -32,9 +32,32 @@ curl https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai/chat/
3232
--data '{"model": "gpt-3.5-turbo", "messages": [{"role": "user", "content": "What is Cloudflare?"}]}'
3333
```
3434

35-
## Setting Authenticated Gateway using the API
35+
Using OpenAI sdk:
3636

37-
For API setup, see the [API documentation](/api/operations/aig-config-create-gateway/).
37+
```javascript
38+
import OpenAI from "openai";
39+
40+
const openai = new OpenAI({
41+
apiKey: process.env.OPENAI_API_KEY,
42+
baseURL: "https://gateway.ai.cloudflare.com/v1/account-id/gateway/openai",
43+
defaultHeaders: {
44+
"cf-aig-token": `Bearer {token}`,
45+
},
46+
});
47+
```
48+
49+
## Example requests with Vercel sdk
50+
51+
```javascript
52+
import { createOpenAI } from "@ai-sdk/openai";
53+
54+
const openai = createOpenAI({
55+
baseURL: "https://gateway.ai.cloudflare.com/v1/account-id/gateway/openai",
56+
headers: {
57+
"cf-aig-token": `Bearer {token}`,
58+
},
59+
});
60+
```
3861

3962
## Expected behavior
4063

0 commit comments

Comments
 (0)