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, image generation, and video 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, generateImage, and generateVideo 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:

Using custom endpoints

You can use your own Serverless endpoints with the AI SDK. This is useful when you’ve deployed a custom model or want to use a specific endpoint you’ve created.

Using endpoint IDs

Pass your Serverless endpoint ID directly as the model identifier:
The SDK resolves your endpoint ID to https://api.runpod.ai/v2/{endpointId} automatically.

Using Console URLs

Copy an endpoint URL directly from the Runpod Console and use it as the model identifier:
The SDK extracts the endpoint ID from the Console URL and routes requests to your endpoint.

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:

Video generation

Use experimental_generateVideo to generate videos from text prompts or images. The Runpod provider supports 15 video models, including Sora, Wan, Seedance, and Kling. Video generation is asynchronous—the SDK submits a job, polls for completion, and returns the video URL when ready.

Text-to-video

Generate videos from text prompts:
The response includes:
  • video.url: URL to the generated video
  • video.mediaType: Video MIME type (video/mp4)

Image-to-video

Animate an existing image:

Video generation parameters

Control the video generation with additional parameters:

Video provider options

Pass model-specific parameters using providerOptions:

Supported models

Text models

Image models

Video 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