
# AI SDK

The 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](/docs/foundations/providers-and-models). This enables developers to focus on building great AI applications, not waste time on technical details.

For example, here’s how you can generate text with various models using the AI SDK:

<PreviewSwitchProviders />

The AI SDK has two main libraries:

- **[AI SDK Core](/docs/ai-sdk-core):** A unified API for generating text, structured objects, tool calls, and building agents with LLMs.
- **[AI SDK UI](/docs/ai-sdk-ui):** A set of framework-agnostic hooks for quickly building chat and generative user interface.

## Model Providers

The AI SDK supports [multiple model providers](/providers).

<OfficialModelCards />

## Templates

We've built some [templates](https://vercel.com/templates?type=ai) 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

<Templates type="starter-kits" />

### Feature Exploration

<Templates type="feature-exploration" />

### Frameworks

<Templates type="frameworks" />

### Generative UI

<Templates type="generative-ui" />

### Security

<Templates type="security" />

## 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](https://community.vercel.com/c/ai-sdk/62).

## `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](/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:

1. Copy the documentation contents from [ai-sdk.dev/llms.txt](/llms.txt)
2. Use the following prompt format:

```prompt
Documentation:
{paste documentation here}
---
Based on the above documentation, answer the following:
{your question}
```


## Navigation

- [AI SDK by Vercel](/docs/introduction)
- [Foundations](/docs/foundations)
  - [Overview](/docs/foundations/overview)
  - [Providers and Models](/docs/foundations/providers-and-models)
  - [Prompts](/docs/foundations/prompts)
  - [Tools](/docs/foundations/tools)
  - [Streaming](/docs/foundations/streaming)
  - [Provider Options](/docs/foundations/provider-options)
- [Getting Started](/docs/getting-started)
  - [Choosing a Provider](/docs/getting-started/choosing-a-provider)
  - [Navigating the Library](/docs/getting-started/navigating-the-library)
  - [Next.js App Router](/docs/getting-started/nextjs-app-router)
  - [Next.js Pages Router](/docs/getting-started/nextjs-pages-router)
  - [Svelte](/docs/getting-started/svelte)
  - [Vue.js (Nuxt)](/docs/getting-started/nuxt)
  - [Node.js](/docs/getting-started/nodejs)
  - [Expo](/docs/getting-started/expo)
  - [TanStack Start](/docs/getting-started/tanstack-start)
  - [Coding Agents](/docs/getting-started/coding-agents)
- [Agents](/docs/agents)
  - [Overview](/docs/agents/overview)
  - [Building Agents](/docs/agents/building-agents)
  - [Workflow Patterns](/docs/agents/workflows)
  - [Loop Control](/docs/agents/loop-control)
  - [Configuring Call Options](/docs/agents/configuring-call-options)
  - [Memory](/docs/agents/memory)
  - [Subagents](/docs/agents/subagents)
- [AI SDK Core](/docs/ai-sdk-core)
  - [Overview](/docs/ai-sdk-core/overview)
  - [Generating Text](/docs/ai-sdk-core/generating-text)
  - [Generating Structured Data](/docs/ai-sdk-core/generating-structured-data)
  - [Tool Calling](/docs/ai-sdk-core/tools-and-tool-calling)
  - [Model Context Protocol (MCP)](/docs/ai-sdk-core/mcp-tools)
  - [Prompt Engineering](/docs/ai-sdk-core/prompt-engineering)
  - [Settings](/docs/ai-sdk-core/settings)
  - [Embeddings](/docs/ai-sdk-core/embeddings)
  - [Reranking](/docs/ai-sdk-core/reranking)
  - [Image Generation](/docs/ai-sdk-core/image-generation)
  - [Transcription](/docs/ai-sdk-core/transcription)
  - [Speech](/docs/ai-sdk-core/speech)
  - [Video Generation](/docs/ai-sdk-core/video-generation)
  - [Language Model Middleware](/docs/ai-sdk-core/middleware)
  - [Provider & Model Management](/docs/ai-sdk-core/provider-management)
  - [Error Handling](/docs/ai-sdk-core/error-handling)
  - [Testing](/docs/ai-sdk-core/testing)
  - [Telemetry](/docs/ai-sdk-core/telemetry)
  - [DevTools](/docs/ai-sdk-core/devtools)
  - [Event Callbacks](/docs/ai-sdk-core/event-listeners)
