Vercel AI SDK
A TypeScript library for AI chats with streaming, tools and a swappable model provider.
AIUsing since 2024 · Featured project: ENATIV Portfolio
- Category
- AI
- Using since
- 2024
- Featured project
- ENATIV Portfolio
In practice
I pick the AI SDK when an AI feature should live inside a TypeScript app and not tie it to one model provider. The chat on this site, ENATIV Portfolio, runs on it with streaming and tools, and Next.js serves the API route.
What is Vercel AI SDK?
The Vercel AI SDK is an open-source TypeScript toolkit for building apps on language models. Its Core layer gives one API for generating text, structured objects and tool calls, and its UI layer adds chat hooks such as useChat for React. That keeps answer streaming and tool calls inside a plain API route.
The same code runs against many model providers. OpenAI and Anthropic are among them, and others, OpenRouter for one, come as community providers. Swapping the model changes configuration, not the rest of the app. You write all of it in TypeScript.
- License
- Apache 2.0
- Language
- TypeScript
How I work with Vercel AI SDK
I start from what the feature has to do and which data it may touch, and only then pick a model. The provider is replaceable, the limits are not. First I settle what happens when the model gets it wrong, because a prompt cannot fix that.
Streaming and validation
The answer streams to the browser through
streamText, and I validate the request and the conversation history on the server before anything reaches the model. That is how I built the chat route in ENATIV Portfolio. Only then does the answer reach the user piece by piece.Tools with limits
The model gets tools, but I decide what they can do. The inquiry tool only drafts a message, sending needs the visitor to confirm it, and the server sets the recipient. Project citations read from the registry, not from the "memory" of the model.
Caps and provider
I keep the provider in one place and cap the number of steps and the answer length, so one request cannot grow into a chain of model calls. I treat the system prompt as guidance for the model, not as a safeguard. On top of that comes a fixed set of test questions that I run on every model change.
When it fits, and when it doesn't
The AI SDK fits when AI is a feature of an app, not a system of its own.
A good fit when
- A chat or assistant in a Next.js app with streamed answers.
- A feature that has to call tools: look up data, draft a message, read a record.
- A project where the model provider may change during the life of the product.
- A reply with a fixed shape, such as sorting a ticket into a closed list of categories.
Not a fit when
- An app without TypeScript, since the SDK is written in it.
- A single script that asks a model once: a plain HTTP request is enough.
- A large processing pipeline in a team that already knows another tool.
- A team where nobody will maintain the prompts and the response validation.
There I look at LangChain, and at OpenRouter for reaching many models through one account, which this site uses. When the assistant should answer from your own documents, that is a separate topic: RAG.
Frequently asked questions
Want to add AI to your app?
Tell me what the assistant should do and which data it can use. I will say whether a chat with a few tools is enough or the project needs more. The scope is described on the [[service:ai|AI integration]] page.