Skip to content

Commit ffa2c77

Browse files
[ai-gateway] Add Vercel AI SDK example page
1 parent 93b5b3f commit ffa2c77

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,6 @@
8383
"node": ">=22"
8484
},
8585
"volta": {
86-
"node": "22.8.0"
86+
"node": "22.9.0"
8787
}
8888
}

src/content/docs/ai-gateway/providers/google-ai-studio.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,4 +69,4 @@ const model = genAI.getGenerativeModel(
6969
);
7070

7171
await model.generateContent(["What is Cloudflare?"]);
72-
```
72+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
title: Vercel AI SDK
3+
pcx_content_type: configuration
4+
sidebar:
5+
order: 3
6+
---
7+
8+
The [Vercel AI SDK](https://sdk.vercel.ai/) is a TypeScript library for building AI applications. The SDK supports many different AI providers, tools for streaming completions, and more.
9+
10+
To use Cloudflare AI Gateway inside of the AI SDK, you can configure a custom "Gateway URL" for most supported providers. Below are a few examples of how it works.
11+
12+
## Examples
13+
14+
### OpenAI
15+
16+
If you're using the `openai` provider in AI SDK, you can create a customized setup with `createOpenAI`, passing your OpenAI-compatible AI Gateway URL:
17+
18+
```typescript
19+
import { createOpenAI } from '@ai-sdk/openai';
20+
21+
const openai = createOpenAI({
22+
baseURL: `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai`
23+
});
24+
```
25+
26+
### Anthropic
27+
28+
If you're using the `anthropic` provider in AI SDK, you can create a customized setup with `createAnthropic`, passing your Anthropic-compatible AI Gateway URL:
29+
30+
```typescript
31+
import { createAnthropic } from '@ai-sdk/anthropic';
32+
33+
const anthropic = createAnthropic({
34+
baseURL: `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic`
35+
});
36+
```
37+
38+
### Other providers
39+
40+
For other providers that are not listed above, you can follow a similar pattern by creating a custom instance for any AI provider, and passing your AI Gateway URL. For help finding your provider-specific AI Gateway URL, refer to the [Supported providers page](/ai-gateway/providers).

0 commit comments

Comments
 (0)