# Vercel AI SDK — Build AI Apps in TypeScript > Official TypeScript SDK for building AI-powered applications. Unified API for Claude, GPT-4, Gemini with streaming, tool use, structured output, and React hooks. By Vercel. 12,000+ stars. ## Install Save as a script file and run: ## Quick Use ```bash npm install ai @ai-sdk/anthropic ``` ```typescript import { generateText } from "ai"; import { anthropic } from "@ai-sdk/anthropic"; const { text } = await generateText({ model: anthropic("claude-sonnet-4-20250514"), prompt: "Explain quantum computing in 3 sentences", }); console.log(text); ``` Streaming in Next.js: ```typescript import { streamText } from "ai"; export async function POST(req: Request) { const { messages } = await req.json(); const result = streamText({ model: anthropic("claude-sonnet-4-20250514"), messages, }); return result.toDataStreamResponse(); } ``` --- ## Intro Vercel AI SDK is the official TypeScript SDK for building AI-powered applications with 12,000+ GitHub stars. It provides a unified API across Claude, GPT-4, Gemini, and 20+ providers with streaming, tool use, structured output (JSON schema), and React hooks for chat UIs. Used by Next.js AI Chatbot, v0, and thousands of production apps. Best for TypeScript/React developers building AI features into web applications. Works with: Next.js, React, Svelte, Vue, Node.js. Setup time: under 2 minutes. --- ## Core Functions ### `generateText` — Simple Completion ```typescript const { text } = await generateText({ model: anthropic("claude-sonnet-4-20250514"), prompt: "Write a haiku about coding", }); ``` ### `streamText` — Streaming Response ```typescript const result = streamText({ model: anthropic("claude-sonnet-4-20250514"), messages: [{ role: "user", content: "Tell me a story" }], }); for await (const chunk of result.textStream) { process.stdout.write(chunk); } ``` ### `generateObject` — Structured Output ```typescript import { z } from "zod"; const { object } = await generateObject({ model: anthropic("claude-sonnet-4-20250514"), schema: z.object({ recipe: z.string(), ingredients: z.array(z.string()), steps: z.array(z.string()), }), prompt: "Generate a recipe for chocolate cake", }); // object.recipe, object.ingredients, object.steps — fully typed! ``` ### Tool Use ```typescript const result = await generateText({ model: anthropic("claude-sonnet-4-20250514"), tools: { getWeather: { description: "Get weather for a location", parameters: z.object({ city: z.string() }), execute: async ({ city }) => ({ temp: 22, condition: "sunny" }), }, }, prompt: "What is the weather in Tokyo?", }); ``` ### React Hooks (useChat) ```typescript "use client"; import { useChat } from "ai/react"; export default function Chat() { const { messages, input, handleInputChange, handleSubmit } = useChat(); return (
{messages.map(m =>
{m.role}: {m.content}
)}
); } ``` ### Provider Adapters | Provider | Package | |----------|---------| | Anthropic | `@ai-sdk/anthropic` | | OpenAI | `@ai-sdk/openai` | | Google | `@ai-sdk/google` | | Mistral | `@ai-sdk/mistral` | | Cohere | `@ai-sdk/cohere` | | Amazon Bedrock | `@ai-sdk/amazon-bedrock` | ### Key Stats - 12,000+ GitHub stars - By Vercel - 20+ provider adapters - Streaming, tools, structured output - React/Svelte/Vue hooks ### FAQ **Q: What is Vercel AI SDK?** A: A TypeScript SDK providing a unified API for building AI features with streaming, tool use, and structured output across 20+ model providers. **Q: Is it free?** A: Yes, open-source under Apache 2.0. You provide your own API keys. **Q: Do I need Next.js?** A: No, the core SDK works with any Node.js project. The React hooks work with any React app. --- ## Source & Thanks > Created by [Vercel](https://github.com/vercel). Licensed under Apache 2.0. > > [ai](https://github.com/vercel/ai) — stars 12,000+ Thanks to Vercel for standardizing AI development in TypeScript. --- ## 快速使用 ```bash npm install ai @ai-sdk/anthropic ``` ```typescript import { generateText } from "ai"; import { anthropic } from "@ai-sdk/anthropic"; const { text } = await generateText({ model: anthropic("claude-sonnet-4-20250514"), prompt: "用三句话解释量子计算", }); ``` --- ## 简介 Vercel AI SDK 是官方 TypeScript AI 开发 SDK,GitHub 12,000+ stars。为 Claude、GPT-4、Gemini 等 20+ 提供商提供统一 API,支持流式、工具调用、结构化输出和 React Hooks。适合构建 AI 功能的 TypeScript/React 开发者。 --- ## 来源与感谢 > Created by [Vercel](https://github.com/vercel). Licensed under Apache 2.0. > > [ai](https://github.com/vercel/ai) — stars 12,000+ --- Source: https://tokrepo.com/en/workflows/7a5b5d88-b0a1-409f-906a-d9bd54ad3330 Author: Script Depot