# ai

> TypeScript library for calling AI models and building agents and chat UIs

- Repository: https://github.com/vercel/ai
- Category: Coding agents & dev tools
- Stars: 27,467 · Forks: 5,419 · Language: TypeScript · License: not stated
- Experience: Some experience
- Page: https://ir.adyog.com/repos/vercel/ai/

The AI SDK is a TypeScript library for adding language models to web apps. It gives you one set of functions for many model providers, so switching models is mostly a matter of changing a model name.

On the server, you call functions like generateText to get text, or ask for structured output that matches a Zod schema. For agents, ToolLoopAgent runs a model that can call tools in a loop. On the client, a separate UI module offers hooks such as useChat for building chatbots and interfaces that show tool results.

The obvious alternative is using each provider's own SDK. Here, model strings go through the Vercel AI Gateway by default, or you can install provider packages like @ai-sdk/openai and @ai-sdk/anthropic to connect directly. It is made by the Vercel and Next.js team and works with Next.js, React, Svelte, Vue, Angular and Node.js.

## What it does

- **One API for many providers**: Call OpenAI, Anthropic, Google and others through the same functions. Use a model string via the Vercel AI Gateway, or install provider packages to connect directly.
- **Text and structured output**: generateText returns plain text. Output.object with a Zod schema returns typed data, such as a recipe with ingredients and steps.
- **Tool-using agents**: ToolLoopAgent takes a model, a system prompt and tools, for example a shell tool that runs commands in a sandbox.
- **UI hooks for chat**: The @ai-sdk/react package provides useChat. The hooks are framework agnostic across Next.js, React, Svelte and Vue, and tool calls can render as custom components.
- **Skill for coding agents**: You can add an AI SDK skill to your repository so tools like Claude Code or Cursor know how to use the library.

## What you could build

- Build a chatbot in Next.js that streams replies from any major model provider.
- Extract structured data, such as a recipe, from a prompt and validate it with a Zod schema.
- Create an agent that calls tools, such as running shell commands in a sandbox.
- Show generated images or other tool results inside a chat interface with custom components.
- Switch an app between OpenAI, Anthropic and Google models by changing one string.

## Who it's for

Suits web developers who already know TypeScript and want to add LLM features to an app; you need Node.js 22+ and some React or similar framework experience for the UI parts.

## Get started

Install the ai package with Node.js 22 or newer, then call generateText with a model string. For chat UIs, add the package for your framework, such as @ai-sdk/react, and use the useChat hook.

```
npm install ai
```
```
npm install @ai-sdk/react
```
```
npx skills add vercel/ai
```

Tags: typescript, llm, agents, nextjs, sdk
