Skip to content

Commit

Permalink
added examples and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
daisyfaithauma committed Nov 14, 2024
1 parent d513d58 commit 6e16f6a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 4 deletions.
7 changes: 6 additions & 1 deletion src/content/changelogs/ai-gateway.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ productLink: "/ai-gateway/"
productArea: Developer platform
productAreaLink: /workers/platform/changelog/platform/
entries:
- publish_date: "2024-11-19"
title: Authentication
description: |-
* **Configuration**: Added [Authentication](/ai-gateway/configuration/authentication/) which adds security by requiring a valid authorization token for each request.
- publish_date: "2024-10-28"
title: Grok
description: |-
* **Providers**: Added [Grok](/ai-gateway/providers/grok/) as a new provider.
- publish_date: "2024-10-17"
title: Vercel SDK
description: |-
Expand Down
29 changes: 26 additions & 3 deletions src/content/docs/ai-gateway/configuration/authentication.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ If Authenticated Gateway is enabled but a request does not include the required
3. Include the `cf-aig-authorization` header with your API token in each request for this gateway.
4. Return to the settings page and toggle on Authenticated Gateway.

## Example request with OpenAI
## Example requests with OpenAI

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

## Setting Authenticated Gateway using the API
Using OpenAI sdk:

For API setup, see the [API documentation](/api/operations/aig-config-create-gateway/).
```javascript
import OpenAI from "openai";

const openai = new OpenAI({
apiKey: process.env.OPENAI_API_KEY,
baseURL: "https://gateway.ai.cloudflare.com/v1/account-id/gateway/openai",
defaultHeaders: {
"cf-aig-token": `Bearer {token}`,
},
});
```

## Example requests with Vercel sdk

```javascript
import { createOpenAI } from "@ai-sdk/openai";

const openai = createOpenAI({
baseURL: "https://gateway.ai.cloudflare.com/v1/account-id/gateway/openai",
headers: {
"cf-aig-token": `Bearer {token}`,
},
});
```

## Expected behavior

Expand Down

0 comments on commit 6e16f6a

Please sign in to comment.