页面简介
The AI SDK is the TypeScript toolkit for building AI applications and agents with React, Next.js, Vue, Svelte, Node.js, and more.
正文摘录
MenuAI SDK by VercelCopy for LLMView MarkdownAsk AI about this pageThe AI SDK is the TypeScript toolkit designed to help developers build AI-powered applications and agents with React, Next.js, Vue, Svelte, Node.js, and more. Why use the AI SDK? Integrating large language models (LLMs) into applications is complicated and heavily dependent on the specific model provider you use. The AI SDK standardizes integrating artificial intelligence (AI) models across supported providers. This enables developers to focus on building great AI applications, not waste time on technical details. The AI SDK also includes a harness abstraction for using established agent harnesses such as Claude Code, Codex, and Pi through HarnessAgent. Harnesses are decoupled from model providers, but use compatible stream and response primitives so AI SDK UI and agent surfaces can consume them in the same way. For example, here’s how you can generate text with various models using the AI SDK: GatewayProviderCustomClaude Sonnet 5.5import { generateText } from "ai"; const { text } = await generateText({ model: "anthropic/claude-sonnet-5.5", prompt: "What is love?", }); Love is a complex and multifaceted emotion that can be felt and expressed in many different ways. It involves deep affection, care, compassion, and connection towards another person or thing. The AI SDK has these primary surfaces: AI SDK Core: A unified API for generating text, structured objects, tool calls, and building agents with LLMs. AI SDK UI: A set of framework-agnostic hooks for quickly building chat and generative user interfaces. AI SDK Harnesses: A uniform API for running established agent harnesses with HarnessAgent. Model Providers The AI SDK supports multiple model providers. Vercel AI GatewayImage InputImage GenerationObject GenerationTool UsageTool StreamingOpenAIImage InputImage GenerationObject GenerationTool UsageTool StreamingAnthropicImage InputObject GenerationTool UsageTool StreamingGoogle Generative AIImage InputObject GenerationTool UsageTool StreamingxAI GrokImage InputImage GenerationObject GenerationTool UsageTool StreamingAzureImage InputObject GenerationTool UsageTool StreamingAmazon BedrockImage InputImage GenerationObject GenerationTool UsageTool StreamingGroqImage InputObject GenerationTool UsageTool StreamingFal AIImage GenerationDeepInfraImage InputObject GenerationTool UsageTool StreamingGoogle Vertex AIImage InputImage GenerationObject GenerationTool UsageTool StreamingMistralImage InputObject GenerationTool UsageTool StreamingTogether.aiObject GenerationTool UsageTool StreamingCohereTool UsageTool StreamingFireworksImage GenerationObject GenerationTool UsageTool StreamingDeepSeekObject GenerationTool UsageTool StreamingCerebrasObject GenerationTool UsageTool StreamingPerplexityImage InputObject GenerationTool UsageTool StreamingLuma AIImage GenerationBasetenObject GenerationTool Usage Templates We've built some templates that include AI SDK integrations for different use cases, providers, and frameworks. You can use these templates to get started with your AI-powered application. Starter Kits Chatbot Starter TemplateUses the AI SDK and Next.js. Features persistence, multi-modal chat, and more.eve ChatA persisted AI SDK chat app powered by eve with durable agent sessions, tools, and integrations.Internal Knowledge Base (RAG)Uses AI SDK Language Model Middleware for RAG and enforcing guardrails.Multi-Modal ChatUses Next.js and AI SDK useChat hook for multi-modal message chat interface.Semantic Image SearchAn AI semantic image search app template built with Next.js, AI SDK, and Postgres.Natural Language PostgreSQLQuery PostgreSQL using natural language with AI SDK and GPT-4o. Feature Exploration Feature Flags ExampleAI SDK with Next.js, Feature Flags, and Edge Config for dynamic model switching.Chatbot with TelemetryAI SDK chatbot with OpenTelemetry support.Structured Object StreamingUses AI SDK useObject hook to stream structured object generation.Multi-Step ToolsUses AI SDK streamText function to handle multiple tool steps automatically. Frameworks Next.js OpenAI StarterUses OpenAI GPT-4, AI SDK, and Next.js.Nuxt OpenAI StarterUses OpenAI GPT-4, AI SDK, and Nuxt.js.SvelteKit OpenAI StarterUses OpenAI GPT-4, AI SDK, and SvelteKit.Solid OpenAI StarterUses OpenAI GPT-4, AI SDK, and Solid. Generative UI Gemini ChatbotUses Google Gemini, AI SDK, and Next.js.Generative UI with RSC (experimental)Uses Next.js, AI SDK, and streamUI to create generative UIs with React Server Components. Security Bot ProtectionUses Kasada, OpenAI GPT-4, AI SDK, and Next.js.Rate LimitingUses Vercel KV, OpenAI GPT-4, AI SDK, and Next.js. Join our Community If you have questions about anything related to the AI SDK, you're always welcome to ask our community on the Vercel Community. llms.txt (for Cursor, Windsurf, Copilot, Claude etc.) You can access the entire AI SDK documentation in Markdown format at ai-sdk.dev/llms.txt. This can be used to ask any LLM (assuming it has a big enough context window) questions about the AI SDK based on the most up-to-date documentation. Example Usage For instance, to prompt an LLM with questions about the AI SDK: Copy the documentation contents from ai-sdk.dev/llms.txt Use the following prompt format: Documentation: {paste documentation here} --- Based on the above documentation, answer the following: {your question}NextOverview