Delv
Vercel AI SDK
Getting Started Guide

How to Use Vercel AI SDK

A practical guide to get you up and running with Vercel AI SDK. Written by Delv Editorial, Delv Team.

Getting started with Vercel AI SDK

In this guide, you'll learn how to set up the Vercel AI SDK and create your first AI-powered application using TypeScript. By the end, you'll be able to build applications that can call tools and manage multi-step workflows.

Step 1: Sign up and set up

  1. Go to the Vercel AI SDK website.
  2. Click on the Get Started button on the homepage.
  3. If you don't have an account, click on Sign Up and create a free account using your email or GitHub.
  4. After signing up, log in to your account.
  5. Click on Documentation in the top menu to access the SDK documentation for setup instructions.

Step 2: Your first application

  1. Open your terminal and create a new directory for your project:
mkdir my-ai-app
   cd my-ai-app
  1. Initialise a new TypeScript project:
npm init -y
   npm install typescript ts-node @types/node --save-dev
   npx tsc --init
  1. Install the Vercel AI SDK:
npm install @vercel/ai-sdk
  1. Create a new file named index.ts in your project directory.
  2. Add the following code to index.ts to set up a basic AI tool call:
import { createAI } from '@vercel/ai-sdk';

const ai = createAI({ apiKey: 'your-api-key-here' });

async function fetchResponse() {
const response = await ai.call('What is the weather today?');
console.log(response);
}

fetchResponse();


  1. Replace 'your-api-key-here' with your actual API key from the Vercel dashboard.

  2. Run your application:

npx ts-node index.ts

Step 3: Get better results

  • To enhance your AI's responses, use specific prompts. Instead of asking vague questions, frame them with context, like "Explain the weather patterns in London today."
  • Explore the API Reference in the documentation to learn about additional methods and settings you can configure for your AI calls.

Pro tip

Use TypeScript's type definitions by installing @types/vercel__ai-sdk to get autocomplete suggestions and error checking while coding. This will speed up your development process and help you avoid mistakes.

Common mistake to avoid

Many beginners forget to add their API key, leading to authentication errors. Ensure you have correctly set your API key in the configuration before running your application.