Vercel AI SDK
The Vercel AI SDK ↗ 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.
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:
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:
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.