@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, andgenerateVideofunctions 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 theRUNPOD_API_KEY environment variable by default. Import the runpod instance and start using it immediately:
.env file:
Custom configuration
For more control, usecreateRunpod 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: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:Text generation
Basic text generation
UsegenerateText to generate text from a prompt:
text: The generated textfinishReason: Why generation stopped (stop,length, etc.)usage: Token counts (promptTokens,completionTokens,totalTokens)
Chat conversations
For multi-turn conversations, pass amessages array instead of a prompt:
Generation parameters
Control the generation behavior with additional parameters:Streaming
For real-time output (useful for chat interfaces), usestreamText:
Streaming with callbacks
You can also use callbacks to handle streaming events:Image generation
Text-to-image
Generate images using models like Flux:image.uint8Array: Binary image dataimage.base64: Base64-encoded imageimage.mimeType: Image MIME type (e.g.,image/png)
Image editing
Edit existing images by providing reference images:Provider options
Pass model-specific parameters usingproviderOptions:
Video generation
Useexperimental_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:video.url: URL to the generated videovideo.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 usingproviderOptions:
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
- Model reference: View all available models and their parameters.
- Make API requests: Learn about the REST API for lower-level control.
- @runpod/ai-sdk-provider on GitHub: View the source code and contribute.
- Vercel AI SDK documentation: Learn more about the AI SDK.