- [AI SDK UI](/docs/ai-sdk-ui)
  - [Overview](/docs/ai-sdk-ui/overview)
  - [Chatbot](/docs/ai-sdk-ui/chatbot)
  - [Chatbot Message Persistence](/docs/ai-sdk-ui/chatbot-message-persistence)
  - [Chatbot Resume Streams](/docs/ai-sdk-ui/chatbot-resume-streams)
  - [Chatbot Tool Usage](/docs/ai-sdk-ui/chatbot-tool-usage)
  - [Generative User Interfaces](/docs/ai-sdk-ui/generative-user-interfaces)
  - [Completion](/docs/ai-sdk-ui/completion)
  - [Object Generation](/docs/ai-sdk-ui/object-generation)
  - [Streaming Custom Data](/docs/ai-sdk-ui/streaming-data)
  - [Error Handling](/docs/ai-sdk-ui/error-handling)
  - [Transport](/docs/ai-sdk-ui/transport)
  - [Reading UIMessage Streams](/docs/ai-sdk-ui/reading-ui-message-streams)
  - [Message Metadata](/docs/ai-sdk-ui/message-metadata)
  - [Stream Protocols](/docs/ai-sdk-ui/stream-protocol)
- [AI SDK RSC](/docs/ai-sdk-rsc)
  - [Overview](/docs/ai-sdk-rsc/overview)
  - [Streaming React Components](/docs/ai-sdk-rsc/streaming-react-components)
  - [Managing Generative UI State](/docs/ai-sdk-rsc/generative-ui-state)
  - [Saving and Restoring States](/docs/ai-sdk-rsc/saving-and-restoring-states)
  - [Multistep Interfaces](/docs/ai-sdk-rsc/multistep-interfaces)
  - [Streaming Values](/docs/ai-sdk-rsc/streaming-values)
  - [Handling Loading State](/docs/ai-sdk-rsc/loading-state)
  - [Error Handling](/docs/ai-sdk-rsc/error-handling)
  - [Handling Authentication](/docs/ai-sdk-rsc/authentication)
  - [Migrating from RSC to UI](/docs/ai-sdk-rsc/migrating-to-ui)
- [Advanced](/docs/advanced)
  - [Prompt Engineering](/docs/advanced/prompt-engineering)
  - [Stopping Streams](/docs/advanced/stopping-streams)
  - [Backpressure](/docs/advanced/backpressure)
  - [Caching](/docs/advanced/caching)
  - [Multiple Streamables](/docs/advanced/multiple-streamables)
  - [Rate Limiting](/docs/advanced/rate-limiting)
  - [Rendering UI with Language Models](/docs/advanced/rendering-ui-with-language-models)
  - [Language Models as Routers](/docs/advanced/model-as-router)
  - [Multistep Interfaces](/docs/advanced/multistep-interfaces)
  - [Sequential Generations](/docs/advanced/sequential-generations)
  - [Vercel Deployment Guide](/docs/advanced/vercel-deployment-guide)
