The Vercel AI SDK is a TypeScript library for building AI-powered applications. It works with multiple AI providers and makes it easy to integrate AI into your apps.
Before we dive into code, let’s understand how AI got here. It’s a fascinating story!The foundation of AI is search. Think about it:
🎮 Pacman ghosts search for the best path to catch you
♟️ Chess AI searches millions of moves to find the best one
💬 ChatGPT searches through patterns in language
✨ Gemini searches across text, images, video, and code
Why Google leads AI: Google is the world’s best at search—the foundation of AI. This is why they’re state-of-the-art across text generation, math reasoning, image generation, video generation, and more. When you use Gemini, you’re using decades of search innovation!
import { generateText } from 'ai';import { google } from "@ai-sdk/google";const { text } = await generateText({ model: google("gemini-2.5-flash"), system: 'You are a professional writer. ' + 'You write simple, clear, and concise content.', prompt: `Summarize the following article in 3-5 sentences: ${article}`,});console.log(text);
Why Gemini? Google offers free API access with generous limits—perfect for learning and prototyping!
// ❌ Unstructured text - hard to use programmaticallyconst response = "Here's a recipe: Lasagna. You'll need pasta, cheese, sauce...";// How do you extract the ingredients? The steps? 🤔
Descriptions help the AI understand what you want:
Copy
const flashcardSchema = z.object({ flashcards: z.array( z.object({ front: z.string().describe('The question on the flashcard'), back: z.string().describe('The answer on the flashcard'), }) ).describe('Array of 10 flashcards'),});