Prerequisites

  • API keys for the AI services you plan to use (e.g., OpenAI, Anthropic, Google, etc.)

Setup

  1. Add the API keys to your environment variables
.env
# OpenAI API key
OPENAI_API_KEY=your-openai-api-key
ANTHROPIC_API_KEY=your-anthropic-api-key
GOOGLE_GENERATIVE_AI_API_KEY=your-google-api-key
# Add other API keys as needed
  1. The boilerplate already includes the necessary configuration for the Vercel AI SDK in src/lib/ai/ai-sdk. This file initializes the Vercel AI SDK with your API keys.

Usage

To use the Vercel AI SDK in your application, you can create an API route that interacts with the AI models provided by the SDK. This route can be used to generate images, text, and more using the AI models provided by the various services.

Create a new file in your API routes directory (e.g., app/api/ai-sdk/route.ts). This file will contain the logic for interacting with the Vercel AI SDK.

Here’s an example of how to set up a route that uses the OpenAI model:

Model Selection

The Vercel AI SDK provides access to various AI models from different services. You can use these models to generate text, images, and more. Here are some of the models available in the Vercel AI SDK:

  • Anthropic
  • Fireworks
  • Google Generative AI
  • Groq
  • Mistral
  • OpenAI
  • Perplexity
  • Vertex AI