From ffa2c7792084751a0797965d183f5518ef593b84 Mon Sep 17 00:00:00 2001 From: Kristian Freeman Date: Thu, 10 Oct 2024 11:56:41 -0500 Subject: [PATCH 1/3] [ai-gateway] Add Vercel AI SDK example page --- package.json | 2 +- .../ai-gateway/providers/google-ai-studio.mdx | 2 +- .../ai-gateway/providers/vercel-ai-sdk.mdx | 40 +++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 src/content/docs/ai-gateway/providers/vercel-ai-sdk.mdx diff --git a/package.json b/package.json index 81ff9169e767d8..34bb71fc3f8d00 100644 --- a/package.json +++ b/package.json @@ -83,6 +83,6 @@ "node": ">=22" }, "volta": { - "node": "22.8.0" + "node": "22.9.0" } } diff --git a/src/content/docs/ai-gateway/providers/google-ai-studio.mdx b/src/content/docs/ai-gateway/providers/google-ai-studio.mdx index adc96e95c4eb32..9cb880571068c0 100644 --- a/src/content/docs/ai-gateway/providers/google-ai-studio.mdx +++ b/src/content/docs/ai-gateway/providers/google-ai-studio.mdx @@ -69,4 +69,4 @@ const model = genAI.getGenerativeModel( ); await model.generateContent(["What is Cloudflare?"]); -``` +``` \ No newline at end of file diff --git a/src/content/docs/ai-gateway/providers/vercel-ai-sdk.mdx b/src/content/docs/ai-gateway/providers/vercel-ai-sdk.mdx new file mode 100644 index 00000000000000..47a750bcf0511c --- /dev/null +++ b/src/content/docs/ai-gateway/providers/vercel-ai-sdk.mdx @@ -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). \ No newline at end of file From e3dd763c52387b9156b96800792f645dbb272da5 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 16 Oct 2024 13:31:04 +0100 Subject: [PATCH 2/3] Moved vercel SDK to Integration --- .../docs/ai-gateway/{providers => integration}/vercel-ai-sdk.mdx | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename src/content/docs/ai-gateway/{providers => integration}/vercel-ai-sdk.mdx (100%) diff --git a/src/content/docs/ai-gateway/providers/vercel-ai-sdk.mdx b/src/content/docs/ai-gateway/integration/vercel-ai-sdk.mdx similarity index 100% rename from src/content/docs/ai-gateway/providers/vercel-ai-sdk.mdx rename to src/content/docs/ai-gateway/integration/vercel-ai-sdk.mdx From 8217d418cf0f455fa4789892ae8f7c29aacbf310 Mon Sep 17 00:00:00 2001 From: daisyfaithauma Date: Wed, 16 Oct 2024 14:36:46 +0100 Subject: [PATCH 3/3] hid the index --- src/content/docs/ai-gateway/integration/index.mdx | 8 ++++++++ .../docs/ai-gateway/integration/vercel-ai-sdk.mdx | 10 +++++----- 2 files changed, 13 insertions(+), 5 deletions(-) create mode 100644 src/content/docs/ai-gateway/integration/index.mdx diff --git a/src/content/docs/ai-gateway/integration/index.mdx b/src/content/docs/ai-gateway/integration/index.mdx new file mode 100644 index 00000000000000..1574b2332fd980 --- /dev/null +++ b/src/content/docs/ai-gateway/integration/index.mdx @@ -0,0 +1,8 @@ +--- +pcx_content_type: configuration +title: Integration +sidebar: + group: + hideIndex: true + order: 12 +--- diff --git a/src/content/docs/ai-gateway/integration/vercel-ai-sdk.mdx b/src/content/docs/ai-gateway/integration/vercel-ai-sdk.mdx index 47a750bcf0511c..bd18fa2fb39a54 100644 --- a/src/content/docs/ai-gateway/integration/vercel-ai-sdk.mdx +++ b/src/content/docs/ai-gateway/integration/vercel-ai-sdk.mdx @@ -16,10 +16,10 @@ To use Cloudflare AI Gateway inside of the AI SDK, you can configure a custom "G 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'; +import { createOpenAI } from "@ai-sdk/openai"; const openai = createOpenAI({ - baseURL: `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai` + baseURL: `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/openai`, }); ``` @@ -28,13 +28,13 @@ const openai = createOpenAI({ 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'; +import { createAnthropic } from "@ai-sdk/anthropic"; const anthropic = createAnthropic({ - baseURL: `https://gateway.ai.cloudflare.com/v1/{account_id}/{gateway_id}/anthropic` + 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). \ No newline at end of file +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).