Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ai-gateway] Add Vercel AI SDK example page #17468

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,6 @@
"node": ">=22"
},
"volta": {
"node": "22.8.0"
"node": "22.9.0"
}
}
8 changes: 8 additions & 0 deletions src/content/docs/ai-gateway/integration/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
pcx_content_type: configuration
title: Integration
sidebar:
group:
hideIndex: true
order: 12
---
40 changes: 40 additions & 0 deletions src/content/docs/ai-gateway/integration/vercel-ai-sdk.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
title: Vercel AI SDK
pcx_content_type: configuration
sidebar:
order: 3
---

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.

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.

## Examples

### OpenAI

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:

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

const openai = createOpenAI({
baseURL: `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai`,
});
```

### Anthropic

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:

```typescript
import { createAnthropic } from "@ai-sdk/anthropic";

const anthropic = createAnthropic({
baseURL: `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic`,
});
```

### Other providers

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).
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,4 @@ const model = genAI.getGenerativeModel(
);

await model.generateContent(["What is Cloudflare?"]);
```
```
Loading