Skip to main content
The @runpod/ai-sdk-provider package integrates Runpod Public Endpoints with the Vercel AI SDK. This gives you a streamlined, type-safe interface for text generation, streaming, and image generation in JavaScript and TypeScript projects. The Vercel AI SDK is a popular open-source library for building AI applications. By using the Runpod provider, you can access Runpod’s Public Endpoints using the same patterns and APIs you’d use with other AI providers like OpenAI or Anthropic.

Why use the Vercel AI SDK?

  • Unified interface: Use the same generateText, streamText, and generateImage functions regardless of which AI provider you’re using.
  • Type safety: Full TypeScript support with typed responses and parameters.
  • Streaming built-in: First-class support for streaming text responses.
  • Framework integrations: Works seamlessly with Next.js, React, Svelte, and other frameworks.
  • Provider switching: Easily switch between Runpod and other providers without rewriting your code.

Installation

Install the Runpod provider alongside the Vercel AI SDK:

Configuration

Default configuration

The provider reads your API key from the RUNPOD_API_KEY environment variable by default. Import the runpod instance and start using it immediately:
Set the environment variable in your shell or .env file:

Custom configuration

For more control, use createRunpod to create a custom provider instance:

Text generation

Basic text generation

Use generateText to generate text from a prompt:
The response includes:
  • text: The generated text
  • finishReason: Why generation stopped (stop, length, etc.)
  • usage: Token counts (promptTokens, completionTokens, totalTokens)

Chat conversations

For multi-turn conversations, pass a messages array instead of a prompt:

Generation parameters

Control the generation behavior with additional parameters:

Streaming

For real-time output (useful for chat interfaces), use streamText:

Streaming with callbacks

You can also use callbacks to handle streaming events:

Image generation

Text-to-image

Generate images using models like Flux:
The response includes:
  • image.uint8Array: Binary image data
  • image.base64: Base64-encoded image
  • image.mimeType: Image MIME type (e.g., image/png)

Image editing

Edit existing images by providing reference images:
For models that support multiple reference images:

Provider options

Pass model-specific parameters using providerOptions:

Supported models

Text models

Image models

For a complete list of available models and their parameters, see the model reference.

Example: Chat application

Here’s a complete example of a simple chat application using streaming:

Next steps