- [Reference](/docs/reference)
  - [AI SDK Core](/docs/reference/ai-sdk-core)
    - [generateText](/docs/reference/ai-sdk-core/generate-text)
    - [streamText](/docs/reference/ai-sdk-core/stream-text)
    - [embed](/docs/reference/ai-sdk-core/embed)
    - [embedMany](/docs/reference/ai-sdk-core/embed-many)
    - [rerank](/docs/reference/ai-sdk-core/rerank)
    - [generateImage](/docs/reference/ai-sdk-core/generate-image)
    - [transcribe](/docs/reference/ai-sdk-core/transcribe)
    - [generateSpeech](/docs/reference/ai-sdk-core/generate-speech)
    - [experimental_generateVideo](/docs/reference/ai-sdk-core/generate-video)
    - [Agent (Interface)](/docs/reference/ai-sdk-core/agent)
    - [ToolLoopAgent](/docs/reference/ai-sdk-core/tool-loop-agent)
    - [createAgentUIStream](/docs/reference/ai-sdk-core/create-agent-ui-stream)
    - [createAgentUIStreamResponse](/docs/reference/ai-sdk-core/create-agent-ui-stream-response)
    - [pipeAgentUIStreamToResponse](/docs/reference/ai-sdk-core/pipe-agent-ui-stream-to-response)
    - [tool](/docs/reference/ai-sdk-core/tool)
    - [dynamicTool](/docs/reference/ai-sdk-core/dynamic-tool)
    - [createMCPClient](/docs/reference/ai-sdk-core/create-mcp-client)
    - [Experimental_StdioMCPTransport](/docs/reference/ai-sdk-core/mcp-stdio-transport)
    - [jsonSchema](/docs/reference/ai-sdk-core/json-schema)
    - [zodSchema](/docs/reference/ai-sdk-core/zod-schema)
    - [valibotSchema](/docs/reference/ai-sdk-core/valibot-schema)
    - [Output](/docs/reference/ai-sdk-core/output)
    - [ModelMessage](/docs/reference/ai-sdk-core/model-message)
    - [UIMessage](/docs/reference/ai-sdk-core/ui-message)
    - [validateUIMessages](/docs/reference/ai-sdk-core/validate-ui-messages)
    - [safeValidateUIMessages](/docs/reference/ai-sdk-core/safe-validate-ui-messages)
    - [createProviderRegistry](/docs/reference/ai-sdk-core/provider-registry)
    - [customProvider](/docs/reference/ai-sdk-core/custom-provider)
    - [cosineSimilarity](/docs/reference/ai-sdk-core/cosine-similarity)
    - [wrapLanguageModel](/docs/reference/ai-sdk-core/wrap-language-model)
    - [wrapImageModel](/docs/reference/ai-sdk-core/wrap-image-model)
    - [LanguageModelV3Middleware](/docs/reference/ai-sdk-core/language-model-v2-middleware)
    - [extractReasoningMiddleware](/docs/reference/ai-sdk-core/extract-reasoning-middleware)
    - [simulateStreamingMiddleware](/docs/reference/ai-sdk-core/simulate-streaming-middleware)
    - [defaultSettingsMiddleware](/docs/reference/ai-sdk-core/default-settings-middleware)
    - [addToolInputExamplesMiddleware](/docs/reference/ai-sdk-core/add-tool-input-examples-middleware)
    - [extractJsonMiddleware](/docs/reference/ai-sdk-core/extract-json-middleware)
    - [stepCountIs](/docs/reference/ai-sdk-core/step-count-is)
    - [hasToolCall](/docs/reference/ai-sdk-core/has-tool-call)
    - [isLoopFinished](/docs/reference/ai-sdk-core/loop-finished)
    - [simulateReadableStream](/docs/reference/ai-sdk-core/simulate-readable-stream)
    - [smoothStream](/docs/reference/ai-sdk-core/smooth-stream)
    - [generateId](/docs/reference/ai-sdk-core/generate-id)
    - [createIdGenerator](/docs/reference/ai-sdk-core/create-id-generator)
    - [DefaultGeneratedFile](/docs/reference/ai-sdk-core/default-generated-file)
  - [AI SDK UI](/docs/reference/ai-sdk-ui)
    - [useChat](/docs/reference/ai-sdk-ui/use-chat)
    - [useCompletion](/docs/reference/ai-sdk-ui/use-completion)
    - [useObject](/docs/reference/ai-sdk-ui/use-object)
    - [convertToModelMessages](/docs/reference/ai-sdk-ui/convert-to-model-messages)
    - [pruneMessages](/docs/reference/ai-sdk-ui/prune-messages)
    - [createUIMessageStream](/docs/reference/ai-sdk-ui/create-ui-message-stream)
    - [createUIMessageStreamResponse](/docs/reference/ai-sdk-ui/create-ui-message-stream-response)
    - [pipeUIMessageStreamToResponse](/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response)
    - [readUIMessageStream](/docs/reference/ai-sdk-ui/read-ui-message-stream)
    - [InferUITools](/docs/reference/ai-sdk-ui/infer-ui-tools)
    - [InferUITool](/docs/reference/ai-sdk-ui/infer-ui-tool)
    - [DirectChatTransport](/docs/reference/ai-sdk-ui/direct-chat-transport)
  - [AI SDK RSC](/docs/reference/ai-sdk-rsc)
    - [streamUI](/docs/reference/ai-sdk-rsc/stream-ui)
    - [createAI](/docs/reference/ai-sdk-rsc/create-ai)
    - [createStreamableUI](/docs/reference/ai-sdk-rsc/create-streamable-ui)
    - [createStreamableValue](/docs/reference/ai-sdk-rsc/create-streamable-value)
    - [readStreamableValue](/docs/reference/ai-sdk-rsc/read-streamable-value)
    - [getAIState](/docs/reference/ai-sdk-rsc/get-ai-state)
    - [getMutableAIState](/docs/reference/ai-sdk-rsc/get-mutable-ai-state)
    - [useAIState](/docs/reference/ai-sdk-rsc/use-ai-state)
    - [useActions](/docs/reference/ai-sdk-rsc/use-actions)
    - [useUIState](/docs/reference/ai-sdk-rsc/use-ui-state)
    - [useStreamableValue](/docs/reference/ai-sdk-rsc/use-streamable-value)
    - [render (Removed)](/docs/reference/ai-sdk-rsc/render)
  - [AI SDK Errors](/docs/reference/ai-sdk-errors)
    - [AI_APICallError](/docs/reference/ai-sdk-errors/ai-api-call-error)
    - [AI_DownloadError](/docs/reference/ai-sdk-errors/ai-download-error)
    - [AI_EmptyResponseBodyError](/docs/reference/ai-sdk-errors/ai-empty-response-body-error)
    - [AI_InvalidArgumentError](/docs/reference/ai-sdk-errors/ai-invalid-argument-error)
    - [AI_InvalidDataContentError](/docs/reference/ai-sdk-errors/ai-invalid-data-content-error)
    - [AI_InvalidMessageRoleError](/docs/reference/ai-sdk-errors/ai-invalid-message-role-error)
    - [AI_InvalidPromptError](/docs/reference/ai-sdk-errors/ai-invalid-prompt-error)
    - [AI_InvalidResponseDataError](/docs/reference/ai-sdk-errors/ai-invalid-response-data-error)
    - [AI_InvalidToolApprovalError](/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error)
    - [AI_InvalidToolInputError](/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error)
    - [AI_JSONParseError](/docs/reference/ai-sdk-errors/ai-json-parse-error)
    - [AI_LoadAPIKeyError](/docs/reference/ai-sdk-errors/ai-load-api-key-error)
    - [AI_LoadSettingError](/docs/reference/ai-sdk-errors/ai-load-setting-error)
    - [AI_MessageConversionError](/docs/reference/ai-sdk-errors/ai-message-conversion-error)
    - [AI_NoContentGeneratedError](/docs/reference/ai-sdk-errors/ai-no-content-generated-error)
    - [AI_NoImageGeneratedError](/docs/reference/ai-sdk-errors/ai-no-image-generated-error)
    - [AI_NoObjectGeneratedError](/docs/reference/ai-sdk-errors/ai-no-object-generated-error)
    - [AI_NoOutputGeneratedError](/docs/reference/ai-sdk-errors/ai-no-output-generated-error)
    - [AI_NoSpeechGeneratedError](/docs/reference/ai-sdk-errors/ai-no-speech-generated-error)
    - [AI_NoSuchModelError](/docs/reference/ai-sdk-errors/ai-no-such-model-error)
    - [AI_NoSuchProviderError](/docs/reference/ai-sdk-errors/ai-no-such-provider-error)
    - [AI_NoSuchToolError](/docs/reference/ai-sdk-errors/ai-no-such-tool-error)
    - [AI_NoTranscriptGeneratedError](/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error)
    - [AI_NoVideoGeneratedError](/docs/reference/ai-sdk-errors/ai-no-video-generated-error)
    - [AI_RetryError](/docs/reference/ai-sdk-errors/ai-retry-error)
    - [AI_TooManyEmbeddingValuesForCallError](/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error)
    - [AI_ToolCallNotFoundForApprovalError](/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error)
    - [ToolCallRepairError](/docs/reference/ai-sdk-errors/ai-tool-call-repair-error)
    - [AI_TypeValidationError](/docs/reference/ai-sdk-errors/ai-type-validation-error)
    - [AI_UIMessageStreamError](/docs/reference/ai-sdk-errors/ai-ui-message-stream-error)
    - [AI_UnsupportedFunctionalityError](/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error)
