====== Vercel AI SDK ====== **Vercel AI SDK** is an open-source TypeScript toolkit for building AI-powered applications. It provides a unified API across providers like OpenAI, Anthropic, Google, and Mistral, with core functions for text and object generation, React/Next.js hooks, tool calling, and streaming support.((source [[https://ai-sdk.dev/docs/introduction|AI SDK Documentation]])) ===== Core Functions ===== The AI SDK Core provides primitive functions for LLM interactions:((source [[https://vercel.com/docs/ai-sdk|Vercel AI SDK Docs]])) * **generateText** -- generates text from any supported model; suitable for Q&A, batch processing, classification * **streamText** -- streams text tokens in real-time for responsive chat UIs and progressive content generation * **generateObject** -- produces structured JSON output constrained to a Zod schema; eliminates brittle text parsing * **streamObject** -- streams structured objects incrementally for progressive UI updates with validated JSON All functions use a unified API, requiring only provider/model swaps for portability. ===== Streaming ===== Streaming is a first-class concern in the AI SDK:((source [[https://blog.logrocket.com/nextjs-vercel-ai-sdk-streaming/|Vercel AI SDK Streaming - LogRocket]])) * Token-by-token delivery for real-time user experiences * Built-in handling of Server-Sent Events (SSE) * Backpressure management and error recovery * Edge runtime compatible for low-latency global deployment * Works across Vercel Edge, Cloudflare Workers, and Node.js ===== Tool Calling ===== The tool system enables AI models to execute functions and interact with external systems:((source [[https://www.pkgpulse.com/blog/vercel-ai-sdk-v4-generatetext-streamtext-tools-2026|AI SDK v4 Tools - PkgPulse]])) * Define tools with Zod-validated parameter schemas and ''execute'' functions * Model decides which tool to call based on conversation context * SDK validates inputs, executes the function, and passes results back to the model * **maxSteps** enables automatic multi-step tool execution for agentic workflows * Integrated with both ''generateText'' and ''streamText'' ===== Multi-Provider Support ===== The SDK provides a unified interface across all major LLM providers:((source [[https://www.better-stack.ai/p/blog/vercel-ai-sdk-vs-tanstack-ai-2026-best-ai-sdk-for-developers|AI SDK vs TanStack AI 2026]])) * **OpenAI** -- GPT series models * **Anthropic** -- Claude models * **Google** -- Gemini models * **Mistral** -- Mistral and Mixtral models * **Cohere, Hugging Face, Amazon Bedrock** -- additional providers * Switch providers by changing a single import line * AI Gateway proxy adds retries, fallbacks, token tracking, and cost management ===== React and Next.js Integration ===== AI SDK UI provides React hooks for interactive applications:((source [[https://www.codecademy.com/article/guide-to-vercels-ai-sdk|Vercel AI SDK Guide - Codecademy]])) * **useChat** -- manages chat state, streaming messages, multimodal inputs, and tool calls * **useCompletion** -- streamlined hook for non-conversational text completion * **useObject** -- streaming structured data to React components * Framework support for React, Svelte, Vue, and Angular * Optimized for Next.js App Router and Server Actions ===== Server Actions ===== The SDK integrates directly with Next.js Server Actions:((source [[https://www.digitalapplied.com/blog/vercel-ai-sdk-6-streaming-chat-nextjs-guide|AI SDK 6 Streaming Guide]])) * Server-side generation and streaming without separate API routes * API keys remain secure on the server * End-to-end type safety between server and client * React Server Component streaming for AI-generated UI * 70% reduction in API boilerplate compared to REST-based approaches ===== Recent Developments ===== * **v4 (2025)** -- introduced ''generateObject'' for structured outputs, multi-step tool calling with ''maxSteps'', ''useObject'' for streaming structured data, and provider middleware for logging and caching((source [[https://www.pkgpulse.com/blog/vercel-ai-sdk-v4-generatetext-streamtext-tools-2026|AI SDK v4 - PkgPulse]])) * **v6 (2026)** -- shifted from REST routes to native Server Actions, unified API enhancements, multimodal support improvements, and agent optimizations((source [[https://www.digitalapplied.com/blog/vercel-ai-sdk-6-streaming-chat-nextjs-guide|AI SDK 6 Guide]])) * The ''ai'' npm package reaches approximately 3.5 million weekly downloads as of March 2026 ===== See Also ===== * [[streamlit_ai|Streamlit for AI]] * [[gradio|Gradio]] * [[hugging_face|Hugging Face]] ===== References =====