---
title: "What the AI SDK is (and why)"
summary: "The Vercel AI SDK is a TypeScript library: generateText, streamText, tools, structured output — provider-agnostic."
track: "The model"
day: 1
minutes: 14
author: "Akash Panchal"
url: https://ai-sdk-patterns.dev/learn/fundamentals/day-1/why-ai-sdk
dateModified: 2026-08-29
---

# What the AI SDK is (and why)

The Vercel AI SDK is a TypeScript library: generateText, streamText, tools, structured output — provider-agnostic.

*The model · Day 1: How AI apps work · ~14 min. Written by [Akash Panchal](https://github.com/akashp1712).*

Canonical: https://ai-sdk-patterns.dev/learn/fundamentals/day-1/why-ai-sdk

## After this topic

You will be able to point at four names — model, provider SDK, AI SDK, AI Gateway — and say what each one is for. You will know which file in this course to copy when you start an app.

## Four things people mash together

Before you copy code, separate these four names in your head — they are not interchangeable.

The model is the weights: Claude, GPT, Gemini. You do not import it. You name it.

A provider SDK (@openai/openai, @anthropic-ai/sdk, …) talks one vendor’s HTTP. Fine if you will only ever call that vendor and you like rewriting streaming yourself.

The Vercel AI SDK is the TypeScript library in the ai package (and @ai-sdk/react on the client). It is not a model. It is generateText, streamText, tool(), Output.object, useChat. One call shape, many backends.

AI Gateway sits in front of those backends on Vercel: one auth story, model ids like anthropic/claude-sonnet-4-5, observability, failover. The SDK can talk to Gateway with a plain string. That is the default in this course.

## What the library actually does

> The Vercel AI SDK is npm packages (ai and @ai-sdk/react). It is the TypeScript you write so calling a model from Next.js is boring — in a good way.

Without it you pick a vendor SDK, learn their streaming format, then their tool-call envelope, then do it again for a second vendor. With AI SDK v6 you call generateText or streamText, pass a model, pass messages, and optionally tools or an output schema. Switching models is a string, not a rewrite.

On the server you import from ai. On the client you import useChat from @ai-sdk/react and point it at your Route Handler. The key never enters the browser. That split is the whole architecture of a chat app in this stack.

- ai — server: generateText, streamText, tool(), Output.object, embed
- @ai-sdk/react — client: useChat, talking to your /api/* route
- getModel() — our helper: env → Gateway model id (every lesson uses this)
- AI Gateway — keys, routing, billing (recommended on Vercel)
- eve — later, when the product is a durable agent, not one Route Handler

## The one helper every lesson copies

This is lib/model.ts on this site. Lesson code never writes openai('gpt-4o') or anthropic('claude-…'). It writes getModel(). You change DEFAULT_MODEL in the environment — openai/gpt-4.1-mini or anthropic/claude-sonnet-4-5 — and the same generateText call hits a different vendor.

The helper also accepts the older provider:model spelling and rewrites it to provider/model, which is what Gateway expects. You can ignore that once you have seen it.

### lib/model.ts

```ts
import type { LanguageModel } from "ai";

export function getModel(id?: string): LanguageModel {
  const raw = id ?? process.env.DEFAULT_MODEL ?? "anthropic/claude-sonnet-4-5";
  const gatewayId = raw.includes("/") ? raw : raw.replace(":", "/");
  return gatewayId as LanguageModel;
}

// generateText({ model: getModel(), … })
// DEFAULT_MODEL=anthropic/claude-sonnet-4-5 → anthropic/claude-sonnet-4-5 via AI Gateway
```

- **Gateway model id.** AI SDK v6 accepts a plain string as the model. anthropic/claude-sonnet-4-5 is a Gateway id: provider, then the snapshot name.
- **DEFAULT_MODEL is the switch.** Set it locally in .env. On Vercel, set it in the project env. No code change, no new import.
- **Lesson code stays boring.** generateText({ model: getModel(), … }) never imports @ai-sdk/openai. That is how a six-month-old tutorial stops locking you to one vendor.

## What we learn next, and why this order

Next you will wait for a full reply with generateText. That is the easiest picture: one function, one string out. Then you will send a real messages array (system / user / assistant). Then streamText, which is the same call with a different delivery. Then a Zod schema so the string is data. Then embeddings, so you can find similar text.

We do not start with streaming, tools, or agents. Those are the interesting parts, and they only make sense once you can see a request and a reply on a page. If you already know this layer, skim — but do not skip generateText. Every later API is that call with more options.

## Common questions

### What the AI SDK is (and why)?

The Vercel AI SDK is a TypeScript library: generateText, streamText, tools, structured output — provider-agnostic.

### What will I be able to do after this lesson?

You will be able to point at four names — model, provider SDK, AI SDK, AI Gateway — and say what each one is for. You will know which file in this course to copy when you start an app.

### How long does this lesson take?

About 14 minutes of reading. It is a free chapter in the AI SDK Patterns TypeScript course.