- [Migration Guides](/docs/migration-guides)
  - [Versioning](/docs/migration-guides/versioning)
  - [Migrate AI SDK 5.x to 6.0](/docs/migration-guides/migration-guide-6-0)
  - [Migrate Your Data to AI SDK 5.0](/docs/migration-guides/migration-guide-5-0-data)
  - [Migrate AI SDK 4.x to 5.0](/docs/migration-guides/migration-guide-5-0)
  - [Migrate AI SDK 4.1 to 4.2](/docs/migration-guides/migration-guide-4-2)
  - [Migrate AI SDK 4.0 to 4.1](/docs/migration-guides/migration-guide-4-1)
  - [Migrate AI SDK 3.4 to 4.0](/docs/migration-guides/migration-guide-4-0)
  - [Migrate AI SDK 3.3 to 3.4](/docs/migration-guides/migration-guide-3-4)
  - [Migrate AI SDK 3.2 to 3.3](/docs/migration-guides/migration-guide-3-3)
  - [Migrate AI SDK 3.1 to 3.2](/docs/migration-guides/migration-guide-3-2)
  - [Migrate AI SDK 3.0 to 3.1](/docs/migration-guides/migration-guide-3-1)
- [Troubleshooting](/docs/troubleshooting)
  - [Azure OpenAI Slow to Stream](/docs/troubleshooting/azure-stream-slow)
  - [Server Actions in Client Components](/docs/troubleshooting/server-actions-in-client-components)
  - [useChat/useCompletion stream output contains 0:... instead of text](/docs/troubleshooting/strange-stream-output)
  - [Streamable UI Errors](/docs/troubleshooting/streamable-ui-errors)
  - [Tool Invocation Missing Result Error](/docs/troubleshooting/tool-invocation-missing-result)
  - [Streaming Not Working When Deployed](/docs/troubleshooting/streaming-not-working-when-deployed)
  - [Streaming Not Working When Proxied](/docs/troubleshooting/streaming-not-working-when-proxied)
  - [Getting Timeouts When Deploying on Vercel](/docs/troubleshooting/timeout-on-vercel)
  - [Unclosed Streams](/docs/troubleshooting/unclosed-streams)
  - [useChat Failed to Parse Stream](/docs/troubleshooting/use-chat-failed-to-parse-stream)
  - [Server Action Plain Objects Error](/docs/troubleshooting/client-stream-error)
  - [useChat No Response](/docs/troubleshooting/use-chat-tools-no-response)
  - [Custom headers, body, and credentials not working with useChat](/docs/troubleshooting/use-chat-custom-request-options)
  - [TypeScript performance issues with Zod and AI SDK 5](/docs/troubleshooting/typescript-performance-zod)
  - [useChat "An error occurred"](/docs/troubleshooting/use-chat-an-error-occurred)
  - [Repeated assistant messages in useChat](/docs/troubleshooting/repeated-assistant-messages)
  - [onFinish not called when stream is aborted](/docs/troubleshooting/stream-abort-handling)
  - [Tool calling with structured outputs](/docs/troubleshooting/tool-calling-with-structured-outputs)
  - [Abort breaks resumable streams](/docs/troubleshooting/abort-breaks-resumable-streams)
  - [streamText fails silently](/docs/troubleshooting/stream-text-not-working)
  - [Streaming Status Shows But No Text Appears](/docs/troubleshooting/streaming-status-delay)
  - [Stale body values with useChat](/docs/troubleshooting/use-chat-stale-body-data)
  - [Type Error with onToolCall](/docs/troubleshooting/ontoolcall-type-narrowing)
  - [Unsupported model version error](/docs/troubleshooting/unsupported-model-version)
  - [Object generation failed with OpenAI](/docs/troubleshooting/no-object-generated-content-filter)
  - [Missing Tool Results Error](/docs/troubleshooting/missing-tool-results-error)
  - [Model is not assignable to type "LanguageModelV1"](/docs/troubleshooting/model-is-not-assignable-to-type)
  - [TypeScript error "Cannot find namespace 'JSX'"](/docs/troubleshooting/typescript-cannot-find-namespace-jsx)
  - [React error "Maximum update depth exceeded"](/docs/troubleshooting/react-maximum-update-depth-exceeded)
  - [Jest: cannot find module '@ai-sdk/rsc'](/docs/troubleshooting/jest-cannot-find-module-ai-rsc)
  - [High memory usage when processing many images](/docs/troubleshooting/high-memory-usage-with-images)


[Full Sitemap](/sitemap.md)
