# Table of Contents - [AI SDK by Vercel](#ai-sdk-by-vercel) - [Foundations](#foundations) - [AI SDK UI: readUIMessageStream](#ai-sdk-ui-readuimessagestream) - [AI SDK RSC: useAIState](#ai-sdk-rsc-useaistate) - [AI SDK UI: pipeUIMessageStreamToResponse](#ai-sdk-ui-pipeuimessagestreamtoresponse) - [AI SDK RSC: useUIState](#ai-sdk-rsc-useuistate) - [AI SDK RSC: createAI](#ai-sdk-rsc-createai) - [AI SDK RSC: useStreamableValue](#ai-sdk-rsc-usestreamablevalue) - [AI SDK UI: useCompletion](#ai-sdk-ui-usecompletion) - [Reference: AI SDK UI](#reference-ai-sdk-ui) - [AI SDK UI: createUIMessageStreamResponse](#ai-sdk-ui-createuimessagestreamresponse) - [AI SDK UI: InferUITools](#ai-sdk-ui-inferuitools) - [AI SDK UI: createUIMessageStream](#ai-sdk-ui-createuimessagestream) - [AI SDK RSC: createStreamableValue](#ai-sdk-rsc-createstreamablevalue) - [AI SDK RSC: createStreamableUI](#ai-sdk-rsc-createstreamableui) - [AI SDK RSC: getMutableAIState](#ai-sdk-rsc-getmutableaistate) - [AI SDK RSC: readStreamableValue](#ai-sdk-rsc-readstreamablevalue) - [AI SDK RSC: render (Removed)](#ai-sdk-rsc-render-removed-) - [AI SDK UI: InferUITool](#ai-sdk-ui-inferuitool) - [Reference: AI SDK RSC](#reference-ai-sdk-rsc) - [AI SDK RSC: getAIState](#ai-sdk-rsc-getaistate) - [AI SDK UI: useObject](#ai-sdk-ui-useobject) - [AI SDK UI: pruneMessages](#ai-sdk-ui-prunemessages) - [AI SDK UI: useChat](#ai-sdk-ui-usechat) - [AI SDK RSC: streamUI](#ai-sdk-rsc-streamui) - [AI SDK UI: convertToModelMessages](#ai-sdk-ui-converttomodelmessages) - [AI SDK UI: DirectChatTransport](#ai-sdk-ui-directchattransport) - [AI SDK RSC: useActions](#ai-sdk-rsc-useactions) - [AI SDK Errors: AI_InvalidDataContentError](#ai-sdk-errors-ai-invaliddatacontenterror) - [AI SDK Errors: AI_EmptyResponseBodyError](#ai-sdk-errors-ai-emptyresponsebodyerror) - [AI SDK Errors: AI_LoadAPIKeyError](#ai-sdk-errors-ai-loadapikeyerror) - [AI SDK Errors: AI_MessageConversionError](#ai-sdk-errors-ai-messageconversionerror) - [AI SDK Errors: AI_APICallError](#ai-sdk-errors-ai-apicallerror) - [AI SDK Errors: AI_InvalidArgumentError](#ai-sdk-errors-ai-invalidargumenterror) - [AI SDK Errors: AI_DownloadError](#ai-sdk-errors-ai-downloaderror) - [AI SDK Errors: AI_InvalidResponseDataError](#ai-sdk-errors-ai-invalidresponsedataerror) - [AI SDK Errors: AI_InvalidMessageRoleError](#ai-sdk-errors-ai-invalidmessageroleerror) - [AI SDK Errors: AI_JSONParseError](#ai-sdk-errors-ai-jsonparseerror) - [AI SDK Errors: AI_InvalidToolInputError](#ai-sdk-errors-ai-invalidtoolinputerror) - [AI SDK Errors: AI_LoadSettingError](#ai-sdk-errors-ai-loadsettingerror) - [AI SDK Errors: AI_NoImageGeneratedError](#ai-sdk-errors-ai-noimagegeneratederror) - [AI SDK Errors: AI_NoContentGeneratedError](#ai-sdk-errors-ai-nocontentgeneratederror) - [AI SDK Errors: AI_InvalidPromptError](#ai-sdk-errors-ai-invalidprompterror) - [AI SDK Errors: AI_NoOutputGeneratedError](#ai-sdk-errors-ai-nooutputgeneratederror) - [AI SDK Errors: AI_NoSpeechGeneratedError](#ai-sdk-errors-ai-nospeechgeneratederror) - [AI SDK Errors: AI_NoSuchModelError](#ai-sdk-errors-ai-nosuchmodelerror) - [AI SDK Errors: AI_NoTranscriptGeneratedError](#ai-sdk-errors-ai-notranscriptgeneratederror) - [AI SDK Errors: AI_NoSuchProviderError](#ai-sdk-errors-ai-nosuchprovidererror) - [AI SDK Errors: AI_TooManyEmbeddingValuesForCallError](#ai-sdk-errors-ai-toomanyembeddingvaluesforcallerror) - [AI SDK Errors: AI_TypeValidationError](#ai-sdk-errors-ai-typevalidationerror) - [AI SDK Errors: AI_InvalidToolApprovalError](#ai-sdk-errors-ai-invalidtoolapprovalerror) - [AI SDK Errors: AI_ToolCallNotFoundForApprovalError](#ai-sdk-errors-ai-toolcallnotfoundforapprovalerror) - [AI SDK Errors: AI_UnsupportedFunctionalityError](#ai-sdk-errors-ai-unsupportedfunctionalityerror) - [AI SDK Errors: AI_NoObjectGeneratedError](#ai-sdk-errors-ai-noobjectgeneratederror) - [AI SDK Errors: AI_NoSuchToolError](#ai-sdk-errors-ai-nosuchtoolerror) - [AI SDK Errors: AI_RetryError](#ai-sdk-errors-ai-retryerror) - [Troubleshooting: Azure OpenAI Slow to Stream](#troubleshooting-azure-openai-slow-to-stream) - [AI SDK Errors: ToolCallRepairError](#ai-sdk-errors-toolcallrepairerror) - [AI SDK Errors: AI_UIMessageStreamError](#ai-sdk-errors-ai-uimessagestreamerror) - [Troubleshooting: Model is not assignable to type "LanguageModelV1"](#troubleshooting-model-is-not-assignable-to-type-languagemodelv1-) - [Troubleshooting: React error "Maximum update depth exceeded"](#troubleshooting-react-error-maximum-update-depth-exceeded-) - [Troubleshooting: Object generation failed with OpenAI](#troubleshooting-object-generation-failed-with-openai) - [Troubleshooting](#troubleshooting) - [Troubleshooting: Streaming Not Working When Deployed](#troubleshooting-streaming-not-working-when-deployed) - [Troubleshooting: Missing Tool Results Error](#troubleshooting-missing-tool-results-error) - [Troubleshooting: Streamable UI Errors](#troubleshooting-streamable-ui-errors) - [Troubleshooting: Streaming Not Working When Proxied](#troubleshooting-streaming-not-working-when-proxied) - [Troubleshooting: TypeScript error "Cannot find namespace 'JSX'"](#troubleshooting-typescript-error-cannot-find-namespace-jsx-) - [Troubleshooting: Jest: cannot find module '@ai-sdk/rsc'](#troubleshooting-jest-cannot-find-module-ai-sdk-rsc-) - [Troubleshooting: Repeated assistant messages in useChat](#troubleshooting-repeated-assistant-messages-in-usechat) - [Troubleshooting: Streaming Status Shows But No Text Appears](#troubleshooting-streaming-status-shows-but-no-text-appears) - [Troubleshooting: useChat/useCompletion stream output contains 0:... instead of text](#troubleshooting-usechat-usecompletion-stream-output-contains-0-instead-of-text) - [Troubleshooting: Abort breaks resumable streams](#troubleshooting-abort-breaks-resumable-streams) - [Troubleshooting: Getting Timeouts When Deploying on Vercel](#troubleshooting-getting-timeouts-when-deploying-on-vercel) - [Troubleshooting: TypeScript performance issues with Zod and AI SDK 5](#troubleshooting-typescript-performance-issues-with-zod-and-ai-sdk-5) - [Troubleshooting: Tool Invocation Missing Result Error](#troubleshooting-tool-invocation-missing-result-error) - [Troubleshooting: Tool calling with generateObject and streamObject](#troubleshooting-tool-calling-with-generateobject-and-streamobject) - [Troubleshooting: onFinish not called when stream is aborted](#troubleshooting-onfinish-not-called-when-stream-is-aborted) - [Troubleshooting: streamText fails silently](#troubleshooting-streamtext-fails-silently) - [Troubleshooting: Unclosed Streams](#troubleshooting-unclosed-streams) - [Troubleshooting: Server Actions in Client Components](#troubleshooting-server-actions-in-client-components) - [Troubleshooting: Unsupported model version error](#troubleshooting-unsupported-model-version-error) - [Troubleshooting: useChat "An error occurred"](#troubleshooting-usechat-an-error-occurred-) - [Troubleshooting: Server Action Plain Objects Error](#troubleshooting-server-action-plain-objects-error) - [Troubleshooting: useChat Failed to Parse Stream](#troubleshooting-usechat-failed-to-parse-stream) - [Troubleshooting: Custom headers, body, and credentials not working with useChat](#troubleshooting-custom-headers-body-and-credentials-not-working-with-usechat) - [Troubleshooting: Type Error with onToolCall](#troubleshooting-type-error-with-ontoolcall) - [Troubleshooting: Stale body values with useChat](#troubleshooting-stale-body-values-with-usechat) - [Troubleshooting: useChat No Response](#troubleshooting-usechat-no-response) - [Guides: RAG Agent](#guides-rag-agent) - [Guides: Multi-Modal Agent](#guides-multi-modal-agent) --- # AI SDK by Vercel [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) AI SDK by Vercel Copy markdown [AI SDK](https://ai-sdk.dev/docs/introduction#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?](https://ai-sdk.dev/docs/introduction#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](https://ai-sdk.dev/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: Gateway Provider Custom Claude Sonnet 4.5 1import { generateText } from "ai";2 3const { text } = await generateText({4 model: "anthropic/claude-sonnet-4.5",5 prompt: "What is love?",6}); 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 two main libraries: * **[AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) :** A unified API for generating text, structured objects, tool calls, and building agents with LLMs. * **[AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) :** A set of framework-agnostic hooks for quickly building chat and generative user interface. [Model Providers](https://ai-sdk.dev/docs/introduction#model-providers) ------------------------------------------------------------------------ The AI SDK supports [multiple model providers](https://ai-sdk.dev/providers) . [Vercel AI Gateway\ \ Image InputImage GenerationObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/ai-gateway) [OpenAI\ \ Image InputImage GenerationObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/openai) [Anthropic\ \ Image InputObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/anthropic) [Google Generative AI\ \ ![Google Generative AI logo](https://ai-sdk.dev/_next/image?url=%2Ficons%2Fgoogle.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)\ \ Image InputObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai) [xAI Grok\ \ Image InputImage GenerationObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/xai) [Azure\ \ ![Azure logo](https://ai-sdk.dev/_next/image?url=%2Ficons%2Fazure.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)\ \ Image InputObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/azure) [Amazon Bedrock\ \ Image InputImage GenerationObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/amazon-bedrock) [Groq\ \ Image InputObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/groq) [Fal AI\ \ Image Generation](https://ai-sdk.dev/providers/ai-sdk-providers/fal) [DeepInfra\ \ Image InputObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/deepinfra) [Google Vertex AI\ \ ![Google Vertex AI logo](https://ai-sdk.dev/_next/image?url=%2Ficons%2Fgoogle.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)\ \ Image InputImage GenerationObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/google-vertex) [Mistral\ \ ![Mistral logo](https://ai-sdk.dev/_next/image?url=%2Ficons%2Fmistral.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)\ \ Image InputObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/mistral) [Together.ai\ \ Object GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/togetherai) [Cohere\ \ ![Cohere logo](https://ai-sdk.dev/_next/image?url=%2Ficons%2Fcohere.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)\ \ Tool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/cohere) [Fireworks\ \ ![Fireworks logo](https://ai-sdk.dev/_next/image?url=%2Ficons%2Ffireworks.png&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)\ \ Image GenerationObject GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/fireworks) [DeepSeek\ \ ![DeepSeek logo](https://ai-sdk.dev/_next/image?url=%2Ficons%2Fdeepseek.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)\ \ Object GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/deepseek) [Cerebras\ \ Object GenerationTool UsageTool Streaming](https://ai-sdk.dev/providers/ai-sdk-providers/cerebras) [Perplexity\ \ ![Perplexity logo](https://ai-sdk.dev/_next/image?url=%2Ficons%2Fperplexity.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)](https://ai-sdk.dev/providers/ai-sdk-providers/perplexity) [Luma AI\ \ ![Luma AI logo](https://ai-sdk.dev/_next/image?url=%2Ficons%2Fluma.png&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)\ \ Image Generation](https://ai-sdk.dev/providers/ai-sdk-providers/luma) [Baseten\ \ ![Baseten logo](https://ai-sdk.dev/_next/image?url=%2Ficons%2Fbaseten.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)\ \ Object GenerationTool Usage](https://ai-sdk.dev/providers/ai-sdk-providers/baseten) [Templates](https://ai-sdk.dev/docs/introduction#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](https://ai-sdk.dev/docs/introduction#starter-kits) [Chatbot Starter Template\ \ Uses the AI SDK and Next.js. Features persistence, multi-modal chat, and more.](https://vercel.com/templates/next.js/nextjs-ai-chatbot) [Internal Knowledge Base (RAG)\ \ Uses AI SDK Language Model Middleware for RAG and enforcing guardrails.](https://vercel.com/templates/next.js/ai-sdk-internal-knowledge-base) [Multi-Modal Chat\ \ Uses Next.js and AI SDK useChat hook for multi-modal message chat interface.](https://vercel.com/templates/next.js/multi-modal-chatbot) [Semantic Image Search\ \ An AI semantic image search app template built with Next.js, AI SDK, and Postgres.](https://vercel.com/templates/next.js/semantic-image-search) [Natural Language PostgreSQL\ \ Query PostgreSQL using natural language with AI SDK and GPT-4o.](https://vercel.com/templates/next.js/natural-language-postgres) ### [Feature Exploration](https://ai-sdk.dev/docs/introduction#feature-exploration) [Feature Flags Example\ \ AI SDK with Next.js, Feature Flags, and Edge Config for dynamic model switching.](https://vercel.com/templates/next.js/ai-sdk-feature-flags-edge-config) [Chatbot with Telemetry\ \ AI SDK chatbot with OpenTelemetry support.](https://vercel.com/templates/next.js/ai-chatbot-telemetry) [Structured Object Streaming\ \ Uses AI SDK useObject hook to stream structured object generation.](https://vercel.com/templates/next.js/use-object) [Multi-Step Tools\ \ Uses AI SDK streamText function to handle multiple tool steps automatically.](https://vercel.com/templates/next.js/ai-sdk-roundtrips) ### [Frameworks](https://ai-sdk.dev/docs/introduction#frameworks) [Next.js OpenAI Starter\ \ Uses OpenAI GPT-4, AI SDK, and Next.js.](https://github.com/vercel/ai/tree/main/examples/next-openai) [Nuxt OpenAI Starter\ \ Uses OpenAI GPT-4, AI SDK, and Nuxt.js.](https://github.com/vercel/ai/tree/main/examples/nuxt-openai) [SvelteKit OpenAI Starter\ \ Uses OpenAI GPT-4, AI SDK, and SvelteKit.](https://github.com/vercel/ai/tree/main/examples/sveltekit-openai) [Solid OpenAI Starter\ \ Uses OpenAI GPT-4, AI SDK, and Solid.](https://github.com/vercel/ai/tree/main/examples/solidstart-openai) ### [Generative UI](https://ai-sdk.dev/docs/introduction#generative-ui) [Gemini Chatbot\ \ Uses Google Gemini, AI SDK, and Next.js.](https://vercel.com/templates/next.js/gemini-ai-chatbot) [Generative UI with RSC (experimental)\ \ Uses Next.js, AI SDK, and streamUI to create generative UIs with React Server Components.](https://vercel.com/templates/next.js/rsc-genui) ### [Security](https://ai-sdk.dev/docs/introduction#security) [Bot Protection\ \ Uses Kasada, OpenAI GPT-4, AI SDK, and Next.js.](https://vercel.com/templates/next.js/advanced-ai-bot-protection) [Rate Limiting\ \ Uses Vercel KV, OpenAI GPT-4, AI SDK, and Next.js.](https://github.com/vercel/ai/tree/main/examples/next-openai-upstash-rate-limits) [Join our Community](https://ai-sdk.dev/docs/introduction#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.)](https://ai-sdk.dev/docs/introduction#llmstxt-for-cursor-windsurf-copilot-claude-etc) ----------------------------------------------------------------------------------------------------------------------------------------------- You can access the entire AI SDK documentation in Markdown format at [ai-sdk.dev/llms.txt](https://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](https://ai-sdk.dev/docs/introduction#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](https://ai-sdk.dev/llms.txt) 2. Use the following prompt format: 1Documentation:2{paste documentation here}3---4Based on the above documentation, answer the following:5{your question} On this page [AI SDK](https://ai-sdk.dev/docs/introduction#ai-sdk) [Why use the AI SDK?](https://ai-sdk.dev/docs/introduction#why-use-the-ai-sdk) [Model Providers](https://ai-sdk.dev/docs/introduction#model-providers) [Templates](https://ai-sdk.dev/docs/introduction#templates) [Starter Kits](https://ai-sdk.dev/docs/introduction#starter-kits) [Feature Exploration](https://ai-sdk.dev/docs/introduction#feature-exploration) [Frameworks](https://ai-sdk.dev/docs/introduction#frameworks) [Generative UI](https://ai-sdk.dev/docs/introduction#generative-ui) [Security](https://ai-sdk.dev/docs/introduction#security) [Join our Community](https://ai-sdk.dev/docs/introduction#join-our-community) [llms.txt (for Cursor, Windsurf, Copilot, Claude etc.)](https://ai-sdk.dev/docs/introduction#llmstxt-for-cursor-windsurf-copilot-claude-etc) [Example Usage](https://ai-sdk.dev/docs/introduction#example-usage) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Foundations [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Foundations Copy markdown [Foundations](https://ai-sdk.dev/docs/foundations#foundations) =============================================================== [Overview\ \ Learn about foundational concepts around AI and LLMs.](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models\ \ Learn about the providers and models that you can use with the AI SDK.](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts\ \ Learn about how Prompts are used and defined in the AI SDK.](https://ai-sdk.dev/docs/foundations/prompts) [Tools\ \ Learn about tools in the AI SDK.](https://ai-sdk.dev/docs/foundations/tools) [Streaming\ \ Learn why streaming is used for AI applications.](https://ai-sdk.dev/docs/foundations/streaming) [Agents\ \ Learn how to build agents with the AI SDK.](https://ai-sdk.dev/docs/agents) On this page [Foundations](https://ai-sdk.dev/docs/foundations#foundations) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: readUIMessageStream [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream#readuimessagestream) ============================================================================================================== Transforms a stream of `UIMessageChunk`s into an `AsyncIterableStream` of `UIMessage`s. UI message streams are useful outside of Chat use cases, e.g. for terminal UIs, custom stream consumption on the client, or RSC (React Server Components). [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream#import) ------------------------------------------------------------------------------------ 1import { readUIMessageStream } from 'ai'; [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream#api-signature) -------------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream#parameters) ### message?: UIMessage The last assistant message to use as a starting point when the conversation is resumed. Otherwise undefined. ### stream: ReadableStream The stream of UIMessageChunk objects to read. ### onError?: (error: unknown) => void A function that is called when an error occurs during stream processing. ### terminateOnError?: boolean Whether to terminate the stream if an error occurs. Defaults to false. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream#returns) An `AsyncIterableStream` of `UIMessage`s. Each stream part represents a different state of the same message as it is being completed. For comprehensive examples and use cases, see [Reading UI Message Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) . On this page [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream#readuimessagestream) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream#returns) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: useAIState [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`useAIState`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state#useaistate) ===================================================================================== AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . It is a hook that enables you to read and update the AI state. The AI state is shared globally between all `useAIState` hooks under the same `` provider. The AI state is intended to contain context and information shared with the AI model, such as system messages, function responses, and other relevant data. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state#import) --------------------------------------------------------------------------- import { useAIState } from "@ai-sdk/rsc" [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state#api-signature) ----------------------------------------------------------------------------------------- ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state#returns) Similar to useState, it is an array where the first element is the current AI state and the second element is a function to update the state. On this page [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state#useaistate) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state#api-signature) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state#returns) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: pipeUIMessageStreamToResponse [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`pipeUIMessageStreamToResponse`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response#pipeuimessagestreamtoresponse) ================================================================================================================================================ The `pipeUIMessageStreamToResponse` function pipes streaming data to a Node.js ServerResponse object (see [Streaming Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) ). [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response#import) ------------------------------------------------------------------------------------------------ import { pipeUIMessageStreamToResponse } from "ai" [Example](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response#example) -------------------------------------------------------------------------------------------------- 1pipeUIMessageStreamToResponse({2 response: serverResponse,3 status: 200,4 statusText: 'OK',5 headers: {6 'Custom-Header': 'value',7 },8 stream: myUIMessageStream,9 consumeSseStream: ({ stream }) => {10 // Optional: consume the SSE stream independently11 console.log('Consuming SSE stream:', stream);12 },13}); [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response#api-signature) -------------------------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response#parameters) ### response: ServerResponse The Node.js ServerResponse object to pipe the data to. ### stream: ReadableStream The UI message stream to pipe to the response. ### status?: number The status code for the response. ### statusText?: string The status text for the response. ### headers?: Headers | Record Additional headers for the response. ### consumeSseStream?: ({ stream }: { stream: ReadableStream }) => PromiseLike | void Optional function to consume the SSE stream independently. The stream is teed and this function receives a copy. On this page [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response#pipeuimessagestreamtoresponse) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response#import) [Example](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response#example) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response#parameters) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: useUIState [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`useUIState`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state#useuistate) ===================================================================================== AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . It is a hook that enables you to read and update the UI State. The state is client-side and can contain functions, React nodes, and other data. UIState is the visual representation of the AI state. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state#import) --------------------------------------------------------------------------- import { useUIState } from "@ai-sdk/rsc" [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state#api-signature) ----------------------------------------------------------------------------------------- ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state#returns) Similar to useState, it is an array, where the first element is the current UI state and the second element is the function that updates the state. [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state#examples) ------------------------------------------------------------------------------- [Learn to manage AI and UI states in Next.js](https://ai-sdk.dev/examples/next-app/state-management/ai-ui-states) On this page [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state#useuistate) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state#api-signature) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state#returns) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state#examples) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: createAI [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`createAI`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#createai) ============================================================================== AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . Creates a client-server context provider that can be used to wrap parts of your application tree to easily manage both UI and AI states of your application. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#import) ------------------------------------------------------------------------ import { createAI } from "@ai-sdk/rsc" [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#api-signature) -------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#parameters) ### actions: Record Server side actions that can be called from the client. ### initialAIState: any Initial AI state to be used in the client. ### initialUIState: any Initial UI state to be used in the client. ### onGetUIState: () => UIState is called during SSR to compare and update UI state. ### onSetAIState: (Event) => void is triggered whenever an update() or done() is called by the mutable AI state in your action, so you can safely store your AI state in the database. Event ### state: AIState The resulting AI state after the update. ### done: boolean Whether the AI state updates have been finalized or not. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#returns) It returns an `` context provider. [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#examples) ---------------------------------------------------------------------------- [Learn to manage AI and UI states in Next.js](https://ai-sdk.dev/examples/next-app/state-management/ai-ui-states) [Learn to persist and restore states UI/AI states in Next.js](https://ai-sdk.dev/examples/next-app/state-management/save-and-restore-states) On this page [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#createai) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#returns) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai#examples) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: useStreamableValue [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`useStreamableValue`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#usestreamablevalue) ============================================================================================================= AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . It is a React hook that takes a streamable value created using [`createStreamableValue`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) and returns the current value, error, and pending state. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#import) ----------------------------------------------------------------------------------- import { useStreamableValue } from "@ai-sdk/rsc" [Example](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#example) ------------------------------------------------------------------------------------- This is useful for consuming streamable values received from a component's props. 1function MyComponent({ streamableValue }) {2 const [data, error, pending] = useStreamableValue(streamableValue);3 4 if (pending) return
Loading...
;5 if (error) return
Error: {error.message}
;6 7 return
Data: {data}
;8} [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#api-signature) ------------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#parameters) It accepts a streamable value created using `createStreamableValue`. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#returns) It is an array, where the first element contains the data, the second element contains an error if it is thrown anytime during the stream, and the third is a boolean indicating if the value is pending. On this page [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#usestreamablevalue) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#import) [Example](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#example) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value#returns) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: useCompletion [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`useCompletion()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#usecompletion) ============================================================================================== Allows you to create text completion based capabilities for your application. It enables the streaming of text completions from your AI provider, manages the state for chat input, and updates the UI automatically as new messages are received. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#import) ---------------------------------------------------------------------------- ReactSvelteVueAngular import { useCompletion } from '@ai-sdk/react' [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#api-signature) ------------------------------------------------------------------------------------------ ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#parameters) ### api: string = '/api/completion' The API endpoint that is called to generate text. It can be a relative path (starting with \`/\`) or an absolute URL. ### id: string A unique identifier for the completion. If not provided, a random one will be generated. When provided, the \`useCompletion\` hook with the same \`id\` will have shared states across components. This is useful when you have multiple components showing the same chat stream ### initialInput: string An optional string for the initial prompt input. ### initialCompletion: string An optional string for the initial completion result. ### onFinish: (prompt: string, completion: string) => void An optional callback function that is called when the completion stream ends. ### onError: (error: Error) => void An optional callback that will be called when the chat stream encounters an error. ### headers: Record | Headers An optional object of headers to be passed to the API endpoint. ### body: object An optional, additional body object to be passed to the API endpoint. ### credentials: 'omit' | 'same-origin' | 'include' An optional literal that sets the mode of credentials to be used on the request. Defaults to same-origin. ### streamProtocol?: 'text' | 'data' An optional literal that sets the type of stream to be used. Defaults to \`data\`. If set to \`text\`, the stream will be treated as a text stream. ### fetch?: FetchFunction Optional. A custom fetch function to be used for the API call. Defaults to the global fetch function. ### experimental\_throttle?: number React only. Custom throttle wait time in milliseconds for the completion and data updates. When specified, throttles how often the UI updates during streaming. Default is undefined, which disables throttling. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#returns) ### completion: string The current text completion. ### complete: (prompt: string, options?: { headers?: Record | Headers, body?: object }) => Promise Function to execute text completion based on the provided prompt. Returns the completion result when finished. ### error: undefined | Error The error thrown during the completion process, if any. ### setCompletion: (completion: string) => void Function to update the \`completion\` state. ### stop: () => void Function to abort the current API request. ### input: string The current value of the input field. ### setInput: React.Dispatch> Function to update the input value. ### handleInputChange: (event: any) => void Handler for the \`onChange\` event of the input field to control the input's value. ### handleSubmit: (event?: { preventDefault?: () => void }) => void Form submission handler that automatically resets the input field and appends a user message. ### isLoading: boolean Boolean flag indicating whether a fetch operation is currently in progress. On this page [useCompletion()](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#usecompletion) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#returns) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Reference: AI SDK UI [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui#ai-sdk-ui) =================================================================== [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) is designed to help you build interactive chat, completion, and assistant applications with ease. It is framework-agnostic toolkit, streamlining the integration of advanced AI functionalities into your applications. AI SDK UI contains the following hooks: [useChat\ \ Use a hook to interact with language models in a chat interface.](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion\ \ Use a hook to interact with language models in a completion interface.](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject\ \ Use a hook for consuming a streamed JSON objects.](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages\ \ Convert useChat messages to ModelMessages for AI functions.](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages\ \ Prunes model messages from a list of model messages.](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream\ \ Create a UI message stream to stream additional data to the client.](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse\ \ Create a response object to stream UI messages to the client.](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse\ \ Pipe a UI message stream to a Node.js ServerResponse object.](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream\ \ Transform a stream of UIMessageChunk objects into an AsyncIterableStream of UIMessage objects.](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [UI Framework Support](https://ai-sdk.dev/docs/reference/ai-sdk-ui#ui-framework-support) ----------------------------------------------------------------------------------------- AI SDK UI supports the following frameworks: [React](https://react.dev/) , [Svelte](https://svelte.dev/) , [Vue.js](https://vuejs.org/) , [Angular](https://angular.dev/) , and [SolidJS](https://www.solidjs.com/) . Here is a comparison of the supported functions across these frameworks: | | [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) | [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) | [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) | | --- | --- | --- | --- | | React `@ai-sdk/react` | | | | | Vue.js `@ai-sdk/vue` | Chat | | | | Svelte `@ai-sdk/svelte` | Chat | Completion | StructuredObject | | Angular `@ai-sdk/angular` | Chat | Completion | StructuredObject | | [SolidJS](https://github.com/kodehort/ai-sdk-solid)
(community) | | | | [Contributions](https://github.com/vercel/ai/blob/main/CONTRIBUTING.md) are welcome to implement missing features for non-React frameworks. On this page [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui#ai-sdk-ui) [UI Framework Support](https://ai-sdk.dev/docs/reference/ai-sdk-ui#ui-framework-support) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: createUIMessageStreamResponse [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`createUIMessageStreamResponse`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#createuimessagestreamresponse) =============================================================================================================================================== The `createUIMessageStreamResponse` function creates a Response object that streams UI messages to the client. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#import) ----------------------------------------------------------------------------------------------- import { createUIMessageStreamResponse } from "ai" [Example](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#example) ------------------------------------------------------------------------------------------------- Gateway Provider Custom Claude Sonnet 4.5 1import {2 createUIMessageStream,3 createUIMessageStreamResponse,4 streamText,5} from 'ai';6 7const response = createUIMessageStreamResponse({8 status: 200,9 statusText: 'OK',10 headers: {11 'Custom-Header': 'value',12 },13 stream: createUIMessageStream({14 execute({ writer }) {15 // Write custom data (type must be 'data-')16 writer.write({17 type: 'data-message',18 data: { content: 'Hello' },19 });20 21 // Write text content using start/delta/end pattern22 writer.write({23 type: 'text-start',24 id: 'greeting-text',25 });26 writer.write({27 type: 'text-delta',28 id: 'greeting-text',29 delta: 'Hello, world!',30 });31 writer.write({32 type: 'text-end',33 id: 'greeting-text',34 });35 36 // Write source information (flat properties, not nested)37 writer.write({38 type: 'source-url',39 sourceId: 'source-1',40 url: 'https://example.com',41 title: 'Example Source',42 });43 44 // Merge with LLM stream45 const result = streamText({46 model: "anthropic/claude-sonnet-4.5",47 prompt: 'Say hello',48 });49 50 writer.merge(result.toUIMessageStream());51 },52 }),53}); [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#api-signature) ------------------------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#parameters) ### stream: ReadableStream The UI message stream to send to the client. ### status?: number The status code for the response. Defaults to 200. ### statusText?: string The status text for the response. ### headers?: Headers | Record Additional headers for the response. ### consumeSseStream?: (options: { stream: ReadableStream }) => PromiseLike | void Optional callback to consume the Server-Sent Events stream. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#returns) `Response` A Response object that streams UI message chunks with the specified status, headers, and content. On this page [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#createuimessagestreamresponse) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#import) [Example](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#example) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response#returns) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: InferUITools [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#inferuitools) ======================================================================================== Infers the input and output types of a `ToolSet`. This type helper is useful when working with tools in TypeScript to ensure type safety for your tool inputs and outputs in `UIMessage`s. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#import) ---------------------------------------------------------------------------- 1import { InferUITools } from 'ai'; [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#api-signature) ------------------------------------------------------------------------------------------ ### [Type Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#type-parameters) ### TOOLS: ToolSet The tool set to infer types from. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#returns) A type that maps each tool in the tool set to its inferred input and output types. The resulting type has the shape: 1{2 [NAME in keyof TOOLS & string]: {3 input: InferToolInput;4 output: InferToolOutput;5 };6} [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#examples) -------------------------------------------------------------------------------- ### [Basic Usage](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#basic-usage) 1import { InferUITools } from 'ai';2import { z } from 'zod';3 4const tools = {5 weather: {6 description: 'Get the current weather',7 inputSchema: z.object({8 location: z.string().describe('The city and state'),9 }),10 execute: async ({ location }) => {11 return `The weather in ${location} is sunny.`;12 },13 },14 calculator: {15 description: 'Perform basic arithmetic',16 inputSchema: z.object({17 operation: z.enum(['add', 'subtract', 'multiply', 'divide']),18 a: z.number(),19 b: z.number(),20 }),21 execute: async ({ operation, a, b }) => {22 switch (operation) {23 case 'add':24 return a + b;25 case 'subtract':26 return a - b;27 case 'multiply':28 return a * b;29 case 'divide':30 return a / b;31 }32 },33 },34};35 36// Infer the types from the tool set37type MyUITools = InferUITools;38// This creates a type with:39// {40// weather: { input: { location: string }; output: string };41// calculator: { input: { operation: 'add' | 'subtract' | 'multiply' | 'divide'; a: number; b: number }; output: number };42// } [Related](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#related) ------------------------------------------------------------------------------ * [`InferUITool`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) - Infer types for a single tool * [`useChat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) - Chat hook that supports typed tools On this page [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#inferuitools) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#api-signature) [Type Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#type-parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#returns) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#examples) [Basic Usage](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#basic-usage) [Related](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools#related) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: createUIMessageStream [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`createUIMessageStream`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#createuimessagestream) ====================================================================================================================== The `createUIMessageStream` function allows you to create a readable stream for UI messages with advanced features like message merging, error handling, and finish callbacks. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#import) -------------------------------------------------------------------------------------- import { createUIMessageStream } from "ai" [Example](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#example) ---------------------------------------------------------------------------------------- Gateway Provider Custom Claude Sonnet 4.5 1const existingMessages: UIMessage[] = [2 /* ... */3];4 5const stream = createUIMessageStream({6 async execute({ writer }) {7 // Start a text message8 // Note: The id must be consistent across text-start, text-delta, and text-end steps9 // This allows the system to correctly identify they belong to the same text block10 writer.write({11 type: 'text-start',12 id: 'example-text',13 });14 15 // Write a message chunk16 writer.write({17 type: 'text-delta',18 id: 'example-text',19 delta: 'Hello',20 });21 22 // End the text message23 writer.write({24 type: 'text-end',25 id: 'example-text',26 });27 28 // Merge another stream from streamText29 const result = streamText({30 model: "anthropic/claude-sonnet-4.5",31 prompt: 'Write a haiku about AI',32 });33 34 writer.merge(result.toUIMessageStream());35 },36 onError: error => `Custom error: ${error.message}`,37 originalMessages: existingMessages,38 onFinish: ({ messages, isContinuation, responseMessage }) => {39 console.log('Stream finished with messages:', messages);40 },41}); [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#api-signature) ---------------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#parameters) ### execute: (options: { writer: UIMessageStreamWriter }) => Promise | void A function that receives a writer instance and can use it to write UI message chunks to the stream. UIMessageStreamWriter ### write: (part: UIMessageChunk) => void Writes a UI message chunk to the stream. ### merge: (stream: ReadableStream) => void Merges the contents of another UI message stream into this stream. ### onError: (error: unknown) => string Error handler that is used by the stream writer for handling errors in merged streams. ### onError: (error: unknown) => string A function that handles errors and returns an error message string. By default, it returns the error message. ### originalMessages: UIMessage\[\] | undefined The original messages. If provided, persistence mode is assumed and a message ID is provided for the response message. ### onFinish: (options: { messages: UIMessage\[\]; isContinuation: boolean; isAborted: boolean; responseMessage: UIMessage; finishReason?: FinishReason }) => PromiseLike | void A callback function that is called when the stream finishes. FinishOptions ### messages: UIMessage\[\] The updated list of UI messages. ### isContinuation: boolean Indicates whether the response message is a continuation of the last original message, or if a new message was created. ### isAborted: boolean Indicates whether the stream was aborted. ### responseMessage: UIMessage The message that was sent to the client as a response (including the original message if it was extended). ### finishReason: FinishReason | undefined The reason why the generation finished. One of: 'stop', 'length', 'content-filter', 'tool-calls', 'error', or 'other'. ### generateId: IdGenerator | undefined A function to generate unique IDs for messages. Uses the default ID generator if not provided. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#returns) `ReadableStream` A readable stream that emits UI message chunks. The stream automatically handles error propagation, merging of multiple streams, and proper cleanup when all operations are complete. On this page [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#createuimessagestream) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#import) [Example](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#example) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream#returns) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: createStreamableValue [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`createStreamableValue`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#createstreamablevalue) ====================================================================================================================== AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . Create a stream that sends values from the server to the client. The value can be any serializable data. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#import) -------------------------------------------------------------------------------------- import { createStreamableValue } from "@ai-sdk/rsc" [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#api-signature) ---------------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#parameters) ### value: any Any data that RSC supports. Example, JSON. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#returns) ### value: StreamableValue The value of the streamable. This can be returned from a Server Action and received by the client. To read the streamed values, use the \`readStreamableValue\` or \`useStreamableValue\` APIs. ### [Methods](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#methods) ### update: (value: T) => StreamableValueWrapper Updates the current value with a new one. ### append: (value: T) => StreamableValueWrapper Appends a delta string to the current value. It requires the current value of the streamable to be a string. ### done: (value?: T) => StreamableValueWrapper Marks the value as finalized. You can either call it without any parameters or with a new value as the final state. Once called, the value cannot be updated or appended anymore. This method is always required to be called, otherwise the response will be stuck in a loading state. ### error: (error: any) => StreamableValueWrapper Signals that there is an error in the value stream. It will be thrown on the client side when consumed via \`readStreamableValue\` or \`useStreamableValue\`. On this page [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#createstreamablevalue) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#returns) [Methods](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value#methods) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: createStreamableUI [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`createStreamableUI`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#createstreamableui) ============================================================================================================= AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . Create a stream that sends UI from the server to the client. On the client side, it can be rendered as a normal React node. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#import) ----------------------------------------------------------------------------------- import { createStreamableUI } from "@ai-sdk/rsc" [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#api-signature) ------------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#parameters) ### initialValue?: ReactNode The initial value of the streamable UI. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#returns) ### value: ReactNode The value of the streamable UI. This can be returned from a Server Action and received by the client. ### [Methods](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#methods) ### update: (ReactNode) => void Updates the current UI node. It takes a new UI node and replaces the old one. ### append: (ReactNode) => void Appends a new UI node to the end of the old one. Once appended a new UI node, the previous UI node cannot be updated anymore. ### done: (ReactNode | null) => void Marks the UI node as finalized and closes the stream. Once called, the UI node cannot be updated or appended anymore. This method is always required to be called, otherwise the response will be stuck in a loading state. ### error: (Error) => void Signals that there is an error in the UI stream. It will be thrown on the client side and caught by the nearest error boundary component. [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#examples) --------------------------------------------------------------------------------------- [Render a React component during a tool call](https://ai-sdk.dev/examples/next-app/tools/render-interface-during-tool-call) On this page [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#createstreamableui) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#returns) [Methods](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#methods) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#examples) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: getMutableAIState [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`getMutableAIState`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#getmutableaistate) =========================================================================================================== AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . Get a mutable copy of the AI state. You can use this to update the state in the server. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#import) ----------------------------------------------------------------------------------- import { getMutableAIState } from "@ai-sdk/rsc" [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#api-signature) ------------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#parameters) ### key?: string Returns the value of the specified key in the AI state, if it's an object. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#returns) The mutable AI state. ### [Methods](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#methods) ### update: (newState: any) => void Updates the AI state with the new state. ### done: (newState: any) => void Updates the AI state with the new state, marks it as finalized and closes the stream. [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#examples) --------------------------------------------------------------------------------------- [Learn to persist and restore states AI and UI states in Next.js](https://ai-sdk.dev/examples/next-app/state-management/save-and-restore-states) On this page [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#getmutableaistate) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#returns) [Methods](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#methods) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state#examples) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: readStreamableValue [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`readStreamableValue`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#readstreamablevalue) ================================================================================================================ AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . It is a function that helps you read the streamable value from the client that was originally created using [`createStreamableValue`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) on the server. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#import) ------------------------------------------------------------------------------------ import { readStreamableValue } from "@ai-sdk/rsc" [Example](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#example) -------------------------------------------------------------------------------------- app/actions.ts 1async function generate() {2 'use server';3 const streamable = createStreamableValue('');4 5 streamable.append('Hello');6 streamable.append(' ');7 streamable.append('World');8 streamable.done();9 10 return streamable.value;11} app/page.tsx 1import { readStreamableValue } from '@ai-sdk/rsc';2 3export default function Page() {4 const [generation, setGeneration] = useState('');5 6 return (7
8 {10 const stream = await generate();11 12 for await (const value of readStreamableValue(stream)) {13 setGeneration(value);14 }15 }}16 >17 Generate18 19
20 );21} [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#api-signature) -------------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#parameters) ### stream: StreamableValue The streamable value to read from. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#returns) It returns an async iterator that contains the values emitted by the streamable value. On this page [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#readstreamablevalue) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#import) [Example](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#example) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value#returns) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: render (Removed) [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`render` (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render#render-removed) ========================================================================================= "render" has been removed in AI SDK 4.0. AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . A helper function to create a streamable UI from LLM providers. This function is similar to AI SDK Core APIs and supports the same model interfaces. > **Note**: `render` has been deprecated in favor of [`streamUI`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) > . During migration, please ensure that the `messages` parameter follows the updated [specification](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#messages) > . [Import (No longer available)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render#import-no-longer-available) --------------------------------------------------------------------------------------------------------------- The following import will no longer work since `render` has been removed: import { render } from "@ai-sdk/rsc" Use [`streamUI`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) instead. [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render#api-signature) ----------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render#parameters) ### model: string Model identifier, must be OpenAI SDK compatible. ### provider: provider client Currently the only provider available is OpenAI. This needs to match the model name. ### initial?: ReactNode The initial UI to render. ### messages: Array A list of messages that represent a conversation. SystemMessage ### role: 'system' The role for the system message. ### content: string The content of the message. UserMessage ### role: 'user' The role for the user message. ### content: string The content of the message. AssistantMessage ### role: 'assistant' The role for the assistant message. ### content: string The content of the message. ### tool\_calls: ToolCall\[\] A list of tool calls made by the model. ToolCall ### id: string The id of the tool call. ### type: 'function' The type of the tool call. ### function: Function The function to call. Function ### name: string The name of the function. ### arguments: string The arguments of the function. ToolMessage ### role: 'tool' The role for the tool message. ### content: string The content of the message. ### toolCallId: string The id of the tool call. ### functions?: ToolSet Tools that are accessible to and can be called by the model. Tool ### description?: string Information about the purpose of the tool including details on how and when it can be used by the model. ### parameters: zod schema The typed schema that describes the parameters of the tool that can also be used to validation and error handling. ### render?: async (parameters) => any An async function that is called with the arguments from the tool call and produces a result. ### tools?: ToolSet Tools that are accessible to and can be called by the model. Tool ### description?: string Information about the purpose of the tool including details on how and when it can be used by the model. ### parameters: zod schema The typed schema that describes the parameters of the tool that can also be used to validation and error handling. ### render?: async (parameters) => any An async function that is called with the arguments from the tool call and produces a result. ### text?: (Text) => ReactNode Callback to handle the generated tokens from the model. Text ### content: string The full content of the completion. ### delta: string The delta. ### done: boolean Is it done? ### temperature?: number The temperature to use for the model. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render#returns) It can return any valid ReactNode. On this page [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render#render-removed) [Import (No longer available)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render#import-no-longer-available) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render#returns) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: InferUITool [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#inferuitool) ===================================================================================== Infers the input and output types of a tool. This type helper is useful when working with individual tools to ensure type safety for your tool inputs and outputs in `UIMessage`s. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#import) --------------------------------------------------------------------------- 1import { InferUITool } from 'ai'; [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#api-signature) ----------------------------------------------------------------------------------------- ### [Type Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#type-parameters) ### TOOL: Tool The tool to infer types from. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#returns) A type that contains the inferred input and output types of the tool. The resulting type has the shape: 1{2 input: InferToolInput;3 output: InferToolOutput;4} [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#examples) ------------------------------------------------------------------------------- ### [Basic Usage](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#basic-usage) 1import { InferUITool } from 'ai';2import { z } from 'zod';3 4const weatherTool = {5 description: 'Get the current weather',6 inputSchema: z.object({7 location: z.string().describe('The city and state'),8 }),9 execute: async ({ location }) => {10 return `The weather in ${location} is sunny.`;11 },12};13 14// Infer the types from the tool15type WeatherUITool = InferUITool;16// This creates a type with:17// {18// input: { location: string };19// output: string;20// } [Related](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#related) ----------------------------------------------------------------------------- * [`InferUITools`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) - Infer types for a tool set * [`ToolUIPart`](https://ai-sdk.dev/docs/reference/ai-sdk-core/ui-message#tooluipart) - Tool part type for UI messages On this page [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#inferuitool) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#api-signature) [Type Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#type-parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#returns) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#examples) [Basic Usage](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#basic-usage) [Related](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool#related) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Reference: AI SDK RSC [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc#ai-sdk-rsc) ====================================================================== AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . [streamUI\ \ Use a helper function that streams React Server Components on tool execution.](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI\ \ Create a context provider that wraps your application and shares state between the client and language model on the server.](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI\ \ Create a streamable UI component that can be rendered on the server and streamed to the client.](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue\ \ Create a streamable value that can be rendered on the server and streamed to the client.](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [getAIState\ \ Read the AI state on the server.](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState\ \ Read and update the AI state on the server.](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState\ \ Get the AI state on the client from the context provider.](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useUIState\ \ Get the UI state on the client from the context provider.](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useActions\ \ Call server actions from the client.](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) On this page [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc#ai-sdk-rsc) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: getAIState [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`getAIState`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#getaistate) ===================================================================================== AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . Get the current AI state. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#import) --------------------------------------------------------------------------- import { getAIState } from "@ai-sdk/rsc" [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#api-signature) ----------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#parameters) ### key?: string Returns the value of the specified key in the AI state, if it's an object. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#returns) The AI state. [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#examples) ------------------------------------------------------------------------------- [Learn to render a React component during a tool call made by a language model in Next.js](https://ai-sdk.dev/examples/next-app/tools/render-interface-during-tool-call) On this page [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#getaistate) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#returns) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state#examples) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: useObject [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`experimental_useObject()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#experimental_useobject) ============================================================================================================ `useObject` is an experimental feature and only available in React, Svelte, and Vue. Allows you to consume text streams that represent a JSON object and parse them into a complete object based on a schema. You can use it together with [`streamText`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) and [`Output.object()`](https://ai-sdk.dev/docs/reference/ai-sdk-core/output#output-object) in the backend. 1'use client';2 3import { experimental_useObject as useObject } from '@ai-sdk/react';4 5export default function Page() {6 const { object, submit } = useObject({7 api: '/api/use-object',8 schema: z.object({ content: z.string() }),9 });10 11 return (12
13 14 {object?.content &&

{object.content}

}15
16 );17} [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#import) ------------------------------------------------------------------------ ReactSvelteVue import { experimental\_useObject as useObject } from '@ai-sdk/react' [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#api-signature) -------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#parameters) ### api: string The API endpoint that is called to generate objects. It should stream JSON that matches the schema as chunked text. It can be a relative path (starting with \`/\`) or an absolute URL. ### schema: Zod Schema | JSON Schema A schema that defines the shape of the complete object. You can either pass in a Zod schema or a JSON schema (using the \`jsonSchema\` function). ### id?: string A unique identifier. If not provided, a random one will be generated. When provided, the \`useObject\` hook with the same \`id\` will have shared states across components. ### initialValue?: DeepPartial | undefined An value for the initial object. Optional. ### fetch?: FetchFunction A custom fetch function to be used for the API call. Defaults to the global fetch function. Optional. ### headers?: Record | Headers A headers object to be passed to the API endpoint. Optional. ### credentials?: RequestCredentials The credentials mode to be used for the fetch request. Possible values are: "omit", "same-origin", "include". Optional. ### onError?: (error: Error) => void Callback function to be called when an error is encountered. Optional. ### onFinish?: (result: OnFinishResult) => void Called when the streaming response has finished. OnFinishResult ### object: T | undefined The generated object (typed according to the schema). Can be undefined if the final object does not match the schema. ### error: Error | undefined Optional error object. This is e.g. a TypeValidationError when the final object does not match the schema. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#returns) ### submit: (input: INPUT) => void Calls the API with the provided input as JSON body. ### object: DeepPartial | undefined The current value for the generated object. Updated as the API streams JSON chunks. ### error: Error | undefined The error object if the API call fails. ### isLoading: boolean Boolean flag indicating whether a request is currently in progress. ### stop: () => void Function to abort the current API request. ### clear: () => void Function to clear the object state. [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#examples) ---------------------------------------------------------------------------- [Streaming Object Generation with useObject](https://ai-sdk.dev/examples/next-pages/basics/streaming-object-generation) On this page [experimental\_useObject()](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#experimental_useobject) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#returns) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object#examples) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: pruneMessages [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`pruneMessages()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#prunemessages) ============================================================================================== The `pruneMessages` function is used to prune or filter an array of `ModelMessage` objects. This is useful for reducing message context (to save tokens), removing intermediate reasoning, or trimming tool calls and empty messages before sending to an LLM. Gateway Provider Custom Claude Sonnet 4.5 app/api/chat/route.ts 1import { pruneMessages, streamText } from 'ai';2 3export async function POST(req: Request) {4 const { messages } = await req.json();5 6 const prunedMessages = pruneMessages({7 messages,8 reasoning: 'before-last-message',9 toolCalls: 'before-last-2-messages',10 emptyMessages: 'remove',11 });12 13 const result = streamText({14 model: "anthropic/claude-sonnet-4.5",15 messages: prunedMessages,16 });17 18 return result.toUIMessageStreamResponse();19} [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#import) ---------------------------------------------------------------------------- import { pruneMessages } from "ai" [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#api-signature) ------------------------------------------------------------------------------------------ ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#parameters) ### messages: ModelMessage\[\] An array of ModelMessage objects to prune. ### reasoning: 'all' | 'before-last-message' | 'none' How to remove reasoning content from assistant messages. Default: "none". ### toolCalls: 'all' | 'before-last-message' | 'before-last-${number}-messages' | 'none' | Array<{ type: 'all' | 'before-last-message' | 'before-last-${number}-messages'; tools?: string\[\] }> How to prune tool call/results/approval content. Can specify a strategy string or an array for per-tool fine control. Default: \[\] (empty array, equivalent to "none"). ### emptyMessages: 'keep' | 'remove' Whether to keep or remove messages whose content is empty after pruning. Default: "remove". ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#returns) An array of [`ModelMessage`](https://ai-sdk.dev/docs/reference/ai-sdk-core/model-message) objects, pruned according to the provided options. ### ModelMessage\[\]: Array The pruned list of ModelMessage objects [Example Usage](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#example-usage) ------------------------------------------------------------------------------------------ 1import { pruneMessages } from 'ai';2 3const pruned = pruneMessages({4 messages,5 reasoning: 'all', // Remove all reasoning parts6 toolCalls: 'before-last-message', // Remove tool calls except those in the last message7}); [Pruning Options](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#pruning-options) ---------------------------------------------------------------------------------------------- * **reasoning:** Removes reasoning parts from assistant messages. Use `'all'` to remove all, `'before-last-message'` to keep reasoning in the last message, or `'none'` to retain all reasoning. * **toolCalls:** Prune tool-call, tool-result, and tool-approval chunks from assistant/tool messages. Default is an empty array (no pruning). Options include: * `'all'`: Prune all such content. * `'before-last-message'`: Prune except in the last message. * `'before-last-N-messages'`: Prune except in the last N messages. * `'none'`: Do not prune. * Or provide an array for per-tool fine control, e.g., `[{ type: 'before-last-message', tools: ['search', 'calculator'] }]` to prune only specific tools. * **emptyMessages:** Set to `'remove'` (default) to exclude messages that have no content after pruning. > **Tip**: `pruneMessages` is typically used prior to sending a context window to an LLM to reduce message/token count, especially after a series of tool-calls and approvals. For advanced usage and the full list of possible message parts, see [`ModelMessage`](https://ai-sdk.dev/docs/reference/ai-sdk-core/model-message) and [`pruneMessages` implementation](https://github.com/vercel/ai/blob/main/packages/ai/src/generate-text/prune-messages.ts) . On this page [pruneMessages()](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#prunemessages) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#returns) [Example Usage](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#example-usage) [Pruning Options](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages#pruning-options) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: useChat [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`useChat()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#usechat) ============================================================================ Allows you to easily create a conversational user interface for your chatbot application. It enables the streaming of chat messages from your AI provider, manages the chat state, and updates the UI automatically as new messages are received. The `useChat` API has been significantly updated in AI SDK 5.0. It now uses a transport-based architecture and no longer manages input state internally. See the [migration guide](https://ai-sdk.dev/docs/migration-guides/migration-guide-5-0#usechat-changes) for details. [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#import) ---------------------------------------------------------------------- ReactSvelteVueAngular import { useChat } from '@ai-sdk/react' [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#api-signature) ------------------------------------------------------------------------------------ ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#parameters) ### chat?: Chat An existing Chat instance to use. If provided, other parameters are ignored. ### transport?: ChatTransport The transport to use for sending messages. Defaults to DefaultChatTransport with \`/api/chat\` endpoint. DefaultChatTransport ### api?: string = '/api/chat' The API endpoint for chat requests. ### credentials?: RequestCredentials The credentials mode for fetch requests. ### headers?: Record | Headers HTTP headers to send with requests. ### body?: object Extra body object to send with requests. ### fetch?: FetchFunction Custom fetch implementation. You can use it as a middleware to intercept requests, or to provide a custom fetch implementation for e.g. testing. ### prepareSendMessagesRequest?: PrepareSendMessagesRequest A function to customize the request before chat API calls. PrepareSendMessagesRequest ### options: PrepareSendMessageRequestOptions Options for preparing the request PrepareSendMessageRequestOptions ### id: string The chat ID ### messages: UIMessage\[\] Current messages in the chat ### requestMetadata: unknown The request metadata ### body: Record | undefined The request body ### credentials: RequestCredentials | undefined The request credentials ### headers: HeadersInit | undefined The request headers ### api: string The API endpoint to use for the request. If not specified, it defaults to the transport’s API endpoint: /api/chat. ### trigger: 'submit-message' | 'regenerate-message' The trigger for the request ### messageId: string | undefined The message ID if applicable ### prepareReconnectToStreamRequest?: PrepareReconnectToStreamRequest A function to customize the request before reconnect API call. PrepareReconnectToStreamRequest ### options: PrepareReconnectToStreamRequestOptions Options for preparing the reconnect request PrepareReconnectToStreamRequestOptions ### id: string The chat ID ### requestMetadata: unknown The request metadata ### body: Record | undefined The request body ### credentials: RequestCredentials | undefined The request credentials ### headers: HeadersInit | undefined The request headers ### api: string The API endpoint to use for the request. If not specified, it defaults to the transport’s API endpoint combined with the chat ID: /api/chat/{chatId}/stream. ### id?: string A unique identifier for the chat. If not provided, a random one will be generated. ### messages?: UIMessage\[\] Initial chat messages to populate the conversation with. ### messageMetadataSchema?: FlexibleSchema Schema for validating message metadata. ### dataPartSchemas?: UIDataTypesToSchemas Schemas for validating data parts in messages. ### generateId?: IdGenerator A function to generate unique IDs for messages and the chat. If not provided, the default AI SDK generateId is used. ### onToolCall?: ({toolCall: ToolCall}) => void | Promise Optional callback function that is invoked when a tool call is received. You must call addToolOutput to provide the tool result. ### sendAutomaticallyWhen?: (options: { messages: UIMessage\[\] }) => boolean | PromiseLike When provided, this function will be called when the stream is finished or a tool call is added to determine if the current messages should be resubmitted. You can use the lastAssistantMessageIsCompleteWithToolCalls helper for common scenarios. ### onFinish?: (options: OnFinishOptions) => void Called when the assistant response has finished streaming. OnFinishOptions ### message: UIMessage The response message. ### messages: UIMessage\[\] All messages including the response message ### isAbort: boolean True when the request has been aborted by the client. ### isDisconnect: boolean True if the server has been disconnected, e.g. because of a network error. ### isError: boolean True if errors during streaming caused the response to stop early. ### finishReason?: 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' The reason why the model finished generating the response. Undefined if the finish reason was not provided by the model. ### onError?: (error: Error) => void Callback function to be called when an error is encountered. ### onData?: (dataPart: DataUIPart) => void Optional callback function that is called when a data part is received. ### experimental\_throttle?: number Custom throttle wait in ms for the chat messages and data updates. Default is undefined, which disables throttling. ### resume?: boolean Whether to resume an ongoing chat generation stream. Defaults to false. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#returns) ### id: string The id of the chat. ### messages: UIMessage\[\] The current array of chat messages. UIMessage ### id: string A unique identifier for the message. ### role: 'system' | 'user' | 'assistant' The role of the message. ### parts: UIMessagePart\[\] The parts of the message. Use this for rendering the message in the UI. ### metadata?: unknown The metadata of the message. ### status: 'submitted' | 'streaming' | 'ready' | 'error' The current status of the chat: "ready" (idle), "submitted" (request sent), "streaming" (receiving response), or "error" (request failed). ### error: Error | undefined The error object if an error occurred. ### sendMessage: (message?: { text: string; files?: FileList | FileUIPart\[\]; metadata?; messageId?: string } | CreateUIMessage, options?: ChatRequestOptions) => Promise Function to send a new message to the chat. This will trigger an API call to generate the assistant response. If a messageId is provided, the message will be replaced (useful for editing). If no message is provided, resubmits the current messages (useful after adding tool outputs). ChatRequestOptions ### headers?: Record | Headers Additional headers that should be to be passed to the API endpoint. ### body?: object Additional body JSON properties that should be sent to the API endpoint. ### metadata?: unknown Additional data to be sent to the API endpoint. ### regenerate: (options?: { messageId?: string } & ChatRequestOptions) => Promise Function to regenerate the last assistant message or a specific message. If no messageId is provided, regenerates the last assistant message. Accepts ChatRequestOptions for headers, body, and metadata. ### stop: () => void Function to abort the current streaming response from the assistant. ### clearError: () => void Clears the error state. ### resumeStream: () => void Function to resume an interrupted streaming response. Useful when a network error occurs during streaming. ### addToolOutput: (options: { tool: string; toolCallId: string; output: unknown } | { tool: string; toolCallId: string; state: "output-error", errorText: string }) => void Function to add a tool result to the chat. This will update the chat messages with the tool result. If sendAutomaticallyWhen is configured, it may trigger an automatic submission. ### addToolApprovalResponse: (options: { id: string; approved: boolean; reason?: string }) => void | PromiseLike Function to respond to a tool approval request. The id should match the approval id from the tool call. If sendAutomaticallyWhen is configured, it may trigger an automatic submission. ### addToolResult: (options: { tool: string; toolCallId: string; output: unknown } | { tool: string; toolCallId: string; state: "output-error", errorText: string }) => void Deprecated. Use addToolOutput instead. ### setMessages: (messages: UIMessage\[\] | ((messages: UIMessage\[\]) => UIMessage\[\])) => void Function to update the messages state locally without triggering an API call. Useful for optimistic updates. [Learn more](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#learn-more) ------------------------------------------------------------------------------ * [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) * [Chatbot with Tools](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-with-tool-calling) * [UIMessage](https://ai-sdk.dev/docs/reference/ai-sdk-core/ui-message) On this page [useChat()](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#usechat) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#returns) [Learn more](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat#learn-more) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: streamUI [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`streamUI`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#streamui) ============================================================================== AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . A helper function to create a streamable UI from LLM providers. This function is similar to AI SDK Core APIs and supports the same model interfaces. To see `streamUI` in action, check out [these examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#examples) . [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#import) ------------------------------------------------------------------------ import { streamUI } from "@ai-sdk/rsc" [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#parameters) -------------------------------------------------------------------------------- ### model: LanguageModel The language model to use. Example: openai("gpt-4.1") ### initial?: ReactNode The initial UI to render. ### system: string | SystemModelMessage | SystemModelMessage\[\] The system prompt to use that specifies the behavior of the model. ### prompt: string The input prompt to generate the text from. ### messages: Array | Array A list of messages that represent a conversation. Automatically converts UI messages from the useChat hook. SystemModelMessage ### role: 'system' The role for the system message. ### content: string The content of the message. UserModelMessage ### role: 'user' The role for the user message. ### content: string | Array The content of the message. TextPart ### type: 'text' The type of the message part. ### text: string The text content of the message part. ImagePart ### type: 'image' The type of the message part. ### image: string | Uint8Array | Buffer | ArrayBuffer | URL The image content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs. ### mediaType?: string The IANA media type of the image. Optional. FilePart ### type: 'file' The type of the message part. ### data: string | Uint8Array | Buffer | ArrayBuffer | URL The file content of the message part. String are either base64 encoded content, base64 data URLs, or http(s) URLs. ### mediaType: string The IANA media type of the file. AssistantModelMessage ### role: 'assistant' The role for the assistant message. ### content: string | Array The content of the message. TextPart ### type: 'text' The type of the message part. ### text: string The text content of the message part. ToolCallPart ### type: 'tool-call' The type of the message part. ### toolCallId: string The id of the tool call. ### toolName: string The name of the tool, which typically would be the name of the function. ### args: object based on zod schema Parameters generated by the model to be used by the tool. ToolModelMessage ### role: 'tool' The role for the assistant message. ### content: Array The content of the message. ToolResultPart ### type: 'tool-result' The type of the message part. ### toolCallId: string The id of the tool call the result corresponds to. ### toolName: string The name of the tool the result corresponds to. ### result: unknown The result returned by the tool after execution. ### isError?: boolean Whether the result is an error or an error message. ### maxOutputTokens?: number Maximum number of tokens to generate. ### temperature?: number Temperature setting. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either \`temperature\` or \`topP\`, but not both. ### topP?: number Nucleus sampling. The value is passed through to the provider. The range depends on the provider and model. It is recommended to set either \`temperature\` or \`topP\`, but not both. ### topK?: number Only sample from the top K options for each subsequent token. Used to remove "long tail" low probability responses. Recommended for advanced use cases only. You usually only need to use temperature. ### presencePenalty?: number Presence penalty setting. It affects the likelihood of the model to repeat information that is already in the prompt. The value is passed through to the provider. The range depends on the provider and model. ### frequencyPenalty?: number Frequency penalty setting. It affects the likelihood of the model to repeatedly use the same words or phrases. The value is passed through to the provider. The range depends on the provider and model. ### stopSequences?: string\[\] Sequences that will stop the generation of the text. If the model generates any of these sequences, it will stop generating further text. ### seed?: number The seed (integer) to use for random sampling. If set and supported by the model, calls will generate deterministic results. ### maxRetries?: number Maximum number of retries. Set to 0 to disable retries. Default: 2. ### abortSignal?: AbortSignal An optional abort signal that can be used to cancel the call. ### headers?: Record Additional HTTP headers to be sent with the request. Only applicable for HTTP-based providers. ### tools: ToolSet Tools that are accessible to and can be called by the model. Tool ### description?: string Information about the purpose of the tool including details on how and when it can be used by the model. ### inputSchema: zod schema The typed schema that describes the parameters of the tool that can also be used to validation and error handling. ### generate?: (async (parameters) => ReactNode) | AsyncGenerator A function or a generator function that is called with the arguments from the tool call and yields React nodes as the UI. ### toolChoice?: "auto" | "none" | "required" | { "type": "tool", "toolName": string } The tool choice setting. It specifies how tools are selected for execution. The default is "auto". "none" disables tool execution. "required" requires tools to be executed. { "type": "tool", "toolName": string } specifies a specific tool to execute. ### text?: (Text) => ReactNode Callback to handle the generated tokens from the model. Text ### content: string The full content of the completion. ### delta: string The delta. ### done: boolean Is it done? ### providerOptions?: Record | undefined Provider-specific options. The outer key is the provider name. The inner values are the metadata. Details depend on the provider. ### onFinish?: (result: OnFinishResult) => void Callback that is called when the LLM response and all request tool executions (for tools that have a \`generate\` function) are finished. OnFinishResult ### usage: LanguageModelUsage The token usage of the generated text. LanguageModelUsage ### inputTokens: number | undefined The total number of input (prompt) tokens used. ### inputTokenDetails: LanguageModelInputTokenDetails Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens. LanguageModelInputTokenDetails ### noCacheTokens: number | undefined The number of non-cached input (prompt) tokens used. ### cacheReadTokens: number | undefined The number of cached input (prompt) tokens read. ### cacheWriteTokens: number | undefined The number of cached input (prompt) tokens written. ### outputTokens: number | undefined The number of total output (completion) tokens used. ### outputTokenDetails: LanguageModelOutputTokenDetails Detailed information about the output (completion) tokens. LanguageModelOutputTokenDetails ### textTokens: number | undefined The number of text tokens used. ### reasoningTokens: number | undefined The number of reasoning tokens used. ### totalTokens: number | undefined The total number of tokens used. ### raw?: object | undefined Raw usage information from the provider. This is the provider's original usage information and may include additional fields. ### value: ReactNode The final ui node that was generated. ### warnings: Warning\[\] | undefined Warnings from the model provider (e.g. unsupported settings). ### response: Response Optional response data. Response ### headers?: Record Response headers. [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#returns) -------------------------------------------------------------------------- ### value: ReactNode The user interface based on the stream output. ### response?: Response Optional response data. Response ### headers?: Record Response headers. ### warnings: Warning\[\] | undefined Warnings from the model provider (e.g. unsupported settings). ### stream: AsyncIterable & ReadableStream A stream with all events, including text deltas, tool calls, tool results, and errors. You can use it as either an AsyncIterable or a ReadableStream. When an error occurs, the stream will throw the error. StreamPart ### type: 'text-delta' The type to identify the object as text delta. ### textDelta: string The text delta. StreamPart ### type: 'tool-call' The type to identify the object as tool call. ### toolCallId: string The id of the tool call. ### toolName: string The name of the tool, which typically would be the name of the function. ### args: object based on zod schema Parameters generated by the model to be used by the tool. StreamPart ### type: 'error' The type to identify the object as error. ### error: Error Describes the error that may have occurred during execution. StreamPart ### type: 'finish' The type to identify the object as finish. ### finishReason: 'stop' | 'length' | 'content-filter' | 'tool-calls' | 'error' | 'other' The reason the model finished generating the text. ### usage: LanguageModelUsage The token usage of the generated text. LanguageModelUsage ### inputTokens: number | undefined The total number of input (prompt) tokens used. ### inputTokenDetails: LanguageModelInputTokenDetails Detailed information about the input (prompt) tokens. See also: cached tokens and non-cached tokens. LanguageModelInputTokenDetails ### noCacheTokens: number | undefined The number of non-cached input (prompt) tokens used. ### cacheReadTokens: number | undefined The number of cached input (prompt) tokens read. ### cacheWriteTokens: number | undefined The number of cached input (prompt) tokens written. ### outputTokens: number | undefined The number of total output (completion) tokens used. ### outputTokenDetails: LanguageModelOutputTokenDetails Detailed information about the output (completion) tokens. LanguageModelOutputTokenDetails ### textTokens: number | undefined The number of text tokens used. ### reasoningTokens: number | undefined The number of reasoning tokens used. ### totalTokens: number | undefined The total number of tokens used. ### raw?: object | undefined Raw usage information from the provider. This is the provider's original usage information and may include additional fields. [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#examples) ---------------------------------------------------------------------------- [Learn to render a React component as a function call using a language model in Next.js](https://ai-sdk.dev/examples/next-app/state-management/ai-ui-states) [Learn to persist and restore states UI/AI states in Next.js](https://ai-sdk.dev/examples/next-app/state-management/save-and-restore-states) [Learn to route React components using a language model in Next.js](https://ai-sdk.dev/examples/next-app/interface/route-components) [Learn to stream component updates to the client in Next.js](https://ai-sdk.dev/examples/next-app/interface/stream-component-updates) On this page [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#streamui) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#import) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#returns) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui#examples) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: convertToModelMessages [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`convertToModelMessages()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#converttomodelmessages) =========================================================================================================================== The `convertToModelMessages` function is used to transform an array of UI messages from the `useChat` hook into an array of `ModelMessage` objects. These `ModelMessage` objects are compatible with AI core functions like `streamText`. Gateway Provider Custom Claude Sonnet 4.5 app/api/chat/route.ts 1import { convertToModelMessages, streamText } from 'ai';2 3export async function POST(req: Request) {4 const { messages } = await req.json();5 6 const result = streamText({7 model: "anthropic/claude-sonnet-4.5",8 messages: await convertToModelMessages(messages),9 });10 11 return result.toUIMessageStreamResponse();12} [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#import) --------------------------------------------------------------------------------------- import { convertToModelMessages } from "ai" [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#api-signature) ----------------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#parameters) ### messages: Message\[\] An array of UI messages from the useChat hook to be converted ### options: { tools?: ToolSet, ignoreIncompleteToolCalls?: boolean, convertDataPart?: (part: DataUIPart) => TextPart | FilePart | undefined } Optional configuration object. Provide tools to enable multi-modal tool responses. Set ignoreIncompleteToolCalls to true to skip tool calls without results (default: false). Use convertDataPart to transform custom data parts into model-compatible content. ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#returns) A Promise that resolves to an array of [`ModelMessage`](https://ai-sdk.dev/docs/reference/ai-sdk-core/model-message) objects. ### Promise: Promise A Promise that resolves to an array of ModelMessage objects [Multi-modal Tool Responses](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#multi-modal-tool-responses) ------------------------------------------------------------------------------------------------------------------------------- The `convertToModelMessages` function supports tools that can return multi-modal content. This is useful when tools need to return non-text content like images. Gateway Provider Custom Claude Sonnet 4.5 1import { tool } from 'ai';2import { z } from 'zod';3 4const screenshotTool = tool({5 inputSchema: z.object({}),6 execute: async () => 'imgbase64',7 toModelOutput: ({ output }) => [{ type: 'image', data: output }],8});9 10const result = streamText({11 model: "anthropic/claude-sonnet-4.5",12 messages: convertToModelMessages(messages, {13 tools: {14 screenshot: screenshotTool,15 },16 }),17}); Tools can implement the optional `toModelOutput` method to transform their results into multi-modal content. The content is an array of content parts, where each part has a `type` (e.g., 'text', 'image') and corresponding data. [Custom Data Part Conversion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#custom-data-part-conversion) --------------------------------------------------------------------------------------------------------------------------------- The `convertToModelMessages` function supports converting custom data parts attached to user messages. This is useful when users need to include additional context (URLs, code files, JSON configs) with their messages. ### [Basic Usage](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#basic-usage) By default, data parts in user messages are filtered out during conversion. To include them, provide a `convertDataPart` callback that transforms data parts into text or file parts that the model can understand: Gateway Provider Custom Claude Sonnet 4.5 app/api/chat/route.ts 1import { convertToModelMessages, streamText } from 'ai';2 3type CustomUIMessage = UIMessage<4 never,5 {6 url: { url: string; title: string; content: string };7 'code-file': { filename: string; code: string; language: string };8 }9>;10 11export async function POST(req: Request) {12 const { messages } = await req.json();13 14 const result = streamText({15 model: "anthropic/claude-sonnet-4.5",16 messages: convertToModelMessages(messages, {17 convertDataPart: part => {18 // Convert URL attachments to text19 if (part.type === 'data-url') {20 return {21 type: 'text',22 text: `[Reference: ${part.data.title}](${part.data.url})\n\n${part.data.content}`,23 };24 }25 26 // Convert code file attachments27 if (part.type === 'data-code-file') {28 return {29 type: 'text',30 text: `\`\`\`${part.data.language}\n// ${part.data.filename}\n${part.data.code}\n\`\`\``,31 };32 }33 34 // Other data parts are ignored35 },36 }),37 });38 39 return result.toUIMessageStreamResponse();40} ### [Use Cases](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#use-cases) **Attaching URL Content** Allow users to attach URLs to their messages, with the content fetched and formatted for the model: 1// Client side2sendMessage({3 parts: [4 { type: 'text', text: 'Analyze this article' },5 {6 type: 'data-url',7 data: {8 url: 'https://example.com/article',9 title: 'Important Article',10 content: '...',11 },12 },13 ],14}); **Including Code Files as Context** Let users reference code files in their conversations: 1convertDataPart: part => {2 if (part.type === 'data-code-file') {3 return {4 type: 'text',5 text: `\`\`\`${part.data.language}\n${part.data.code}\n\`\`\``,6 };7 }8}; **Selective Inclusion** Only data parts for which you return a text or file model message part are included, all other data parts are ignored. 1const result = convertToModelMessages<2 UIMessage<3 unknown,4 {5 url: { url: string; title: string };6 code: { code: string; language: string };7 note: { text: string };8 }9 >10>(messages, {11 convertDataPart: part => {12 if (part.type === 'data-url') {13 return {14 type: 'text',15 text: `[${part.data.title}](${part.data.url})`,16 };17 }18 19 // data-code and data-node are ignored20 },21}); ### [Type Safety](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#type-safety) The generic parameter ensures full type safety for your custom data parts: 1type MyUIMessage = UIMessage<2 unknown,3 {4 url: { url: string; content: string };5 config: { key: string; value: string };6 }7>;8 9// TypeScript knows the exact shape of part.data10convertToModelMessages(messages, {11 convertDataPart: part => {12 if (part.type === 'data-url') {13 // part.data is typed as { url: string; content: string }14 return { type: 'text', text: part.data.url };15 }16 // Return undefined to skip this part17 },18}); On this page [convertToModelMessages()](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#converttomodelmessages) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#api-signature) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#parameters) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#returns) [Multi-modal Tool Responses](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#multi-modal-tool-responses) [Custom Data Part Conversion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#custom-data-part-conversion) [Basic Usage](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#basic-usage) [Use Cases](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#use-cases) [Type Safety](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages#type-safety) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK UI: DirectChatTransport [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [useChat](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) [useCompletion](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) [useObject](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-object) [convertToModelMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) [pruneMessages](https://ai-sdk.dev/docs/reference/ai-sdk-ui/prune-messages) [createUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream) [createUIMessageStreamResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/create-ui-message-stream-response) [pipeUIMessageStreamToResponse](https://ai-sdk.dev/docs/reference/ai-sdk-ui/pipe-ui-message-stream-to-response) [readUIMessageStream](https://ai-sdk.dev/docs/reference/ai-sdk-ui/read-ui-message-stream) [InferUITools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tools) [InferUITool](https://ai-sdk.dev/docs/reference/ai-sdk-ui/infer-ui-tool) [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`DirectChatTransport`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#directchattransport) =============================================================================================================== A transport that directly communicates with an [Agent](https://ai-sdk.dev/docs/reference/ai-sdk-core/agent) in-process, without going through HTTP. This is useful for: * Server-side rendering scenarios * Testing without network * Single-process applications Unlike `DefaultChatTransport` which sends HTTP requests to an API endpoint, `DirectChatTransport` invokes the agent's `stream()` method directly and converts the result to a UI message stream. Gateway Provider Custom Claude Sonnet 4.5 1import { useChat } from '@ai-sdk/react';2import { DirectChatTransport, ToolLoopAgent } from 'ai';3 4const agent = new ToolLoopAgent({5 model: "anthropic/claude-sonnet-4.5",6 instructions: 'You are a helpful assistant.',7});8 9export default function Chat() {10 const { messages, sendMessage, status } = useChat({11 transport: new DirectChatTransport({ agent }),12 });13 14 // ... render chat UI15} [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#import) ----------------------------------------------------------------------------------- import { DirectChatTransport } from "ai" [Constructor](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#constructor) --------------------------------------------------------------------------------------------- ### [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#parameters) ### agent: Agent The Agent instance to use for generating responses. The agent will be called with \`stream()\` for each message. ### options?: CALL\_OPTIONS Options to pass to the agent when calling it. These are agent-specific options defined when creating the agent. ### originalMessages?: UIMessage\[\] The original messages. If provided, persistence mode is assumed, and a message ID is provided for the response message. ### generateMessageId?: IdGenerator Generate a message ID for the response message. If not provided, no message ID will be set for the response message. ### messageMetadata?: (options: { part: TextStreamPart }) => METADATA | undefined Extracts message metadata that will be sent to the client. Called on \`start\` and \`finish\` events. ### sendReasoning?: boolean Send reasoning parts to the client. Defaults to true. ### sendSources?: boolean Send source parts to the client. Defaults to false. ### sendFinish?: boolean Send the finish event to the client. Set to false if you are using additional streamText calls that send additional data. Defaults to true. ### sendStart?: boolean Send the message start event to the client. Set to false if you are using additional streamText calls and the message start event has already been sent. Defaults to true. ### onError?: (error: unknown) => string Process an error, e.g. to log it. Defaults to \`() => 'An error occurred.'\`. Return the error message to include in the data stream. [Methods](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#methods) ------------------------------------------------------------------------------------- ### [`sendMessages()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#sendmessages) Sends messages to the agent and returns a streaming response. This method validates and converts UI messages to model messages, calls the agent's `stream()` method, and returns the result as a UI message stream. 1const stream = await transport.sendMessages({2 chatId: 'chat-123',3 trigger: 'submit-message',4 messages: [...],5 abortSignal: controller.signal,6}); ### chatId: string Unique identifier for the chat session. ### trigger: 'submit-message' | 'regenerate-message' The type of message submission - either new message or regeneration. ### messageId: string | undefined ID of the message to regenerate, or undefined for new messages. ### messages: UIMessage\[\] Array of UI messages representing the conversation history. ### abortSignal: AbortSignal | undefined Signal to abort the request if needed. ### headers?: Record | Headers Additional headers (ignored by DirectChatTransport). ### body?: object Additional body properties (ignored by DirectChatTransport). ### metadata?: unknown Custom metadata (ignored by DirectChatTransport). #### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#returns) Returns a `Promise>` - a stream of UI message chunks that can be processed by the chat UI. ### [`reconnectToStream()`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#reconnecttostream) Direct transport does not support reconnection since there is no persistent server-side stream to reconnect to. #### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#returns-1) Always returns `Promise`. [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#examples) --------------------------------------------------------------------------------------- ### [Basic Usage](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#basic-usage) 1import { useChat } from '@ai-sdk/react';2import { DirectChatTransport, ToolLoopAgent } from 'ai';3import { openai } from '@ai-sdk/openai';4 5const agent = new ToolLoopAgent({6 model: openai('gpt-4o'),7 instructions: 'You are a helpful assistant.',8});9 10export default function Chat() {11 const { messages, sendMessage, status } = useChat({12 transport: new DirectChatTransport({ agent }),13 });14 15 return (16
17 {messages.map(message => (18
19 {message.role === 'user' ? 'User: ' : 'AI: '}20 {message.parts.map((part, index) =>21 part.type === 'text' ? {part.text} : null,22 )}23
24 ))}25 26
27 );28} ### [With Agent Tools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#with-agent-tools) 1import { useChat } from '@ai-sdk/react';2import { DirectChatTransport, ToolLoopAgent, tool } from 'ai';3import { openai } from '@ai-sdk/openai';4import { z } from 'zod';5 6const weatherTool = tool({7 description: 'Get the current weather',8 parameters: z.object({9 location: z.string().describe('The city and state'),10 }),11 execute: async ({ location }) => {12 return `The weather in ${location} is sunny and 72°F.`;13 },14});15 16const agent = new ToolLoopAgent({17 model: openai('gpt-4o'),18 instructions: 'You are a helpful assistant with access to weather data.',19 tools: { weather: weatherTool },20});21 22export default function Chat() {23 const { messages, sendMessage } = useChat({24 transport: new DirectChatTransport({ agent }),25 });26 27 // ... render chat UI with tool results28} ### [With Custom Agent Options](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#with-custom-agent-options) 1import { useChat } from '@ai-sdk/react';2import { DirectChatTransport, ToolLoopAgent } from 'ai';3import { openai } from '@ai-sdk/openai';4 5const agent = new ToolLoopAgent<{ userId: string }>({6 model: openai('gpt-4o'),7 prepareCall: ({ options, ...rest }) => ({8 ...rest,9 providerOptions: {10 openai: { user: options.userId },11 },12 }),13});14 15export default function Chat({ userId }: { userId: string }) {16 const { messages, sendMessage } = useChat({17 transport: new DirectChatTransport({18 agent,19 options: { userId },20 }),21 });22 23 // ... render chat UI24} ### [With Reasoning](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#with-reasoning) 1import { useChat } from '@ai-sdk/react';2import { DirectChatTransport, ToolLoopAgent } from 'ai';3import { openai } from '@ai-sdk/openai';4 5const agent = new ToolLoopAgent({6 model: openai('o1-preview'),7});8 9export default function Chat() {10 const { messages, sendMessage } = useChat({11 transport: new DirectChatTransport({12 agent,13 sendReasoning: true,14 }),15 });16 17 return (18
19 {messages.map(message => (20
21 {message.parts.map((part, index) => {22 if (part.type === 'text') {23 return

{part.text}

;24 }25 if (part.type === 'reasoning') {26 return (27
28                  {part.text}29                
30 );31 }32 return null;33 })}34
35 ))}36
37 );38} On this page [DirectChatTransport](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#directchattransport) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#import) [Constructor](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#constructor) [Parameters](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#parameters) [Methods](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#methods) [sendMessages()](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#sendmessages) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#returns) [reconnectToStream()](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#reconnecttostream) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#returns-1) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#examples) [Basic Usage](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#basic-usage) [With Agent Tools](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#with-agent-tools) [With Custom Agent Options](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#with-custom-agent-options) [With Reasoning](https://ai-sdk.dev/docs/reference/ai-sdk-ui/direct-chat-transport#with-reasoning) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK RSC: useActions [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [streamUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/stream-ui) [createAI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) [createStreamableUI](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) [createStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) [readStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/read-streamable-value) [getAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-ai-state) [getMutableAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/get-mutable-ai-state) [useAIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ai-state) [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) [useUIState](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-ui-state) [useStreamableValue](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-streamable-value) [render (Removed)](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/render) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [`useActions`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions#useactions) ==================================================================================== AI SDK RSC is currently experimental. We recommend using [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui/overview) for production. For guidance on migrating from RSC to UI, see our [migration guide](https://ai-sdk.dev/docs/ai-sdk-rsc/migrating-to-ui) . It is a hook to help you access your Server Actions from the client. This is particularly useful for building interfaces that require user interactions with the server. It is required to access these server actions via this hook because they are patched when passed through the context. Accessing them directly may result in a [Cannot find Client Component error](https://ai-sdk.dev/docs/troubleshooting/common-issues/server-actions-in-client-components) . [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions#import) -------------------------------------------------------------------------- import { useActions } from "@ai-sdk/rsc" [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions#api-signature) ---------------------------------------------------------------------------------------- ### [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions#returns) `Record`, a dictionary of server actions. [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions#examples) ------------------------------------------------------------------------------ [Learn to manage AI and UI states in Next.js](https://ai-sdk.dev/examples/next-app/state-management/ai-ui-states) [Learn to route React components using a language model in Next.js](https://ai-sdk.dev/examples/next-app/interface/route-components) On this page [useActions](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions#useactions) [Import](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions#import) [API Signature](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions#api-signature) [Returns](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions#returns) [Examples](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions#examples) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_InvalidDataContentError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error#ai_invaliddatacontenterror) ======================================================================================================================================== This error occurs when the data content provided in a multi-modal message part is invalid. Check out the [prompt examples for multi-modal messages](https://ai-sdk.dev/docs/foundations/prompts#message-prompts) . [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error#properties) ------------------------------------------------------------------------------------------------------- * `content`: The invalid content value * `cause`: The underlying error that caused this error (optional) * `message`: The error message describing the expected and received content types (optional, auto-generated) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error#checking-for-this-error) --------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_InvalidDataContentError` using: 1import { InvalidDataContentError } from 'ai';2 3if (InvalidDataContentError.isInstance(error)) {4 // Handle the error5} On this page [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error#ai_invaliddatacontenterror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_EmptyResponseBodyError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error#ai_emptyresponsebodyerror) ===================================================================================================================================== This error occurs when the server returns an empty response body. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error#properties) ------------------------------------------------------------------------------------------------------ * `message`: The error message [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error#checking-for-this-error) -------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_EmptyResponseBodyError` using: 1import { EmptyResponseBodyError } from 'ai';2 3if (EmptyResponseBodyError.isInstance(error)) {4 // Handle the error5} On this page [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error#ai_emptyresponsebodyerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_LoadAPIKeyError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error#ai_loadapikeyerror) ================================================================================================================ This error occurs when API key is not loaded successfully. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error#properties) ----------------------------------------------------------------------------------------------- * `message`: The error message [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error#checking-for-this-error) ------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_LoadAPIKeyError` using: 1import { LoadAPIKeyError } from 'ai';2 3if (LoadAPIKeyError.isInstance(error)) {4 // Handle the error5} On this page [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error#ai_loadapikeyerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_MessageConversionError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error#ai_messageconversionerror) ==================================================================================================================================== This error occurs when message conversion fails. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error#properties) ----------------------------------------------------------------------------------------------------- * `originalMessage`: The original message that failed conversion * `message`: The error message [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error#checking-for-this-error) ------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_MessageConversionError` using: 1import { MessageConversionError } from 'ai';2 3if (MessageConversionError.isInstance(error)) {4 // Handle the error5} On this page [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error#ai_messageconversionerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_APICallError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error#ai_apicallerror) ====================================================================================================== This error occurs when an API call fails. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error#properties) ------------------------------------------------------------------------------------------- * `url`: The URL of the API request that failed * `requestBodyValues`: The request body values sent to the API * `statusCode`: The HTTP status code returned by the API (optional) * `responseHeaders`: The response headers returned by the API (optional) * `responseBody`: The response body returned by the API (optional) * `isRetryable`: Whether the request can be retried based on the status code * `data`: Any additional data associated with the error (optional) * `cause`: The underlying error that caused the API call to fail (optional) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error#checking-for-this-error) --------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_APICallError` using: 1import { APICallError } from 'ai';2 3if (APICallError.isInstance(error)) {4 // Handle the error5} On this page [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error#ai_apicallerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_InvalidArgumentError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error#ai_invalidargumenterror) ============================================================================================================================== This error occurs when an invalid argument was provided. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error#properties) --------------------------------------------------------------------------------------------------- * `parameter`: The name of the parameter that is invalid * `value`: The invalid value * `message`: The error message [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error#checking-for-this-error) ----------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_InvalidArgumentError` using: 1import { InvalidArgumentError } from 'ai';2 3if (InvalidArgumentError.isInstance(error)) {4 // Handle the error5} On this page [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error#ai_invalidargumenterror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_DownloadError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error#ai_downloaderror) ======================================================================================================== This error occurs when a download fails. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error#properties) ------------------------------------------------------------------------------------------- * `url`: The URL that failed to download * `statusCode`: The HTTP status code returned by the server (optional) * `statusText`: The HTTP status text returned by the server (optional) * `cause`: The underlying error that caused the download to fail (optional) * `message`: The error message containing details about the download failure (optional, auto-generated) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error#checking-for-this-error) --------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_DownloadError` using: 1import { DownloadError } from 'ai';2 3if (DownloadError.isInstance(error)) {4 // Handle the error5} On this page [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error#ai_downloaderror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_InvalidResponseDataError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error#ai_invalidresponsedataerror) =========================================================================================================================================== This error occurs when the server returns a response with invalid data content. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error#properties) -------------------------------------------------------------------------------------------------------- * `data`: The invalid response data value * `message`: The error message [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error#checking-for-this-error) ---------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_InvalidResponseDataError` using: 1import { InvalidResponseDataError } from 'ai';2 3if (InvalidResponseDataError.isInstance(error)) {4 // Handle the error5} On this page [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error#ai_invalidresponsedataerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_InvalidMessageRoleError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error#ai_invalidmessageroleerror) ======================================================================================================================================== This error occurs when an invalid message role is provided. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error#properties) ------------------------------------------------------------------------------------------------------- * `role`: The invalid role value * `message`: The error message (optional, auto-generated from `role`) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error#checking-for-this-error) --------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_InvalidMessageRoleError` using: 1import { InvalidMessageRoleError } from 'ai';2 3if (InvalidMessageRoleError.isInstance(error)) {4 // Handle the error5} On this page [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error#ai_invalidmessageroleerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_JSONParseError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error#ai_jsonparseerror) ============================================================================================================ This error occurs when JSON fails to parse. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error#properties) --------------------------------------------------------------------------------------------- * `text`: The text value that could not be parsed * `cause`: The underlying parsing error (required in constructor) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error#checking-for-this-error) ----------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_JSONParseError` using: 1import { JSONParseError } from 'ai';2 3if (JSONParseError.isInstance(error)) {4 // Handle the error5} On this page [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error#ai_jsonparseerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_InvalidToolInputError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error#ai_invalidtoolinputerror) ================================================================================================================================== This error occurs when invalid tool input was provided. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error#properties) ----------------------------------------------------------------------------------------------------- * `toolName`: The name of the tool with invalid inputs * `toolInput`: The invalid tool inputs * `message`: The error message * `cause`: The cause of the error [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error#checking-for-this-error) ------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_InvalidToolInputError` using: 1import { InvalidToolInputError } from 'ai';2 3if (InvalidToolInputError.isInstance(error)) {4 // Handle the error5} On this page [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error#ai_invalidtoolinputerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_LoadSettingError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error#ai_loadsettingerror) ================================================================================================================== This error occurs when a setting is not loaded successfully. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error#properties) ----------------------------------------------------------------------------------------------- * `message`: The error message [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error#checking-for-this-error) ------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_LoadSettingError` using: 1import { LoadSettingError } from 'ai';2 3if (LoadSettingError.isInstance(error)) {4 // Handle the error5} On this page [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error#ai_loadsettingerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_NoImageGeneratedError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error#ai_noimagegeneratederror) ================================================================================================================================== This error occurs when the AI provider fails to generate an image. It can arise due to the following reasons: * The model failed to generate a response. * The model generated an invalid response. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error#properties) ----------------------------------------------------------------------------------------------------- * `message`: The error message (optional, defaults to `'No image generated.'`). * `responses`: Metadata about the image model responses, including timestamp, model, and headers (optional). * `cause`: The cause of the error. You can use this for more detailed error handling (optional). [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error#checking-for-this-error) ------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_NoImageGeneratedError` using: 1import { generateImage, NoImageGeneratedError } from 'ai';2 3try {4 await generateImage({ model, prompt });5} catch (error) {6 if (NoImageGeneratedError.isInstance(error)) {7 console.log('NoImageGeneratedError');8 console.log('Cause:', error.cause);9 console.log('Responses:', error.responses);10 }11} On this page [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error#ai_noimagegeneratederror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_NoContentGeneratedError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error#ai_nocontentgeneratederror) ======================================================================================================================================== This error occurs when the AI provider fails to generate content. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error#properties) ------------------------------------------------------------------------------------------------------- * `message`: The error message (optional, defaults to `'No content generated.'`) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error#checking-for-this-error) --------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_NoContentGeneratedError` using: 1import { NoContentGeneratedError } from 'ai';2 3if (NoContentGeneratedError.isInstance(error)) {4 // Handle the error5} On this page [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error#ai_nocontentgeneratederror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_InvalidPromptError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error#ai_invalidprompterror) ======================================================================================================================== This error occurs when the prompt provided is invalid. [Potential Causes](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error#potential-causes) ------------------------------------------------------------------------------------------------------------- ### [UI Messages](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error#ui-messages) You are passing a `UIMessage[]` as messages into e.g. `streamText`. You need to first convert them to a `ModelMessage[]` using `convertToModelMessages()`. 1import { type UIMessage, generateText, convertToModelMessages } from 'ai';2 3const messages: UIMessage[] = [4 /* ... */5];6 7const result = await generateText({8 // ...9 messages: await convertToModelMessages(messages),10}); [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error#properties) ------------------------------------------------------------------------------------------------- * `prompt`: The invalid prompt value * `message`: The error message (required in constructor) * `cause`: The cause of the error (optional) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error#checking-for-this-error) --------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_InvalidPromptError` using: 1import { InvalidPromptError } from 'ai';2 3if (InvalidPromptError.isInstance(error)) {4 // Handle the error5} On this page [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error#ai_invalidprompterror) [Potential Causes](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error#potential-causes) [UI Messages](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error#ui-messages) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_NoOutputGeneratedError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error#ai_nooutputgeneratederror) ===================================================================================================================================== This error is thrown when no LLM output was generated, e.g. because of errors. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error#properties) ------------------------------------------------------------------------------------------------------ * `message`: The error message (optional, defaults to `'No output generated.'`) * `cause`: The underlying error that caused no output to be generated (optional) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error#checking-for-this-error) -------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_NoOutputGeneratedError` using: 1import { NoOutputGeneratedError } from 'ai';2 3if (NoOutputGeneratedError.isInstance(error)) {4 // Handle the error5} On this page [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error#ai_nooutputgeneratederror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_NoSpeechGeneratedError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error#ai_nospeechgeneratederror) ===================================================================================================================================== This error occurs when no audio could be generated from the input. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error#properties) ------------------------------------------------------------------------------------------------------ * `responses`: Array of speech model response metadata (required in constructor) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error#checking-for-this-error) -------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_NoSpeechGeneratedError` using: 1import { NoSpeechGeneratedError } from 'ai';2 3if (NoSpeechGeneratedError.isInstance(error)) {4 // Handle the error5} On this page [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error#ai_nospeechgeneratederror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_NoSuchModelError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error#ai_nosuchmodelerror) =================================================================================================================== This error occurs when a model ID is not found. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error#properties) ------------------------------------------------------------------------------------------------ * `modelId`: The ID of the model that was not found * `modelType`: The type of model (`'languageModel'`, `'embeddingModel'`, `'imageModel'`, `'transcriptionModel'`, `'speechModel'`, or `'rerankingModel'`) * `message`: The error message (optional, auto-generated from `modelId` and `modelType`) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error#checking-for-this-error) -------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_NoSuchModelError` using: 1import { NoSuchModelError } from 'ai';2 3if (NoSuchModelError.isInstance(error)) {4 // Handle the error5} On this page [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error#ai_nosuchmodelerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_NoTranscriptGeneratedError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error#ai_notranscriptgeneratederror) ================================================================================================================================================= This error occurs when no transcript could be generated from the input. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error#properties) ---------------------------------------------------------------------------------------------------------- * `responses`: Array of transcription model response metadata (required in constructor) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error#checking-for-this-error) ------------------------------------------------------------------------------------------------------------------------------------ You can check if an error is an instance of `AI_NoTranscriptGeneratedError` using: 1import { NoTranscriptGeneratedError } from 'ai';2 3if (NoTranscriptGeneratedError.isInstance(error)) {4 // Handle the error5} On this page [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error#ai_notranscriptgeneratederror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_NoSuchProviderError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error#ai_nosuchprovidererror) ============================================================================================================================ This error occurs when a provider ID is not found. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error#properties) --------------------------------------------------------------------------------------------------- * `providerId`: The ID of the provider that was not found * `availableProviders`: Array of available provider IDs * `modelId`: The ID of the model * `modelType`: The type of model * `message`: The error message [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error#checking-for-this-error) ----------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_NoSuchProviderError` using: 1import { NoSuchProviderError } from 'ai';2 3if (NoSuchProviderError.isInstance(error)) {4 // Handle the error5} On this page [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error#ai_nosuchprovidererror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_TooManyEmbeddingValuesForCallError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error#ai_toomanyembeddingvaluesforcallerror) ============================================================================================================================================================================ This error occurs when too many values are provided in a single embedding call. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error#properties) --------------------------------------------------------------------------------------------------------------------- * `provider`: The AI provider name * `modelId`: The ID of the embedding model * `maxEmbeddingsPerCall`: The maximum number of embeddings allowed per call * `values`: The array of values that was provided [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error#checking-for-this-error) ----------------------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_TooManyEmbeddingValuesForCallError` using: 1import { TooManyEmbeddingValuesForCallError } from 'ai';2 3if (TooManyEmbeddingValuesForCallError.isInstance(error)) {4 // Handle the error5} On this page [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error#ai_toomanyembeddingvaluesforcallerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_TypeValidationError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error#ai_typevalidationerror) =========================================================================================================================== This error occurs when type validation fails. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error#properties) -------------------------------------------------------------------------------------------------- * `value`: The value that failed validation * `cause`: The underlying validation error (required in constructor) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error#checking-for-this-error) ---------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_TypeValidationError` using: 1import { TypeValidationError } from 'ai';2 3if (TypeValidationError.isInstance(error)) {4 // Handle the error5} On this page [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error#ai_typevalidationerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_InvalidToolApprovalError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error#ai_invalidtoolapprovalerror) =========================================================================================================================================== This error occurs when a tool approval response references an unknown `approvalId`. No matching `tool-approval-request` was found in the message history. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error#properties) -------------------------------------------------------------------------------------------------------- * `approvalId`: The approval ID that was not found [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error#checking-for-this-error) ---------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_InvalidToolApprovalError` using: 1import { InvalidToolApprovalError } from 'ai';2 3if (InvalidToolApprovalError.isInstance(error)) {4 // Handle the error5} On this page [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error#ai_invalidtoolapprovalerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_ToolCallNotFoundForApprovalError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error#ai_toolcallnotfoundforapprovalerror) ====================================================================================================================================================================== This error occurs when a tool approval request references a tool call that was not found. This can happen when processing provider-emitted approval requests (e.g., MCP flows) where the referenced tool call ID does not exist. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error#properties) ------------------------------------------------------------------------------------------------------------------- * `toolCallId`: The tool call ID that was not found * `approvalId`: The approval request ID [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error#checking-for-this-error) --------------------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_ToolCallNotFoundForApprovalError` using: 1import { ToolCallNotFoundForApprovalError } from 'ai';2 3if (ToolCallNotFoundForApprovalError.isInstance(error)) {4 // Handle the error5} On this page [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error#ai_toolcallnotfoundforapprovalerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_UnsupportedFunctionalityError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error#ai_unsupportedfunctionalityerror) ========================================================================================================================================================= This error occurs when functionality is not supported. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error#properties) ------------------------------------------------------------------------------------------------------------ * `functionality`: The name of the unsupported functionality * `message`: The error message (optional, auto-generated from `functionality`) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error#checking-for-this-error) -------------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_UnsupportedFunctionalityError` using: 1import { UnsupportedFunctionalityError } from 'ai';2 3if (UnsupportedFunctionalityError.isInstance(error)) {4 // Handle the error5} On this page [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error#ai_unsupportedfunctionalityerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_NoObjectGeneratedError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error#ai_noobjectgeneratederror) ===================================================================================================================================== This error occurs when the AI provider fails to generate a parsable object that conforms to the schema. It can arise due to the following reasons: * The model failed to generate a response. * The model generated a response that could not be parsed. * The model generated a response that could not be validated against the schema. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error#properties) ------------------------------------------------------------------------------------------------------ * `message`: The error message (optional, defaults to `'No object generated.'`). * `text`: The text that was generated by the model. This can be the raw text or the tool call text, depending on the object generation mode (optional). * `response`: Metadata about the language model response, including response id, timestamp, and model (required in constructor). * `usage`: Request token usage (required in constructor). * `finishReason`: Request finish reason. For example 'length' if model generated maximum number of tokens, this could result in a JSON parsing error (required in constructor). * `cause`: The cause of the error (e.g. a JSON parsing error). You can use this for more detailed error handling (optional). [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error#checking-for-this-error) -------------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_NoObjectGeneratedError` using: 1import { generateObject, NoObjectGeneratedError } from 'ai';2 3try {4 await generateObject({ model, schema, prompt });5} catch (error) {6 if (NoObjectGeneratedError.isInstance(error)) {7 console.log('NoObjectGeneratedError');8 console.log('Cause:', error.cause);9 console.log('Text:', error.text);10 console.log('Response:', error.response);11 console.log('Usage:', error.usage);12 console.log('Finish Reason:', error.finishReason);13 }14} On this page [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error#ai_noobjectgeneratederror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_NoSuchToolError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error#ai_nosuchtoolerror) ================================================================================================================ This error occurs when a model tries to call an unavailable tool. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error#properties) ----------------------------------------------------------------------------------------------- * `toolName`: The name of the tool that was not found * `availableTools`: Array of available tool names (optional) * `message`: The error message (optional, auto-generated from `toolName` and `availableTools`) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error#checking-for-this-error) ------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `AI_NoSuchToolError` using: 1import { NoSuchToolError } from 'ai';2 3if (NoSuchToolError.isInstance(error)) {4 // Handle the error5} On this page [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error#ai_nosuchtoolerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_RetryError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error#ai_retryerror) =============================================================================================== This error occurs when a retry operation fails. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error#properties) ---------------------------------------------------------------------------------------- * `reason`: The reason for the retry failure * `lastError`: The most recent error that occurred during retries * `errors`: Array of all errors that occurred during retry attempts * `message`: The error message [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error#checking-for-this-error) ------------------------------------------------------------------------------------------------------------------ You can check if an error is an instance of `AI_RetryError` using: 1import { RetryError } from 'ai';2 3if (RetryError.isInstance(error)) {4 // Handle the error5} On this page [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error#ai_retryerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Azure OpenAI Slow to Stream [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Azure OpenAI Slow To Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow#azure-openai-slow-to-stream) ===================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow#issue) ------------------------------------------------------------------------- When using OpenAI hosted on Azure, streaming is slow and in big chunks. [Cause](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow#cause) ------------------------------------------------------------------------- This is a Microsoft Azure issue. Some users have reported the following solutions: * **Update Content Filtering Settings**: Inside [Azure AI Studio](https://ai.azure.com/) , within "Shared resources" > "Content filters", create a new content filter and set the "Streaming mode (Preview)" under "Output filter" from "Default" to "Asynchronous Filter". [Solution](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow#solution) ------------------------------------------------------------------------------- You can use the [`smoothStream` transformation](https://ai-sdk.dev/docs/ai-sdk-core/generating-text#smoothing-streams) to stream each word individually. 1import { smoothStream, streamText } from 'ai';2 3const result = streamText({4 model,5 prompt,6 experimental_transform: smoothStream(),7}); On this page [Azure OpenAI Slow To Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow#azure-openai-slow-to-stream) [Issue](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow#issue) [Cause](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow#cause) [Solution](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: ToolCallRepairError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error#toolcallrepairerror) ===================================================================================================================== This error occurs when there is a failure while attempting to repair an invalid tool call. This typically happens when the AI attempts to fix either a `NoSuchToolError` or `InvalidToolInputError`. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error#properties) --------------------------------------------------------------------------------------------------- * `originalError`: The original error that triggered the repair attempt (either `NoSuchToolError` or `InvalidToolInputError`) * `message`: The error message * `cause`: The underlying error that caused the repair to fail [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error#checking-for-this-error) ----------------------------------------------------------------------------------------------------------------------------- You can check if an error is an instance of `ToolCallRepairError` using: 1import { ToolCallRepairError } from 'ai';2 3if (ToolCallRepairError.isInstance(error)) {4 // Handle the error5} On this page [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error#toolcallrepairerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error#checking-for-this-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # AI SDK Errors: AI_UIMessageStreamError [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [AI\_APICallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-api-call-error) [AI\_DownloadError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-download-error) [AI\_EmptyResponseBodyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-empty-response-body-error) [AI\_InvalidArgumentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-argument-error) [AI\_InvalidDataContentError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-data-content-error) [AI\_InvalidMessageRoleError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-message-role-error) [AI\_InvalidPromptError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-prompt-error) [AI\_InvalidResponseDataError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-response-data-error) [AI\_InvalidToolApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-approval-error) [AI\_InvalidToolInputError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-invalid-tool-input-error) [AI\_JSONParseError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-json-parse-error) [AI\_LoadAPIKeyError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-api-key-error) [AI\_LoadSettingError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-load-setting-error) [AI\_MessageConversionError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-message-conversion-error) [AI\_NoContentGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-content-generated-error) [AI\_NoImageGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-image-generated-error) [AI\_NoObjectGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-object-generated-error) [AI\_NoOutputGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-output-generated-error) [AI\_NoSpeechGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-speech-generated-error) [AI\_NoSuchModelError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-model-error) [AI\_NoSuchProviderError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-provider-error) [AI\_NoSuchToolError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-such-tool-error) [AI\_NoTranscriptGeneratedError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-no-transcript-generated-error) [AI\_RetryError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-retry-error) [AI\_TooManyEmbeddingValuesForCallError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-too-many-embedding-values-for-call-error) [AI\_ToolCallNotFoundForApprovalError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-not-found-for-approval-error) [ToolCallRepairError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-tool-call-repair-error) [AI\_TypeValidationError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-type-validation-error) [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error) [AI\_UnsupportedFunctionalityError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-unsupported-functionality-error) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) Copy markdown [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error#ai_uimessagestreamerror) =============================================================================================================================== This error occurs when a UI message stream contains invalid or out-of-sequence chunks. Common causes: * Receiving a `text-delta` chunk without a preceding `text-start` chunk * Receiving a `text-end` chunk without a preceding `text-start` chunk * Receiving a `reasoning-delta` chunk without a preceding `reasoning-start` chunk * Receiving a `reasoning-end` chunk without a preceding `reasoning-start` chunk * Receiving a `tool-input-delta` chunk without a preceding `tool-input-start` chunk * Attempting to access a tool invocation that doesn't exist This error often surfaces when an upstream request fails **before any tokens are streamed** and a custom transport tries to write an inline error message to the UI stream without the proper start chunk. [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error#properties) ---------------------------------------------------------------------------------------------------- * `chunkType`: The type of chunk that caused the error (e.g., `text-delta`, `reasoning-end`, `tool-input-delta`) * `chunkId`: The ID associated with the failing chunk (part ID or toolCallId) * `message`: The error message with details about what went wrong [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error#checking-for-this-error) ------------------------------------------------------------------------------------------------------------------------------ You can check if an error is an instance of `AI_UIMessageStreamError` using: 1import { UIMessageStreamError } from 'ai';2 3if (UIMessageStreamError.isInstance(error)) {4 console.log('Chunk type:', error.chunkType);5 console.log('Chunk ID:', error.chunkId);6 // Handle the error7} [Common Solutions](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error#common-solutions) ---------------------------------------------------------------------------------------------------------------- 1. **Ensure proper chunk ordering**: Always send a `*-start` chunk before any `*-delta` or `*-end` chunks for the same ID: 1// Correct order2writer.write({ type: 'text-start', id: 'my-text' });3writer.write({ type: 'text-delta', id: 'my-text', delta: 'Hello' });4writer.write({ type: 'text-end', id: 'my-text' }); 2. **Verify IDs match**: Ensure the `id` used in `*-delta` and `*-end` chunks matches the `id` used in the corresponding `*-start` chunk. 3. **Handle error paths correctly**: When writing error messages in custom transports, ensure you emit the full start/delta/end sequence: 1// When handling errors in custom transports2writer.write({ type: 'text-start', id: errorId });3writer.write({4 type: 'text-delta',5 id: errorId,6 delta: 'Request failed...',7});8writer.write({ type: 'text-end', id: errorId }); 4. **Check stream producer logic**: Review your streaming implementation to ensure chunks are sent in the correct order, especially when dealing with concurrent operations or merged streams. On this page [AI\_UIMessageStreamError](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error#ai_uimessagestreamerror) [Properties](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error#properties) [Checking for this Error](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error#checking-for-this-error) [Common Solutions](https://ai-sdk.dev/docs/reference/ai-sdk-errors/ai-ui-message-stream-error#common-solutions) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Model is not assignable to type "LanguageModelV1" [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type#model-is-not-assignable-to-type-languagemodelv1) ============================================================================================================================================================================= [Issue](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type#issue) --------------------------------------------------------------------------------------- I have updated the AI SDK and now I get the following error: `Type 'SomeModel' is not assignable to type 'LanguageModelV1'.` Similar errors can occur with `EmbeddingModelV3` as well. [Background](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type#background) ------------------------------------------------------------------------------------------------- Sometimes new features are being added to the model specification. This can cause incompatibilities with older provider versions. [Solution](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type#solution) --------------------------------------------------------------------------------------------- Update your provider packages and the AI SDK to the latest version. On this page [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type#model-is-not-assignable-to-type-languagemodelv1) [Issue](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: React error "Maximum update depth exceeded" [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#react-error-maximum-update-depth-exceeded) ===================================================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#issue) ------------------------------------------------------------------------------------------- I am using the AI SDK in a React project with the `useChat` or `useCompletion` hooks and I get the following error when AI responses stream in: `Maximum update depth exceeded`. [Background](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#background) ----------------------------------------------------------------------------------------------------- By default, the UI is re-rendered on every chunk that arrives. This can overload the rendering, especially on slower devices or when complex components need updating (e.g. Markdown). Throttling can mitigate this. [Solution](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#solution) ------------------------------------------------------------------------------------------------- Use the `experimental_throttle` option to throttle the UI updates: ### [`useChat`](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#usechat) page.tsx 1const { messages, ... } = useChat({2 // Throttle the messages and data updates to 50ms:3 experimental_throttle: 504}) ### [`useCompletion`](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#usecompletion) page.tsx 1const { completion, ... } = useCompletion({2 // Throttle the completion and data updates to 50ms:3 experimental_throttle: 504}) On this page [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#react-error-maximum-update-depth-exceeded) [Issue](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#solution) [useChat](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#usechat) [useCompletion](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded#usecompletion) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Object generation failed with OpenAI [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#object-generation-failed-with-openai) ======================================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#issue) ------------------------------------------------------------------------------------------ When using `generateObject` or `streamObject` with OpenAI's structured output generation, you may encounter a `NoObjectGeneratedError` with the finish reason `content-filter`. This error occurs when your Zod schema contains incompatible types that OpenAI's structured output feature cannot process. 1// Problematic code - incompatible schema types2import { generateObject } from 'ai';3import { openai } from '@ai-sdk/openai';4import { z } from 'zod';5 6const result = await generateObject({7 model: openai('gpt-4o-2024-08-06'),8 schema: z.object({9 name: z.string().nullish(), // ❌ .nullish() is not supported10 email: z.string().optional(), // ❌ .optional() is not supported11 age: z.number().nullable(), // ✅ .nullable() is supported12 }),13 prompt: 'Generate a user profile',14});15 16// Error: NoObjectGeneratedError: No object generated.17// Finish reason: content-filter [Background](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#background) ---------------------------------------------------------------------------------------------------- OpenAI's structured output generation uses JSON Schema under the hood and has specific requirements for schema compatibility. The Zod methods `.nullish()` and `.optional()` generate JSON Schema patterns that are incompatible with OpenAI's implementation, causing the model to reject the schema and return a content-filter finish reason. [Solution](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#solution) ------------------------------------------------------------------------------------------------ Replace `.nullish()` and `.optional()` with `.nullable()` in your Zod schemas when using structured output generation with OpenAI models. 1import { generateObject } from 'ai';2import { openai } from '@ai-sdk/openai';3import { z } from 'zod';4 5// Correct approach - use .nullable()6const result = await generateObject({7 model: openai('gpt-4o-2024-08-06'),8 schema: z.object({9 name: z.string().nullable(), // ✅ Use .nullable() instead of .nullish()10 email: z.string().nullable(), // ✅ Use .nullable() instead of .optional()11 age: z.number().nullable(),12 }),13 prompt: 'Generate a user profile',14});15 16console.log(result.object);17// { name: "John Doe", email: "john@example.com", age: 30 }18// or { name: null, email: null, age: 25 } ### [Schema Type Comparison](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#schema-type-comparison) | Zod Type | Compatible | JSON Schema Behavior | | --- | --- | --- | | `.nullable()` | ✅ Yes | Allows `null` or the specified type | | `.optional()` | ❌ No | Field can be omitted (not supported) | | `.nullish()` | ❌ No | Allows `null`, `undefined`, or omitted (not supported) | [Related Information](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#related-information) ---------------------------------------------------------------------------------------------------------------------- * For more details on structured output generation, see [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) * For OpenAI-specific structured output configuration, see [OpenAI Provider - Structured Outputs](https://ai-sdk.dev/providers/ai-sdk-providers/openai#structured-outputs) On this page [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#object-generation-failed-with-openai) [Issue](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#solution) [Schema Type Comparison](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#schema-type-comparison) [Related Information](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter#related-information) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Troubleshooting Copy markdown [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting#troubleshooting) =========================================================================== This section is designed to help you quickly identify and resolve common issues encountered with the AI SDK, ensuring a smoother and more efficient development experience. Report Issues Found a bug? We'd love to hear about it in our GitHub issues. [Open GitHub Issue](https://github.com/vercel/ai/issues/new?assignees=&labels=&projects=&template=1.bug_report.yml) Feature Requests Want to suggest a new feature? Share it with us and the community. [Request Feature](https://github.com/vercel/ai/issues/new?assignees=&labels=&projects=&template=2.feature_request.yml) Ask the Community Join our GitHub discussions to browse for help and best practices. [Ask a question](https://github.com/vercel/ai/discussions) Migration Guides Check out our migration guides to help you upgrade to the latest version. [Migration Guides](https://ai-sdk.dev/docs/migration-guides) On this page [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting#troubleshooting) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Streaming Not Working When Deployed [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed#streaming-not-working-when-deployed) ======================================================================================================================================================= [Issue](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed#issue) ------------------------------------------------------------------------------------------- Streaming with the AI SDK works in my local development environment. However, when deploying, streaming does not work in the deployed app. Instead of streaming, only the full response is returned after a while. [Cause](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed#cause) ------------------------------------------------------------------------------------------- The causes of this issue are varied and depend on the deployment environment. [Solution](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed#solution) ------------------------------------------------------------------------------------------------- You can try the following: * add `'Transfer-Encoding': 'chunked'` and/or `Connection: 'keep-alive'` headers 1return result.toUIMessageStreamResponse({2 headers: {3 'Transfer-Encoding': 'chunked',4 Connection: 'keep-alive',5 },6}); On this page [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed#streaming-not-working-when-deployed) [Issue](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed#issue) [Cause](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed#cause) [Solution](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Missing Tool Results Error [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#missing-tool-results-error) ============================================================================================================================ [Issue](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#issue) ---------------------------------------------------------------------------------- You encounter the error `AI_MissingToolResultsError` with a message like: > Tool results are missing for tool calls: ... [Cause](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#cause) ---------------------------------------------------------------------------------- This error occurs when you attempt to send a new message to the Large Language Model (LLM) while there are pending tool calls from a previous turn that have not yet been resolved. The AI SDK core logic validates that all `tool-call` parts in the conversation history are resolved before proceeding. "Resolved" typically means: 1. The tool has been executed and a `tool-result` has been added to the history. 2. Or, the tool call has triggered a `tool-approval-response` (if using tool approvals). If a tool call is found without a corresponding result or approval response, this error is thrown to prevent sending an invalid conversation history to the model. [Solution](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#solution) ---------------------------------------------------------------------------------------- Ensure that every tool call in your conversation history is properly handled. ### [1\. Provide Tool Results](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#1-provide-tool-results) For standard tool calls, ensure that you provide the output of the tool execution. 1const messages = [2 { role: 'user', content: 'What is the weather in NY?' },3 {4 role: 'assistant',5 content: [6 {7 type: 'tool-call',8 toolCallId: 'call_123',9 toolName: 'getWeather',10 args: { location: 'New York' },11 },12 ],13 },14 // You MUST include this tool message with the result:15 {16 role: 'tool',17 content: [18 {19 type: 'tool-result',20 toolCallId: 'call_123',21 toolName: 'getWeather',22 result: 'Sunny, 25°C',23 },24 ],25 },26 // Now you can add a new user message27 { role: 'user', content: 'And in London?' },28]; ### [2\. Handle Tool Approvals](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#2-handle-tool-approvals) If you are using the tool approval workflow, ensure that you include the `tool-approval-response`. 1const messages = [2 // ... assistant requests tool execution (needs approval)3 {4 role: 'tool',5 content: [6 {7 type: 'tool-approval-response',8 approvalId: 'approval_123',9 approved: true, // or false10 },11 ],12 },13]; On this page [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#missing-tool-results-error) [Issue](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#issue) [Cause](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#cause) [Solution](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#solution) [1\. Provide Tool Results](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#1-provide-tool-results) [2\. Handle Tool Approvals](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error#2-handle-tool-approvals) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Streamable UI Errors [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Streamable UI Component Error](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors#streamable-ui-component-error) ============================================================================================================================ [Issue](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors#issue) ---------------------------------------------------------------------------- * Variable Not Found * Cannot find `div` * `Component` refers to a value, but is being used as a type [Solution](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors#solution) ---------------------------------------------------------------------------------- If you encounter these errors when working with streamable UIs within server actions, it is likely because the file ends in `.ts` instead of `.tsx`. On this page [Streamable UI Component Error](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors#streamable-ui-component-error) [Issue](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors#issue) [Solution](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Streaming Not Working When Proxied [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied#streaming-not-working-when-proxied) ==================================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied#issue) ------------------------------------------------------------------------------------------ Streaming with the AI SDK doesn't work in local development environment, or deployed in some proxy environments. Instead of streaming, only the full response is returned after a while. [Cause](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied#cause) ------------------------------------------------------------------------------------------ The causes of this issue are caused by the proxy middleware. If the middleware is configured to compress the response, it will cause the streaming to fail. [Solution](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied#solution) ------------------------------------------------------------------------------------------------ You can try the following, the solution only affects the streaming API: * add `'Content-Encoding': 'none'` headers 1return result.toUIMessageStreamResponse({2 headers: {3 'Content-Encoding': 'none',4 },5}); On this page [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied#streaming-not-working-when-proxied) [Issue](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied#issue) [Cause](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied#cause) [Solution](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: TypeScript error "Cannot find namespace 'JSX'" [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx#typescript-error-cannot-find-namespace-jsx) ========================================================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx#issue) -------------------------------------------------------------------------------------------- I am using the AI SDK in a project without React, e.g. an Hono server, and I get the following error: `error TS2503: Cannot find namespace 'JSX'.` [Background](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx#background) ------------------------------------------------------------------------------------------------------ The AI SDK has a dependency on `@types/react` which defines the `JSX` namespace. It will be removed in the next major version of the AI SDK. [Solution](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx#solution) -------------------------------------------------------------------------------------------------- You can install the `@types/react` package as a dependency to fix the error. 1npm install @types/react On this page [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx#typescript-error-cannot-find-namespace-jsx) [Issue](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Jest: cannot find module '@ai-sdk/rsc' [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc#jest-cannot-find-module-ai-sdkrsc) =================================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc#issue) -------------------------------------------------------------------------------------- I am using AI SDK RSC and am writing tests for my RSC components with Jest. I am getting the following error: `Cannot find module '@ai-sdk/rsc'`. [Solution](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc#solution) -------------------------------------------------------------------------------------------- Configure the module resolution via `jest config update` in `moduleNameMapper`: jest.config.js 1"moduleNameMapper": {2 "^@ai-sdk/rsc$": "/node_modules/@ai-sdk/rsc/dist"3} On this page [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc#jest-cannot-find-module-ai-sdkrsc) [Issue](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc#issue) [Solution](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Repeated assistant messages in useChat [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages#repeated-assistant-messages-in-usechat) ===================================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages#issue) ----------------------------------------------------------------------------------- When using `useChat` with `streamText` on the server, the assistant's messages appear duplicated in the UI - showing both the previous message and the new message, or showing the same message multiple times. This can occur when using tool calls or complex message flows. 1// Server-side code that may experience assistant message duplication on the client2export async function POST(req: Request) {3 const { messages } = await req.json();4 5 const result = streamText({6 model: 'openai/gpt-5-mini',7 messages: await convertToModelMessages(messages),8 tools: {9 weather: {10 description: 'Get the weather for a location',11 parameters: z.object({12 location: z.string(),13 }),14 execute: async ({ location }) => {15 return { temperature: 72, condition: 'sunny' };16 },17 },18 },19 });20 21 return result.toUIMessageStreamResponse();22} [Background](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages#background) --------------------------------------------------------------------------------------------- The duplication occurs because `toUIMessageStreamResponse` generates new message IDs for each new message. [Solution](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages#solution) ----------------------------------------------------------------------------------------- Pass the original messages array to `toUIMessageStreamResponse` using the `originalMessages` option. By passing `originalMessages`, the method can reuse existing message IDs instead of generating new ones, ensuring the client properly updates existing messages rather than creating duplicates. 1export async function POST(req: Request) {2 const { messages } = await req.json();3 4 const result = streamText({5 model: 'openai/gpt-5-mini',6 messages: await convertToModelMessages(messages),7 tools: {8 weather: {9 description: 'Get the weather for a location',10 parameters: z.object({11 location: z.string(),12 }),13 execute: async ({ location }) => {14 return { temperature: 72, condition: 'sunny' };15 },16 },17 },18 });19 20 return result.toUIMessageStreamResponse({21 originalMessages: messages, // Pass the original messages here22 generateMessageId: generateId,23 onFinish: ({ messages }) => {24 saveChat({ id, messages });25 },26 });27} On this page [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages#repeated-assistant-messages-in-usechat) [Issue](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Streaming Status Shows But No Text Appears [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay#streaming-status-shows-but-no-text-appears) ======================================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay#issue) ------------------------------------------------------------------------------ When using `useChat`, the status changes to "streaming" immediately, but no text appears for several seconds. [Background](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay#background) ---------------------------------------------------------------------------------------- The status changes to "streaming" as soon as the connection to the server is established and streaming begins - this includes metadata streaming, not just the LLM's generated tokens. [Solution](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay#solution) ------------------------------------------------------------------------------------ Create a custom loading state that checks if the last assistant message actually contains content: 1'use client';2 3import { useChat } from '@ai-sdk/react';4 5export default function Page() {6 const { messages, status } = useChat();7 8 const lastMessage = messages.at(-1);9 10 const showLoader =11 status === 'streaming' &&12 lastMessage?.role === 'assistant' &&13 lastMessage?.parts?.length === 0;14 15 return (16 <>17 {messages.map(message => (18
19 {message.role === 'user' ? 'User: ' : 'AI: '}20 {message.parts.map((part, index) =>21 part.type === 'text' ? {part.text} : null,22 )}23
24 ))}25 26 {showLoader &&
Loading...
}27 28 );29} You can also check for specific part types if you're waiting for something specific: 1const showLoader =2 status === 'streaming' &&3 lastMessage?.role === 'assistant' &&4 !lastMessage?.parts?.some(part => part.type === 'text'); [Related Issues](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay#related-issues) ------------------------------------------------------------------------------------------------ * [GitHub Issue #7586](https://github.com/vercel/ai/issues/7586) On this page [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay#streaming-status-shows-but-no-text-appears) [Issue](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay#solution) [Related Issues](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay#related-issues) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: useChat/useCompletion stream output contains 0:... instead of text [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output#usechatusecompletion-stream-output-contains-0-instead-of-text) ================================================================================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output#issue) ----------------------------------------------------------------------------- I am using custom client code to process a server response that is sent using `StreamingTextResponse`. I am using version `3.0.20` or newer of the AI SDK. When I send a query, the UI streams text such as `0: "Je"`, `0: " suis"`, `0: "des"...` instead of the text that I’m looking for. [Background](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output#background) --------------------------------------------------------------------------------------- The AI SDK has switched to the stream data protocol in version `3.0.20`. It sends different stream parts to support data, tool calls, etc. What you see is the raw stream data protocol response. [Solution](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output#solution) ----------------------------------------------------------------------------------- You have several options: 1. Use the AI Core [`streamText`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) function to send a raw text stream: 1export async function POST(req: Request) {2 const { prompt } = await req.json();3 4 const result = streamText({5 model: openai.completion('gpt-3.5-turbo-instruct'),6 maxOutputTokens: 2000,7 prompt,8 });9 10 return result.toTextStreamResponse();11} 2. Pin the AI SDK version to `3.0.19` . This will keep the raw text stream. On this page [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output#usechatusecompletion-stream-output-contains-0-instead-of-text) [Issue](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Abort breaks resumable streams [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#abort-breaks-resumable-streams) ======================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#issue) -------------------------------------------------------------------------------------- When using `useChat` with `resume: true` for stream resumption, the abort functionality breaks. Closing a tab, refreshing the page, or calling the `stop()` function will trigger an abort signal that interferes with the resumption mechanism, preventing streams from being properly resumed. 1// This configuration will cause conflicts2const { messages, stop } = useChat({3 id: chatId,4 resume: true, // Stream resumption enabled5});6 7// Closing the tab will trigger abort and stop resumption [Background](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#background) ------------------------------------------------------------------------------------------------ When a page is closed or refreshed, the browser automatically sends an abort signal, which breaks the resumption flow. [Current limitations](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#current-limitations) ------------------------------------------------------------------------------------------------------------------ We're aware of this incompatibility and are exploring solutions. **In the meantime, please choose either stream resumption or abort functionality based on your application's requirements**, but not both. ### [Option 1: Use stream resumption without abort](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#option-1-use-stream-resumption-without-abort) If you need to support long-running generations that persist across page reloads: 1const { messages, sendMessage } = useChat({2 id: chatId,3 resume: true,4}); ### [Option 2: Use abort without stream resumption](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#option-2-use-abort-without-stream-resumption) If you need to allow users to stop streams manually: 1const { messages, sendMessage, stop } = useChat({2 id: chatId,3 resume: false, // Disable stream resumption (default behavior)4}); [Related](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#related) ------------------------------------------------------------------------------------------ * [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) * [Stopping Streams](https://ai-sdk.dev/docs/advanced/stopping-streams) On this page [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#abort-breaks-resumable-streams) [Issue](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#background) [Current limitations](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#current-limitations) [Option 1: Use stream resumption without abort](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#option-1-use-stream-resumption-without-abort) [Option 2: Use abort without stream resumption](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#option-2-use-abort-without-stream-resumption) [Related](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams#related) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Getting Timeouts When Deploying on Vercel [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#getting-timeouts-when-deploying-on-vercel) ================================================================================================================================================= [Issue](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#issue) ------------------------------------------------------------------------- Streaming with the AI SDK works in my local development environment. However, when I'm deploying to Vercel, longer responses get chopped off in the UI and I'm seeing timeouts in the Vercel logs or I'm seeing the error: `Uncaught (in promise) Error: Connection closed`. [Solution](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#solution) ------------------------------------------------------------------------------- With Vercel's [Fluid Compute](https://vercel.com/docs/fluid-compute) , the default function duration is now **5 minutes (300 seconds)** across all plans. This should be sufficient for most streaming applications. If you need to extend the timeout for longer-running processes, you can increase the `maxDuration` setting: ### [Next.js (App Router)](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#nextjs-app-router) Add the following to your route file or the page you are calling your Server Action from: 1export const maxDuration = 600; Setting `maxDuration` above 300 seconds requires a Pro or Enterprise plan. ### [Other Frameworks](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#other-frameworks) For other frameworks, you can set timeouts in your `vercel.json` file: 1{2 "functions": {3 "api/chat/route.ts": {4 "maxDuration": 6005 }6 }7} Setting `maxDuration` above 300 seconds requires a Pro or Enterprise plan. ### [Maximum Duration Limits](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#maximum-duration-limits) The maximum duration you can set depends on your Vercel plan: * **Hobby**: Up to 300 seconds (5 minutes) * **Pro**: Up to 800 seconds (~13 minutes) * **Enterprise**: Up to 800 seconds (~13 minutes) [Learn more](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#learn-more) ----------------------------------------------------------------------------------- * [Fluid Compute Default Settings](https://vercel.com/docs/fluid-compute#default-settings-by-plan) * [Configuring Maximum Duration for Vercel Functions](https://vercel.com/docs/functions/configuring-functions/duration) On this page [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#getting-timeouts-when-deploying-on-vercel) [Issue](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#issue) [Solution](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#solution) [Next.js (App Router)](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#nextjs-app-router) [Other Frameworks](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#other-frameworks) [Maximum Duration Limits](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#maximum-duration-limits) [Learn more](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel#learn-more) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: TypeScript performance issues with Zod and AI SDK 5 [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#typescript-performance-issues-with-zod-and-ai-sdk-5) ============================================================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#issue) ---------------------------------------------------------------------------------- When using the AI SDK 5 with Zod, you may experience: * TypeScript server crashes or hangs * Extremely slow type checking in files that import AI SDK functions * Error messages like "Type instantiation is excessively deep and possibly infinite" * IDE becoming unresponsive when working with AI SDK code [Background](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#background) -------------------------------------------------------------------------------------------- The AI SDK 5 has specific compatibility requirements with Zod versions. When importing Zod using the standard import path (`import { z } from 'zod'`), TypeScript's type inference can become excessively complex, leading to performance degradation or crashes. [Solution](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#solution) ---------------------------------------------------------------------------------------- ### [Upgrade Zod to 4.1.8 or Later](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#upgrade-zod-to-418-or-later) The primary solution is to upgrade to Zod version 4.1.8 or later, which includes a fix for this module resolution issue: 1pnpm add zod@^4.1.8 This version resolves the underlying problem where different module resolution settings were causing TypeScript to load the same Zod declarations twice, leading to expensive structural comparisons. ### [Alternative: Update TypeScript Configuration](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#alternative-update-typescript-configuration) If upgrading Zod isn't possible, you can update your `tsconfig.json` to use `moduleResolution: "nodenext"`: 1{2 "compilerOptions": {3 "moduleResolution": "nodenext"4 // ... other options5 }6} This resolves the TypeScript performance issues while allowing you to continue using the standard Zod import. On this page [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#typescript-performance-issues-with-zod-and-ai-sdk-5) [Issue](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#solution) [Upgrade Zod to 4.1.8 or Later](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#upgrade-zod-to-418-or-later) [Alternative: Update TypeScript Configuration](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod#alternative-update-typescript-configuration) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Tool Invocation Missing Result Error [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result#tool-invocation-missing-result-error) ==================================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result#issue) -------------------------------------------------------------------------------------- When using `generateText()` or `streamText()`, you may encounter the error "ToolInvocation must have a result" when a tool without an `execute` function is called. [Cause](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result#cause) -------------------------------------------------------------------------------------- The error occurs when you define a tool without an `execute` function and don't provide the result through other means (like `useChat`'s `onToolCall` or `addToolOutput` functions). Each time a tool is invoked, the model expects to receive a result before continuing the conversation. Without a result, the model cannot determine if the tool call succeeded or failed and the conversation state becomes invalid. [Solution](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result#solution) -------------------------------------------------------------------------------------------- You have two options for handling tool results: 1. Server-side execution using tools with an `execute` function: 1const tools = {2 weather: tool({3 description: 'Get the weather in a location',4 parameters: z.object({5 location: z6 .string()7 .describe('The city and state, e.g. "San Francisco, CA"'),8 }),9 execute: async ({ location }) => {10 // Fetch and return weather data11 return { temperature: 72, conditions: 'sunny', location };12 },13 }),14}; 2. Client-side execution with `useChat` (omitting the `execute` function), you must provide results using `addToolOutput`: 1import { useChat } from '@ai-sdk/react';2import {3 DefaultChatTransport,4 lastAssistantMessageIsCompleteWithToolCalls,5} from 'ai';6 7const { messages, sendMessage, addToolOutput } = useChat({8 // Automatically submit when all tool results are available9 sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,10 11 // Handle tool calls in onToolCall12 onToolCall: async ({ toolCall }) => {13 if (toolCall.toolName === 'getLocation') {14 try {15 const result = await getLocationData();16 17 // Important: Don't await inside onToolCall to avoid deadlocks18 addToolOutput({19 tool: 'getLocation',20 toolCallId: toolCall.toolCallId,21 output: result,22 });23 } catch (err) {24 // Important: Don't await inside onToolCall to avoid deadlocks25 addToolOutput({26 tool: 'getLocation',27 toolCallId: toolCall.toolCallId,28 state: 'output-error',29 errorText: 'Failed to get location',30 });31 }32 }33 },34}); 1// For interactive UI elements:2const { messages, sendMessage, addToolOutput } = useChat({3 transport: new DefaultChatTransport({ api: '/api/chat' }),4 sendAutomaticallyWhen: lastAssistantMessageIsCompleteWithToolCalls,5});6 7// Inside your JSX, when rendering tool calls:810 addToolOutput({11 tool: 'myTool',12 toolCallId, // must provide tool call ID13 output: {14 /* your tool result */15 },16 })17 }18>19 Confirm20; Whether handling tools on the server or client, each tool call must have a corresponding result before the conversation can continue. On this page [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result#tool-invocation-missing-result-error) [Issue](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result#issue) [Cause](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result#cause) [Solution](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Tool calling with generateObject and streamObject [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Tool calling with generateObject and streamObject (structured outputs)](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs#tool-calling-with-generateobject-and-streamobject-structured-outputs) ============================================================================================================================================================================================================================ [Issue](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs#issue) -------------------------------------------------------------------------------------------- You may want to combine tool calling with structured output generation. While `generateObject` and `streamObject` are designed specifically for structured outputs, they don't support tool calling. [Background](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs#background) ------------------------------------------------------------------------------------------------------ To use tool calling with structured outputs, use `generateText` or `streamText` with the `output` option. **Important**: When using `output` with tool calling, the structured output generation counts as an additional step in the execution flow. [Solution](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs#solution) -------------------------------------------------------------------------------------------------- When using `output` with tool calling, adjust your `stopWhen` condition to account for the additional step required for structured output generation: Gateway Provider Custom Claude Sonnet 4.5 1const result = await generateText({2 model: "anthropic/claude-sonnet-4.5",3 output: Output.object({4 schema: z.object({5 summary: z.string(),6 sentiment: z.enum(['positive', 'neutral', 'negative']),7 }),8 }),9 tools: {10 analyze: tool({11 description: 'Analyze data',12 inputSchema: z.object({13 data: z.string(),14 }),15 execute: async ({ data }) => {16 return { result: 'analyzed' };17 }),18 },19 },20 // Add at least 1 to your intended step count to account for structured output21 stopWhen: stepCountIs(3), // Now accounts for: tool call + tool result + structured output22 prompt: 'Analyze the data and provide a summary',23}); For more information about using structured outputs with `generateText` and `streamText` see [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data#structured-outputs-with-generatetext-and-streamtext) . On this page [Tool calling with generateObject and streamObject (structured outputs)](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs#tool-calling-with-generateobject-and-streamobject-structured-outputs) [Issue](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: onFinish not called when stream is aborted [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling#onfinish-not-called-when-stream-is-aborted) ======================================================================================================================================================= [Issue](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling#issue) ----------------------------------------------------------------------------- When using `toUIMessageStreamResponse` with an `onFinish` callback, the callback may not execute when the stream is aborted. This happens because the abort handler immediately terminates the response, preventing the `onFinish` callback from being triggered. Gateway Provider Custom Claude Sonnet 4.5 1// Server-side code where onFinish isn't called on abort2export async function POST(req: Request) {3 const { messages } = await req.json();4 5 const result = streamText({6 model: "anthropic/claude-sonnet-4.5",7 messages: await convertToModelMessages(messages),8 abortSignal: req.signal,9 });10 11 return result.toUIMessageStreamResponse({12 onFinish: async ({ isAborted }) => {13 // This isn't called when the stream is aborted!14 if (isAborted) {15 console.log('Stream was aborted');16 // Handle abort-specific cleanup17 } else {18 console.log('Stream completed normally');19 // Handle normal completion20 }21 },22 });23} [Background](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling#background) --------------------------------------------------------------------------------------- When a stream is aborted, the response is immediately terminated. Without proper handling, the `onFinish` callback has no chance to execute, preventing important cleanup operations like saving partial results or logging abort events. [Solution](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling#solution) ----------------------------------------------------------------------------------- Add `consumeStream` to the `toUIMessageStreamResponse` configuration. This ensures that abort events are properly captured and forwarded to the `onFinish` callback, allowing it to execute even when the stream is aborted. Gateway Provider Custom Claude Sonnet 4.5 1// other imports...2import { consumeStream } from 'ai';3 4export async function POST(req: Request) {5 const { messages } = await req.json();6 7 const result = streamText({8 model: "anthropic/claude-sonnet-4.5",9 messages: await convertToModelMessages(messages),10 abortSignal: req.signal,11 });12 13 return result.toUIMessageStreamResponse({14 onFinish: async ({ isAborted }) => {15 // Now this WILL be called even when aborted!16 if (isAborted) {17 console.log('Stream was aborted');18 // Handle abort-specific cleanup19 } else {20 console.log('Stream completed normally');21 // Handle normal completion22 }23 },24 consumeSseStream: consumeStream, // This enables onFinish to be called on abort25 });26} On this page [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling#onfinish-not-called-when-stream-is-aborted) [Issue](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: streamText fails silently [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [`streamText` is not working](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working#streamtext-is-not-working) ========================================================================================================================= [Issue](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working#issue) ------------------------------------------------------------------------------- I am using [`streamText`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) function, and it does not work. It does not throw any errors and the stream is only containing error parts. [Background](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working#background) ----------------------------------------------------------------------------------------- `streamText` immediately starts streaming to enable sending data without waiting for the model. Errors become part of the stream and are not thrown to prevent e.g. servers from crashing. [Solution](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working#solution) ------------------------------------------------------------------------------------- To log errors, you can provide an `onError` callback that is triggered when an error occurs. Gateway Provider Custom Claude Sonnet 4.5 1import { streamText } from 'ai';2 3const result = streamText({4 model: "anthropic/claude-sonnet-4.5",5 prompt: 'Invent a new holiday and describe its traditions.',6 onError({ error }) {7 console.error(error); // your error logging logic here8 },9}); On this page [streamText is not working](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working#streamtext-is-not-working) [Issue](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Unclosed Streams [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams#unclosed-streams) ============================================================================================== Sometimes streams are not closed properly, which can lead to unexpected behavior. The following are some common issues that can occur when streams are not closed properly. [Issue](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams#issue) ------------------------------------------------------------------------ The streamable UI has been slow to update. [Solution](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams#solution) ------------------------------------------------------------------------------ This happens when you create a streamable UI using [`createStreamableUI`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui) and fail to close the stream. In order to fix this, you must ensure you close the stream by calling the [`.done()`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-ui#done) method. This will ensure the stream is closed. 1import { createStreamableUI } from '@ai-sdk/rsc';2 3const submitMessage = async () => {4 'use server';5 6 const stream = createStreamableUI('1');7 8 stream.update('2');9 stream.append('3');10 stream.done('4'); // [!code ++]11 12 return stream.value;13}; On this page [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams#unclosed-streams) [Issue](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams#issue) [Solution](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Server Actions in Client Components [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components#server-actions-in-client-components) ======================================================================================================================================================= You may use Server Actions in client components, but sometimes you may encounter the following issues. [Issue](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components#issue) ------------------------------------------------------------------------------------------- It is not allowed to define inline `"use server"` annotated Server Actions in Client Components. [Solution](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components#solution) ------------------------------------------------------------------------------------------------- To use Server Actions in a Client Component, you can either: * Export them from a separate file with `"use server"` at the top. * Pass them down through props from a Server Component. * Implement a combination of [`createAI`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-ai) and [`useActions`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/use-actions) hooks to access them. Learn more about [Server Actions and Mutations](https://nextjs.org/docs/app/api-reference/functions/server-actions#with-client-components) . Gateway Provider Custom Claude Sonnet 4.5 1'use server';2 3import { generateText } from 'ai';4 5export async function getAnswer(question: string) {6 'use server';7 8 const { text } = await generateText({9 model: "anthropic/claude-sonnet-4.5",10 prompt: question,11 });12 13 return { answer: text };14} On this page [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components#server-actions-in-client-components) [Issue](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components#issue) [Solution](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Unsupported model version error [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#unsupported-model-version-error) ===================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#issue) --------------------------------------------------------------------------------- When migrating to AI SDK 5, you might encounter an error stating that your model uses an unsupported version: 1AI_UnsupportedModelVersionError: Unsupported model version v1 for provider "ollama.chat" and model "gamma3:4b".2AI SDK 5 only supports models that implement specification version "v2". This error occurs because the version of the provider package you're using implements the older (v1) model specification. [Background](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#background) ------------------------------------------------------------------------------------------- AI SDK 5 requires all provider packages to implement specification version "v2". When you upgrade to AI SDK 5 but don't update your provider packages to compatible versions, they continue using the older "v1" specification, causing this error. [Solution](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#solution) --------------------------------------------------------------------------------------- ### [Update provider packages to AI SDK 5 compatible versions](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#update-provider-packages-to-ai-sdk-5-compatible-versions) Update all your `@ai-sdk/*` provider packages to compatible version `2.0.0` or later. These versions implement the v2 specification required by AI SDK 5. 1pnpm install ai@latest @ai-sdk/openai@latest @ai-sdk/anthropic@latest For AI SDK 5 compatibility, you need: * `ai` package: `5.0.0` or later * `@ai-sdk/*` packages: `2.0.0` or later (for example, `@ai-sdk/openai`, `@ai-sdk/anthropic`, `@ai-sdk/google`) * `@ai-sdk/provider` package: `2.0.0` or later * `zod` package: `4.1.8` or later ### [Check provider compatibility](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#check-provider-compatibility) If you're using a third-party or custom provider, verify that it has been updated to support AI SDK 5. Not all providers may have v2-compatible versions available yet. To check if a provider supports AI SDK 5: 1. Check the provider's package.json for `@ai-sdk/provider` peer dependency version `2.0.0` or later 2. Review the provider's changelog or migration guide 3. Check the provider's repository for AI SDK 5 support For more information on migrating to AI SDK 5, see the [AI SDK 5.0 migration guide](https://ai-sdk.dev/docs/migration-guides/migration-guide-5-0) . On this page [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#unsupported-model-version-error) [Issue](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#solution) [Update provider packages to AI SDK 5 compatible versions](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#update-provider-packages-to-ai-sdk-5-compatible-versions) [Check provider compatibility](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version#check-provider-compatibility) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: useChat "An error occurred" [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [`useChat` "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred#usechat-an-error-occurred) ============================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred#issue) ---------------------------------------------------------------------------------- I am using [`useChat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) and I get the error "An error occurred". [Background](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred#background) -------------------------------------------------------------------------------------------- Error messages from `streamText` are masked by default when using `toDataStreamResponse` for security reasons (secure-by-default). This prevents leaking sensitive information to the client. [Solution](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred#solution) ---------------------------------------------------------------------------------------- To forward error details to the client or to log errors, use the `getErrorMessage` function when calling `toDataStreamResponse`. 1export function errorHandler(error: unknown) {2 if (error == null) {3 return 'unknown error';4 }5 6 if (typeof error === 'string') {7 return error;8 }9 10 if (error instanceof Error) {11 return error.message;12 }13 14 return JSON.stringify(error);15} 1const result = streamText({2 // ...3});4 5return result.toUIMessageStreamResponse({6 getErrorMessage: errorHandler,7}); In case you are using `createDataStreamResponse`, you can use the `onError` function when calling `toDataStreamResponse`: 1const response = createDataStreamResponse({2 // ...3 async execute(dataStream) {4 // ...5 },6 onError: errorHandler,7}); On this page [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred#usechat-an-error-occurred) [Issue](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Server Action Plain Objects Error [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown ["Only plain objects can be passed from client components" Server Action Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error#only-plain-objects-can-be-passed-from-client-components-server-action-error) ========================================================================================================================================================================================================================= [Issue](https://ai-sdk.dev/docs/troubleshooting/client-stream-error#issue) --------------------------------------------------------------------------- I am using [`streamText`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) or [`streamObject`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-object) with Server Actions, and I am getting a `"only plain objects and a few built ins can be passed from client components"` error. [Background](https://ai-sdk.dev/docs/troubleshooting/client-stream-error#background) ------------------------------------------------------------------------------------- This error occurs when you're trying to return a non-serializable object from a Server Action to a Client Component. The streamText function likely returns an object with methods or complex structures that can't be directly serialized and passed to the client. [Solution](https://ai-sdk.dev/docs/troubleshooting/client-stream-error#solution) --------------------------------------------------------------------------------- To fix this issue, you need to ensure that you're only returning serializable data from your Server Action. Here's how you can modify your approach: 1. Instead of returning the entire result object from streamText, extract only the necessary serializable data. 2. Use the [`createStreamableValue`](https://ai-sdk.dev/docs/reference/ai-sdk-rsc/create-streamable-value) function to create a streamable value that can be safely passed to the client. Here's an example that demonstrates how to implement this solution: [Streaming Text Generation](https://ai-sdk.dev/examples/next-app/basics/streaming-text-generation) . This approach ensures that only serializable data (the text) is passed to the client, avoiding the "only plain objects" error. On this page ["Only plain objects can be passed from client components" Server Action Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error#only-plain-objects-can-be-passed-from-client-components-server-action-error) [Issue](https://ai-sdk.dev/docs/troubleshooting/client-stream-error#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/client-stream-error#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/client-stream-error#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: useChat Failed to Parse Stream [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [`useChat` "Failed to Parse Stream String" Error](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream#usechat-failed-to-parse-stream-string-error) ======================================================================================================================================================================= [Issue](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream#issue) --------------------------------------------------------------------------------------- I am using [`useChat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) or [`useCompletion`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) , and I am getting a `"Failed to parse stream string. Invalid code"` error. I am using version `3.0.20` or newer of the AI SDK. [Background](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream#background) ------------------------------------------------------------------------------------------------- The AI SDK has switched to the stream data protocol in version `3.0.20`. [`useChat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) and [`useCompletion`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) expect stream parts that support data, tool calls, etc. What you see is a failure to parse the stream. This can be caused by using an older version of the AI SDK in the backend, by providing a text stream using a custom provider, or by using a raw LangChain stream result. [Solution](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream#solution) --------------------------------------------------------------------------------------------- You can switch [`useChat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) and [`useCompletion`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion) to raw text stream processing with the [`streamProtocol`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-completion#stream-protocol) parameter. Set it to `text` as follows: 1const { messages, append } = useChat({ streamProtocol: 'text' }); On this page [useChat "Failed to Parse Stream String" Error](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream#usechat-failed-to-parse-stream-string-error) [Issue](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Custom headers, body, and credentials not working with useChat [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#custom-headers-body-and-credentials-not-working-with-usechat) ======================================================================================================================================================================================================= [Issue](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#issue) --------------------------------------------------------------------------------------- When using the `useChat` hook, custom request options like headers, body fields, and credentials configured directly on the hook are not being sent with the request: 1// These options are not sent with the request2const { messages, sendMessage } = useChat({3 headers: {4 Authorization: 'Bearer token123',5 },6 body: {7 user_id: '123',8 },9 credentials: 'include',10}); [Background](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#background) ------------------------------------------------------------------------------------------------- The `useChat` hook has changed its API for configuring request options. Direct options like `headers`, `body`, and `credentials` on the hook itself are no longer supported. Instead, you need to use the `transport` configuration with `DefaultChatTransport` or pass options at the request level. [Solution](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#solution) --------------------------------------------------------------------------------------------- There are three ways to properly configure request options with `useChat`: ### [Option 1: Request-Level Configuration (Recommended for Dynamic Values)](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#option-1-request-level-configuration-recommended-for-dynamic-values) For dynamic values that change over time, the recommended approach is to pass options when calling `sendMessage`: 1const { messages, sendMessage } = useChat();2 3// Send options with each message4sendMessage(5 { text: input },6 {7 headers: {8 Authorization: `Bearer ${getAuthToken()}`, // Dynamic auth token9 'X-Request-ID': generateRequestId(),10 },11 body: {12 temperature: 0.7,13 max_tokens: 100,14 user_id: getCurrentUserId(), // Dynamic user ID15 sessionId: getCurrentSessionId(), // Dynamic session16 },17 },18); This approach ensures that the most up-to-date values are always sent with each request. ### [Option 2: Hook-Level Configuration with Static Values](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#option-2-hook-level-configuration-with-static-values) For static values that don't change during the component lifecycle, use the `DefaultChatTransport`: 1import { useChat } from '@ai-sdk/react';2import { DefaultChatTransport } from 'ai';3 4const { messages, sendMessage } = useChat({5 transport: new DefaultChatTransport({6 api: '/api/chat',7 headers: {8 'X-API-Version': 'v1', // Static API version9 'X-App-ID': 'my-app', // Static app identifier10 },11 body: {12 model: 'gpt-5.1', // Default model13 stream: true, // Static configuration14 },15 credentials: 'include', // Static credentials policy16 }),17}); ### [Option 3: Hook-Level Configuration with Resolvable Functions](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#option-3-hook-level-configuration-with-resolvable-functions) If you need dynamic values at the hook level, you can use functions that return configuration values. However, request-level configuration is generally preferred for better reliability: 1import { useChat } from '@ai-sdk/react';2import { DefaultChatTransport } from 'ai';3 4const { messages, sendMessage } = useChat({5 transport: new DefaultChatTransport({6 api: '/api/chat',7 headers: () => ({8 Authorization: `Bearer ${getAuthToken()}`,9 'X-User-ID': getCurrentUserId(),10 }),11 body: () => ({12 sessionId: getCurrentSessionId(),13 preferences: getUserPreferences(),14 }),15 credentials: () => (isAuthenticated() ? 'include' : 'same-origin'),16 }),17}); For component state that changes over time, request-level configuration (Option 1) is recommended. If using hook-level functions, consider using `useRef` to store current values and reference `ref.current` in your configuration function. ### [Combining Hook and Request Level Options](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#combining-hook-and-request-level-options) Request-level options take precedence over hook-level options: 1// Hook-level default configuration2const { messages, sendMessage } = useChat({3 transport: new DefaultChatTransport({4 api: '/api/chat',5 headers: {6 'X-API-Version': 'v1',7 },8 body: {9 model: 'gpt-5.1',10 },11 }),12});13 14// Override or add options per request15sendMessage(16 { text: input },17 {18 headers: {19 'X-API-Version': 'v2', // This overrides the hook-level header20 'X-Request-ID': '123', // This is added21 },22 body: {23 model: 'gpt-5-mini', // This overrides the hook-level body field24 temperature: 0.5, // This is added25 },26 },27); For more details on request configuration, see the [Request Configuration](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot#request-configuration) documentation. On this page [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#custom-headers-body-and-credentials-not-working-with-usechat) [Issue](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#solution) [Option 1: Request-Level Configuration (Recommended for Dynamic Values)](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#option-1-request-level-configuration-recommended-for-dynamic-values) [Option 2: Hook-Level Configuration with Static Values](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#option-2-hook-level-configuration-with-static-values) [Option 3: Hook-Level Configuration with Resolvable Functions](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#option-3-hook-level-configuration-with-resolvable-functions) [Combining Hook and Request Level Options](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options#combining-hook-and-request-level-options) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Type Error with onToolCall [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing#type-error-with-ontoolcall) =========================================================================================================================== When using the `onToolCall` callback with TypeScript, you may encounter type errors when trying to pass tool properties directly to `addToolOutput`. [Problem](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing#problem) ------------------------------------------------------------------------------------- TypeScript cannot automatically narrow the type of `toolCall.toolName` when you have both static and dynamic tools, leading to type errors: 1// ❌ This causes a TypeScript error2const { messages, sendMessage, addToolOutput } = useChat({3 async onToolCall({ toolCall }) {4 addToolOutput({5 tool: toolCall.toolName, // Type 'string' is not assignable to type '"yourTool" | "yourOtherTool"'6 toolCallId: toolCall.toolCallId,7 output: someOutput,8 });9 },10}); The error occurs because: * Static tools have specific literal types for their names (e.g., `"getWeatherInformation"`) * Dynamic tools have `toolName` as a generic `string` * TypeScript can't guarantee that `toolCall.toolName` matches your specific tool names [Solution](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing#solution) --------------------------------------------------------------------------------------- Check if the tool is dynamic first to enable proper type narrowing: 1// ✅ Correct approach with type narrowing2const { messages, sendMessage, addToolOutput } = useChat({3 async onToolCall({ toolCall }) {4 // Check if it's a dynamic tool first5 if (toolCall.dynamic) {6 return;7 }8 9 // Now TypeScript knows this is a static tool with the correct type10 addToolOutput({11 tool: toolCall.toolName, // No type error!12 toolCallId: toolCall.toolCallId,13 output: someOutput,14 });15 },16}); If you're still using the deprecated `addToolResult` method, this solution applies the same way. Consider migrating to `addToolOutput` for consistency with the latest API. [Related](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing#related) ------------------------------------------------------------------------------------- * [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) * [Dynamic Tools](https://ai-sdk.dev/docs/reference/ai-sdk-core/dynamic-tool) * [useChat Reference](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) On this page [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing#type-error-with-ontoolcall) [Problem](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing#problem) [Solution](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing#solution) [Related](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing#related) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: Stale body values with useChat [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#stale-body-values-with-usechat) ================================================================================================================================== [Issue](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#issue) -------------------------------------------------------------------------------- When using `useChat` and passing dynamic information via the `body` parameter at the hook level, the data remains stale and only reflects the value from the initial component render. This occurs because the body configuration is captured once when the hook is initialized and doesn't update with subsequent component re-renders. 1// Problematic code - body data will be stale2export default function Chat() {3 const [temperature, setTemperature] = useState(0.7);4 const [userId, setUserId] = useState('user123');5 6 // This body configuration is captured once and won't update7 const { messages, sendMessage } = useChat({8 transport: new DefaultChatTransport({9 api: '/api/chat',10 body: {11 temperature, // Always the initial value (0.7)12 userId, // Always the initial value ('user123')13 },14 }),15 });16 17 // Even if temperature or userId change, the body in requests will still use initial values18 return (19
20 setTemperature(parseFloat(e.target.value))}24 />25 {/* Chat UI */}26
27 );28} [Background](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#background) ------------------------------------------------------------------------------------------ The hook-level body configuration is evaluated once during the initial render and doesn't re-evaluate when component state changes. [Solution](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#solution) -------------------------------------------------------------------------------------- Pass dynamic variables via the second argument of the `sendMessage` function instead of at the hook level. Request-level options are evaluated on each call and take precedence over hook-level options. 1export default function Chat() {2 const [temperature, setTemperature] = useState(0.7);3 const [userId, setUserId] = useState('user123');4 const [input, setInput] = useState('');5 6 const { messages, sendMessage } = useChat({7 // Static configuration only8 transport: new DefaultChatTransport({9 api: '/api/chat',10 }),11 });12 13 return (14
15 setTemperature(parseFloat(e.target.value))}19 />20 21 {23 event.preventDefault();24 if (input.trim()) {25 // Pass dynamic values as request-level options26 sendMessage(27 { text: input },28 {29 body: {30 temperature, // Current value at request time31 userId, // Current value at request time32 },33 },34 );35 setInput('');36 }37 }}38 >39 setInput(e.target.value)} />40 41
42 );43} ### [Alternative: Dynamic Hook-Level Configuration](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#alternative-dynamic-hook-level-configuration) If you need hook-level configuration that responds to changes, you can use functions that return configuration values. However, for component state, you'll need to use `useRef` to access current values: 1export default function Chat() {2 const temperatureRef = useRef(0.7);3 4 const { messages, sendMessage } = useChat({5 transport: new DefaultChatTransport({6 api: '/api/chat',7 body: () => ({8 temperature: temperatureRef.current, // Access via ref.current9 sessionId: getCurrentSessionId(), // Function calls work directly10 }),11 }),12 });13 14 // ...15} **Recommendation:** Request-level configuration is simpler and more reliable for component state. Use it whenever you need to pass dynamic values that change during the component lifecycle. ### [Server-side handling](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#server-side-handling) On your server side, retrieve the custom fields by destructuring the request body: 1// app/api/chat/route.ts2export async function POST(req: Request) {3 const { messages, temperature, userId } = await req.json();4 5 const result = streamText({6 model: 'openai/gpt-5-mini',7 messages: await convertToModelMessages(messages),8 temperature, // Use the dynamic temperature from the request9 // ... other configuration10 });11 12 return result.toUIMessageStreamResponse();13} For more information, see [chatbot request configuration documentation](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot#request-configuration) . On this page [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#stale-body-values-with-usechat) [Issue](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#issue) [Background](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#background) [Solution](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#solution) [Alternative: Dynamic Hook-Level Configuration](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#alternative-dynamic-hook-level-configuration) [Server-side handling](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data#server-side-handling) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Troubleshooting: useChat No Response [](https://vercel.com/) [](https://ai-sdk.dev/) Menu v6 (Latest) AI SDK 6.x [AI SDK by Vercel](https://ai-sdk.dev/docs/introduction) [Foundations](https://ai-sdk.dev/docs/foundations) [Overview](https://ai-sdk.dev/docs/foundations/overview) [Providers and Models](https://ai-sdk.dev/docs/foundations/providers-and-models) [Prompts](https://ai-sdk.dev/docs/foundations/prompts) [Tools](https://ai-sdk.dev/docs/foundations/tools) [Streaming](https://ai-sdk.dev/docs/foundations/streaming) [Getting Started](https://ai-sdk.dev/docs/getting-started) [Choosing a Provider](https://ai-sdk.dev/docs/getting-started/choosing-a-provider) [Navigating the Library](https://ai-sdk.dev/docs/getting-started/navigating-the-library) [Next.js App Router](https://ai-sdk.dev/docs/getting-started/nextjs-app-router) [Next.js Pages Router](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) [Svelte](https://ai-sdk.dev/docs/getting-started/svelte) [Vue.js (Nuxt)](https://ai-sdk.dev/docs/getting-started/nuxt) [Node.js](https://ai-sdk.dev/docs/getting-started/nodejs) [Expo](https://ai-sdk.dev/docs/getting-started/expo) [TanStack Start](https://ai-sdk.dev/docs/getting-started/tanstack-start) [Agents](https://ai-sdk.dev/docs/agents) [Overview](https://ai-sdk.dev/docs/agents/overview) [Building Agents](https://ai-sdk.dev/docs/agents/building-agents) [Workflow Patterns](https://ai-sdk.dev/docs/agents/workflows) [Loop Control](https://ai-sdk.dev/docs/agents/loop-control) [Configuring Call Options](https://ai-sdk.dev/docs/agents/configuring-call-options) [AI SDK Core](https://ai-sdk.dev/docs/ai-sdk-core) [Overview](https://ai-sdk.dev/docs/ai-sdk-core/overview) [Generating Text](https://ai-sdk.dev/docs/ai-sdk-core/generating-text) [Generating Structured Data](https://ai-sdk.dev/docs/ai-sdk-core/generating-structured-data) [Tool Calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) [Model Context Protocol (MCP)](https://ai-sdk.dev/docs/ai-sdk-core/mcp-tools) [Prompt Engineering](https://ai-sdk.dev/docs/ai-sdk-core/prompt-engineering) [Settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) [Reranking](https://ai-sdk.dev/docs/ai-sdk-core/reranking) [Image Generation](https://ai-sdk.dev/docs/ai-sdk-core/image-generation) [Transcription](https://ai-sdk.dev/docs/ai-sdk-core/transcription) [Speech](https://ai-sdk.dev/docs/ai-sdk-core/speech) [Language Model Middleware](https://ai-sdk.dev/docs/ai-sdk-core/middleware) [Provider & Model Management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-core/error-handling) [Testing](https://ai-sdk.dev/docs/ai-sdk-core/testing) [Telemetry](https://ai-sdk.dev/docs/ai-sdk-core/telemetry) [DevTools](https://ai-sdk.dev/docs/ai-sdk-core/devtools) [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) [Overview](https://ai-sdk.dev/docs/ai-sdk-ui/overview) [Chatbot](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot) [Chatbot Message Persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence) [Chatbot Resume Streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams) [Chatbot Tool Usage](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-tool-usage) [Generative User Interfaces](https://ai-sdk.dev/docs/ai-sdk-ui/generative-user-interfaces) [Completion](https://ai-sdk.dev/docs/ai-sdk-ui/completion) [Object Generation](https://ai-sdk.dev/docs/ai-sdk-ui/object-generation) [Streaming Custom Data](https://ai-sdk.dev/docs/ai-sdk-ui/streaming-data) [Error Handling](https://ai-sdk.dev/docs/ai-sdk-ui/error-handling) [Transport](https://ai-sdk.dev/docs/ai-sdk-ui/transport) [Reading UIMessage Streams](https://ai-sdk.dev/docs/ai-sdk-ui/reading-ui-message-streams) [Message Metadata](https://ai-sdk.dev/docs/ai-sdk-ui/message-metadata) [Stream Protocols](https://ai-sdk.dev/docs/ai-sdk-ui/stream-protocol) [AI SDK RSC](https://ai-sdk.dev/docs/ai-sdk-rsc) [Advanced](https://ai-sdk.dev/docs/advanced) [Reference](https://ai-sdk.dev/docs/reference) [AI SDK Core](https://ai-sdk.dev/docs/reference/ai-sdk-core) [AI SDK UI](https://ai-sdk.dev/docs/reference/ai-sdk-ui) [AI SDK RSC](https://ai-sdk.dev/docs/reference/ai-sdk-rsc) [AI SDK Errors](https://ai-sdk.dev/docs/reference/ai-sdk-errors) [Migration Guides](https://ai-sdk.dev/docs/migration-guides) [Troubleshooting](https://ai-sdk.dev/docs/troubleshooting) [Azure OpenAI Slow to Stream](https://ai-sdk.dev/docs/troubleshooting/azure-stream-slow) [Server Actions in Client Components](https://ai-sdk.dev/docs/troubleshooting/server-actions-in-client-components) [useChat/useCompletion stream output contains 0:... instead of text](https://ai-sdk.dev/docs/troubleshooting/strange-stream-output) [Streamable UI Errors](https://ai-sdk.dev/docs/troubleshooting/streamable-ui-errors) [Tool Invocation Missing Result Error](https://ai-sdk.dev/docs/troubleshooting/tool-invocation-missing-result) [Streaming Not Working When Deployed](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-deployed) [Streaming Not Working When Proxied](https://ai-sdk.dev/docs/troubleshooting/streaming-not-working-when-proxied) [Getting Timeouts When Deploying on Vercel](https://ai-sdk.dev/docs/troubleshooting/timeout-on-vercel) [Unclosed Streams](https://ai-sdk.dev/docs/troubleshooting/unclosed-streams) [useChat Failed to Parse Stream](https://ai-sdk.dev/docs/troubleshooting/use-chat-failed-to-parse-stream) [Server Action Plain Objects Error](https://ai-sdk.dev/docs/troubleshooting/client-stream-error) [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response) [Custom headers, body, and credentials not working with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-custom-request-options) [TypeScript performance issues with Zod and AI SDK 5](https://ai-sdk.dev/docs/troubleshooting/typescript-performance-zod) [useChat "An error occurred"](https://ai-sdk.dev/docs/troubleshooting/use-chat-an-error-occurred) [Repeated assistant messages in useChat](https://ai-sdk.dev/docs/troubleshooting/repeated-assistant-messages) [onFinish not called when stream is aborted](https://ai-sdk.dev/docs/troubleshooting/stream-abort-handling) [Tool calling with generateObject and streamObject](https://ai-sdk.dev/docs/troubleshooting/tool-calling-with-structured-outputs) [Abort breaks resumable streams](https://ai-sdk.dev/docs/troubleshooting/abort-breaks-resumable-streams) [streamText fails silently](https://ai-sdk.dev/docs/troubleshooting/stream-text-not-working) [Streaming Status Shows But No Text Appears](https://ai-sdk.dev/docs/troubleshooting/streaming-status-delay) [Stale body values with useChat](https://ai-sdk.dev/docs/troubleshooting/use-chat-stale-body-data) [Type Error with onToolCall](https://ai-sdk.dev/docs/troubleshooting/ontoolcall-type-narrowing) [Unsupported model version error](https://ai-sdk.dev/docs/troubleshooting/unsupported-model-version) [Object generation failed with OpenAI](https://ai-sdk.dev/docs/troubleshooting/no-object-generated-content-filter) [Missing Tool Results Error](https://ai-sdk.dev/docs/troubleshooting/missing-tool-results-error) [Model is not assignable to type "LanguageModelV1"](https://ai-sdk.dev/docs/troubleshooting/model-is-not-assignable-to-type) [TypeScript error "Cannot find namespace 'JSX'"](https://ai-sdk.dev/docs/troubleshooting/typescript-cannot-find-namespace-jsx) [React error "Maximum update depth exceeded"](https://ai-sdk.dev/docs/troubleshooting/react-maximum-update-depth-exceeded) [Jest: cannot find module '@ai-sdk/rsc'](https://ai-sdk.dev/docs/troubleshooting/jest-cannot-find-module-ai-rsc) Copy markdown [`useChat` No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response#usechat-no-response) ================================================================================================================ [Issue](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response#issue) ---------------------------------------------------------------------------------- I am using [`useChat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) . When I log the incoming messages on the server, I can see the tool call and the tool result, but the model does not respond with anything. [Solution](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response#solution) ---------------------------------------------------------------------------------------- To resolve this issue, convert the incoming messages to the `ModelMessage` format using the [`convertToModelMessages`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/convert-to-model-messages) function. Gateway Provider Custom Claude Sonnet 4.5 1import { openai } from '@ai-sdk/openai';2import { convertToModelMessages, streamText } from 'ai';3 4export async function POST(req: Request) {5 const { messages } = await req.json();6 7 const result = streamText({8 model: "anthropic/claude-sonnet-4.5",9 messages: await convertToModelMessages(messages),10 });11 12 return result.toUIMessageStreamResponse();13} On this page [useChat No Response](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response#usechat-no-response) [Issue](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response#issue) [Solution](https://ai-sdk.dev/docs/troubleshooting/use-chat-tools-no-response#solution) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Guides: RAG Agent [](https://vercel.com/) [](https://ai-sdk.dev/) Menu [Guides](https://ai-sdk.dev/cookbook/guides) [RAG Agent](https://ai-sdk.dev/cookbook/guides/rag-chatbot) [Multi-Modal Agent](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot) [Slackbot Agent Guide](https://ai-sdk.dev/cookbook/guides/slackbot) [Natural Language Postgres](https://ai-sdk.dev/cookbook/guides/natural-language-postgres) [Get started with Computer Use](https://ai-sdk.dev/cookbook/guides/computer-use) [Get started with Gemini 3](https://ai-sdk.dev/cookbook/guides/gemini) [Get started with Claude 4](https://ai-sdk.dev/cookbook/guides/claude-4) [OpenAI Responses API](https://ai-sdk.dev/cookbook/guides/openai-responses) [Google Gemini Image Generation](https://ai-sdk.dev/cookbook/guides/google-gemini-image-generation) [Get started with Claude 3.7 Sonnet](https://ai-sdk.dev/cookbook/guides/sonnet-3-7) [Get started with Llama 3.1](https://ai-sdk.dev/cookbook/guides/llama-3_1) [Get started with GPT-5](https://ai-sdk.dev/cookbook/guides/gpt-5) [Get started with OpenAI o1](https://ai-sdk.dev/cookbook/guides/o1) [Get started with OpenAI o3-mini](https://ai-sdk.dev/cookbook/guides/o3) [Get started with DeepSeek R1](https://ai-sdk.dev/cookbook/guides/r1) [Get started with DeepSeek V3.2](https://ai-sdk.dev/cookbook/guides/deepseek-v3-2) [Next.js](https://ai-sdk.dev/cookbook/next) [Generate Text](https://ai-sdk.dev/cookbook/next/generate-text) [Generate Text with Chat Prompt](https://ai-sdk.dev/cookbook/next/generate-text-with-chat-prompt) [Generate Image with Chat Prompt](https://ai-sdk.dev/cookbook/next/generate-image-with-chat-prompt) [Stream Text](https://ai-sdk.dev/cookbook/next/stream-text) [Stream Text with Chat Prompt](https://ai-sdk.dev/cookbook/next/stream-text-with-chat-prompt) [Stream Text with Image Prompt](https://ai-sdk.dev/cookbook/next/stream-text-with-image-prompt) [Chat with PDFs](https://ai-sdk.dev/cookbook/next/chat-with-pdf) [streamText Multi-Step Cookbook](https://ai-sdk.dev/cookbook/next/stream-text-multistep) [Markdown Chatbot with Memoization](https://ai-sdk.dev/cookbook/next/markdown-chatbot-with-memoization) [Generate Object](https://ai-sdk.dev/cookbook/next/generate-object) [Generate Object with File Prompt through Form Submission](https://ai-sdk.dev/cookbook/next/generate-object-with-file-prompt) [Stream Object](https://ai-sdk.dev/cookbook/next/stream-object) [Call Tools](https://ai-sdk.dev/cookbook/next/call-tools) [Call Tools in Multiple Steps](https://ai-sdk.dev/cookbook/next/call-tools-multiple-steps) [Model Context Protocol (MCP) Tools](https://ai-sdk.dev/cookbook/next/mcp-tools) [Share useChat State Across Components](https://ai-sdk.dev/cookbook/next/use-shared-chat-context) [Human-in-the-Loop Agent with Next.js](https://ai-sdk.dev/cookbook/next/human-in-the-loop) [Track Agent Token Usage](https://ai-sdk.dev/cookbook/next/track-agent-token-usage) [Send Custom Body from useChat](https://ai-sdk.dev/cookbook/next/send-custom-body-from-use-chat) [Streaming with Custom Format](https://ai-sdk.dev/cookbook/next/custom-stream-format) [Render Visual Interface in Chat](https://ai-sdk.dev/cookbook/next/render-visual-interface-in-chat) [Caching Middleware](https://ai-sdk.dev/cookbook/next/caching-middleware) [Node](https://ai-sdk.dev/cookbook/node) [Generate Text](https://ai-sdk.dev/cookbook/node/generate-text) [Generate Text with Chat Prompt](https://ai-sdk.dev/cookbook/node/generate-text-with-chat-prompt) [Generate Text with Image Prompt](https://ai-sdk.dev/cookbook/node/generate-text-with-image-prompt) [Stream Text](https://ai-sdk.dev/cookbook/node/stream-text) [Stream Text with Chat Prompt](https://ai-sdk.dev/cookbook/node/stream-text-with-chat-prompt) [Stream Text with Image Prompt](https://ai-sdk.dev/cookbook/node/stream-text-with-image-prompt) [Stream Text with File Prompt](https://ai-sdk.dev/cookbook/node/stream-text-with-file-prompt) [Generate Object with a Reasoning Model](https://ai-sdk.dev/cookbook/node/generate-object-reasoning) [Generate Object](https://ai-sdk.dev/cookbook/node/generate-object) [Stream Object](https://ai-sdk.dev/cookbook/node/stream-object) [Stream Object with Image Prompt](https://ai-sdk.dev/cookbook/node/stream-object-with-image-prompt) [Record Token Usage After Streaming Object](https://ai-sdk.dev/cookbook/node/stream-object-record-token-usage) [Record Final Object after Streaming Object](https://ai-sdk.dev/cookbook/node/stream-object-record-final-object) [Call Tools](https://ai-sdk.dev/cookbook/node/call-tools) [Call Tools in Parallel](https://ai-sdk.dev/cookbook/node/call-tools-in-parallel) [Call Tools with Image Prompt](https://ai-sdk.dev/cookbook/node/call-tools-with-image-prompt) [Call Tools in Multiple Steps](https://ai-sdk.dev/cookbook/node/call-tools-multiple-steps) [Model Context Protocol (MCP) Tools](https://ai-sdk.dev/cookbook/node/mcp-tools) [Manual Agent Loop](https://ai-sdk.dev/cookbook/node/manual-agent-loop) [Web Search Agent](https://ai-sdk.dev/cookbook/node/web-search-agent) [Model Context Protocol (MCP) Elicitation](https://ai-sdk.dev/cookbook/node/mcp-elicitation) [Embed Text](https://ai-sdk.dev/cookbook/node/embed-text) [Embed Text in Batch](https://ai-sdk.dev/cookbook/node/embed-text-batch) [Intercepting Fetch Requests](https://ai-sdk.dev/cookbook/node/intercept-fetch-requests) [Local Caching Middleware](https://ai-sdk.dev/cookbook/node/local-caching-middleware) [Repair Malformed JSON with jsonrepair](https://ai-sdk.dev/cookbook/node/repair-json-with-jsonrepair) [Dynamic Prompt Caching](https://ai-sdk.dev/cookbook/node/dynamic-prompt-caching) [Retrieval Augmented Generation](https://ai-sdk.dev/cookbook/node/retrieval-augmented-generation) [Knowledge Base Agent](https://ai-sdk.dev/cookbook/node/knowledge-base-agent) [API Servers](https://ai-sdk.dev/cookbook/api-servers) [Node.js HTTP Server](https://ai-sdk.dev/cookbook/api-servers/node-http-server) [Express](https://ai-sdk.dev/cookbook/api-servers/express) [Hono](https://ai-sdk.dev/cookbook/api-servers/hono) [Fastify](https://ai-sdk.dev/cookbook/api-servers/fastify) [Nest.js](https://ai-sdk.dev/cookbook/api-servers/nest) [React Server Components](https://ai-sdk.dev/cookbook/rsc) Copy markdown [RAG Agent Guide](https://ai-sdk.dev/cookbook/guides/rag-chatbot#rag-agent-guide) ================================================================================== In this guide, you will learn how to build a retrieval-augmented generation (RAG) agent. Before we dive in, let's look at what RAG is, and why we would want to use it. ### [What is RAG?](https://ai-sdk.dev/cookbook/guides/rag-chatbot#what-is-rag) RAG stands for retrieval augmented generation. In simple terms, RAG is the process of providing a Large Language Model (LLM) with specific information relevant to the prompt. ### [Why is RAG important?](https://ai-sdk.dev/cookbook/guides/rag-chatbot#why-is-rag-important) While LLMs are powerful, the information they can reason on is restricted to the data they were trained on. This problem becomes apparent when asking an LLM for information outside of their training data, like proprietary data or common knowledge that has occurred after the model’s training cutoff. RAG solves this problem by fetching information relevant to the prompt and then passing that to the model as context. To illustrate with a basic example, imagine asking the model for your favorite food: 1**input**2What is my favorite food?3 4**generation**5I don't have access to personal information about individuals, including their6favorite foods. Not surprisingly, the model doesn’t know. But imagine, alongside your prompt, the model received some extra context: 1**input**2Respond to the user's prompt using only the provided context.3user prompt: 'What is my favorite food?'4context: user loves chicken nuggets5 6**generation**7Your favorite food is chicken nuggets! Just like that, you have augmented the model’s generation by providing relevant information to the query. Assuming the model has the appropriate information, it is now highly likely to return an accurate response to the users query. But how does it retrieve the relevant information? The answer relies on a concept called embedding. You could fetch any context for your RAG application (eg. Google search). Embeddings and Vector Databases are just a specific retrieval approach to achieve semantic search. ### [Embedding](https://ai-sdk.dev/cookbook/guides/rag-chatbot#embedding) [Embeddings](https://ai-sdk.dev/docs/ai-sdk-core/embeddings) are a way to represent words, phrases, or images as vectors in a high-dimensional space. In this space, similar words are close to each other, and the distance between words can be used to measure their similarity. In practice, this means that if you embedded the words `cat` and `dog`, you would expect them to be plotted close to each other in vector space. The process of calculating the similarity between two vectors is called ‘cosine similarity’ where a value of 1 would indicate high similarity and a value of -1 would indicate high opposition. Don’t worry if this seems complicated. a high level understanding is all you need to get started! For a more in-depth introduction to embeddings, check out [this guide](https://jalammar.github.io/illustrated-word2vec/) . As mentioned above, embeddings are a way to represent the semantic meaning of **words and phrases**. The implication here is that the larger the input to your embedding, the lower quality the embedding will be. So how would you approach embedding content longer than a simple phrase? ### [Chunking](https://ai-sdk.dev/cookbook/guides/rag-chatbot#chunking) Chunking refers to the process of breaking down a particular source material into smaller pieces. There are many different approaches to chunking and it’s worth experimenting as the most effective approach can differ by use case. A simple and common approach to chunking (and what you will be using in this guide) is separating written content by sentences. Once your source material is appropriately chunked, you can embed each one and then store the embedding and the chunk together in a database. Embeddings can be stored in any database that supports vectors. For this tutorial, you will be using [Postgres](https://www.postgresql.org/) alongside the [pgvector](https://github.com/pgvector/pgvector) plugin. ![](https://ai-sdk.dev/_next/image?url=%2Fimages%2Frag-guide-1.png&w=1920&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![](https://ai-sdk.dev/_next/image?url=%2Fimages%2Frag-guide-1-dark.png&w=1920&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) ### [All Together Now](https://ai-sdk.dev/cookbook/guides/rag-chatbot#all-together-now) Combining all of this together, RAG is the process of enabling the model to respond with information outside of it’s training data by embedding a users query, retrieving the relevant source material (chunks) with the highest semantic similarity, and then passing them alongside the initial query as context. Going back to the example where you ask the model for your favorite food, the prompt preparation process would look like this. ![](https://ai-sdk.dev/_next/image?url=%2Fimages%2Frag-guide-2.png&w=1920&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![](https://ai-sdk.dev/_next/image?url=%2Fimages%2Frag-guide-2-dark.png&w=1920&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) By passing the appropriate context and refining the model’s objective, you are able to fully leverage its strengths as a reasoning machine. Onto the project! [Project Setup](https://ai-sdk.dev/cookbook/guides/rag-chatbot#project-setup) ------------------------------------------------------------------------------ In this project, you will build a agent that will only respond with information that it has within its knowledge base. The agent will be able to both store and retrieve information. This project has many interesting use cases from customer support through to building your own second brain! This project will use the following stack: * [Next.js](https://nextjs.org/) 14 (App Router) * [AI SDK](https://ai-sdk.dev/docs) * [Vercel AI Gateway](https://ai-sdk.dev/providers/ai-sdk-providers/ai-gateway) * [Drizzle ORM](https://orm.drizzle.team/) * [Postgres](https://www.postgresql.org/) with [pgvector](https://github.com/pgvector/pgvector) * [shadcn-ui](https://ui.shadcn.com/) and [TailwindCSS](https://tailwindcss.com/) for styling ### [Clone Repo](https://ai-sdk.dev/cookbook/guides/rag-chatbot#clone-repo) To reduce the scope of this guide, you will be starting with a [repository](https://github.com/vercel/ai-sdk-rag-starter) that already has a few things set up for you: * Drizzle ORM (`lib/db`) including an initial migration and a script to migrate (`db:migrate`) * a basic schema for the `resources` table (this will be for source material) * a Server Action for creating a `resource` To get started, clone the starter repository with the following command: git clone https://github.com/vercel/ai-sdk-rag-starter cd ai-sdk-rag-starter First things first, run the following command to install the project’s dependencies: pnpm install ### [Create Database](https://ai-sdk.dev/cookbook/guides/rag-chatbot#create-database) You will need a Postgres database to complete this tutorial. If you don't have Postgres setup on your local machine you can: * Create a free Postgres database with Vercel (recommended - see instructions below); or * Follow [this guide](https://www.prisma.io/dataguide/postgresql/setting-up-a-local-postgresql-database) to set it up locally #### [Setting up Postgres with Vercel](https://ai-sdk.dev/cookbook/guides/rag-chatbot#setting-up-postgres-with-vercel) To set up a Postgres instance on your Vercel account: 1. Go to [Vercel.com](https://vercel.com/) and make sure you're logged in 2. Navigate to your team homepage 3. Click on the **Integrations** tab 4. Click **Browse Marketplace** 5. Look for the **Storage** option in the sidebar 6. Select the **Neon** option (recommended, but any other PostgreSQL database provider should work) 7. Click **Install**, then click **Install** again in the top right corner 8. On the "Get Started with Neon" page, click **Create Database** on the right 9. Select your region (e.g., Washington, D.C., U.S. East) 10. Turn off **Auth** 11. Click **Continue** 12. Name your database (you can use the default name or rename it to something like "RagTutorial") 13. Click **Create** in the bottom right corner 14. After seeing "Database created successfully", click **Done** 15. You'll be redirected to your database instance 16. In the Quick Start section, click **Show secrets** 17. Copy the full `DATABASE_URL` environment variable ### [Migrate Database](https://ai-sdk.dev/cookbook/guides/rag-chatbot#migrate-database) Once you have a Postgres database, you need to add the connection string as an environment secret. Make a copy of the `.env.example` file and rename it to `.env`. cp .env.example .env Open the new `.env` file. You should see an item called `DATABASE_URL`. Copy in your database connection string after the equals sign. With that set up, you can now run your first database migration. Run the following command: pnpm db:migrate This will first add the `pgvector` extension to your database. Then it will create a new table for your `resources` schema that is defined in `lib/db/schema/resources.ts`. This schema has four columns: `id`, `content`, `createdAt`, and `updatedAt`. If you experience an error with the migration, see the [troubleshooting section](https://ai-sdk.dev/cookbook/guides/rag-chatbot#troubleshooting-migration-error) below. ### [Vercel AI Gateway Key](https://ai-sdk.dev/cookbook/guides/rag-chatbot#vercel-ai-gateway-key) For this guide, you will need a Vercel AI Gateway API key, which gives you access to hundreds of models from different providers with one API key. If you haven't obtained your Vercel AI Gateway API key, you can do so by [signing up](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai&title=Go+to+AI+Gateway) on the Vercel website. The AI SDK's Vercel AI Gateway Provider is the default global provider, so you can access models using a simple string in the model configuration. If you prefer to use a specific provider like OpenAI directly, see the [provider management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) documentation. Now, open your `.env` file and add your API Gateway key: .env 1AI_GATEWAY_API_KEY=your-api-key Replace `your-api-key` with your actual Vercel AI Gateway API key. [Build](https://ai-sdk.dev/cookbook/guides/rag-chatbot#build) -------------------------------------------------------------- Let’s build a quick task list of what needs to be done: 1. Create a table in your database to store embeddings 2. Add logic to chunk and create embeddings when creating resources 3. Create an agent 4. Give the agent tools to query / create resources for it’s knowledge base ### [Create Embeddings Table](https://ai-sdk.dev/cookbook/guides/rag-chatbot#create-embeddings-table) Currently, your application has one table (`resources`) which has a column (`content`) for storing content. Remember, each `resource` (source material) will have to be chunked, embedded, and then stored. Let’s create a table called `embeddings` to store these chunks. Create a new file (`lib/db/schema/embeddings.ts`) and add the following code: lib/db/schema/embeddings.ts 1import { nanoid } from '@/lib/utils';2import { index, pgTable, text, varchar, vector } from 'drizzle-orm/pg-core';3import { resources } from './resources';4 5export const embeddings = pgTable(6 'embeddings',7 {8 id: varchar('id', { length: 191 })9 .primaryKey()10 .$defaultFn(() => nanoid()),11 resourceId: varchar('resource_id', { length: 191 }).references(12 () => resources.id,13 { onDelete: 'cascade' },14 ),15 content: text('content').notNull(),16 embedding: vector('embedding', { dimensions: 1536 }).notNull(),17 },18 table => ({19 embeddingIndex: index('embeddingIndex').using(20 'hnsw',21 table.embedding.op('vector_cosine_ops'),22 ),23 }),24); This table has four columns: * `id` - unique identifier * `resourceId` - a foreign key relation to the full source material * `content` - the plain text chunk * `embedding` - the vector representation of the plain text chunk To perform similarity search, you also need to include an index ([HNSW](https://github.com/pgvector/pgvector?tab=readme-ov-file#hnsw)  or [IVFFlat](https://github.com/pgvector/pgvector?tab=readme-ov-file#ivfflat) ) on this column for better performance. To push this change to the database, run the following command: pnpm db:push ### [Add Embedding Logic](https://ai-sdk.dev/cookbook/guides/rag-chatbot#add-embedding-logic) Now that you have a table to store embeddings, it’s time to write the logic to create the embeddings. Create a file with the following command: mkdir lib/ai && touch lib/ai/embedding.ts ### [Generate Chunks](https://ai-sdk.dev/cookbook/guides/rag-chatbot#generate-chunks) Remember, to create an embedding, you will start with a piece of source material (unknown length), break it down into smaller chunks, embed each chunk, and then save the chunk to the database. Let’s start by creating a function to break the source material into small chunks. lib/ai/embedding.ts 1const generateChunks = (input: string): string[] => {2 return input3 .trim()4 .split('.')5 .filter(i => i !== '');6}; This function will take an input string and split it by periods, filtering out any empty items. This will return an array of strings. It is worth experimenting with different chunking techniques in your projects as the best technique will vary. ### [Install AI SDK](https://ai-sdk.dev/cookbook/guides/rag-chatbot#install-ai-sdk) You will use the AI SDK to create embeddings. This will require two more dependencies, which you can install by running the following command: pnpm add ai @ai-sdk/react This will install the [AI SDK](https://ai-sdk.dev/docs) and the AI SDK's React hooks. The AI SDK is designed to be a unified interface to interact with any large language model. This means that you can change model and providers with just one line of code! Learn more about [available providers](https://ai-sdk.dev/providers) and [building custom providers](https://ai-sdk.dev/providers/community-providers/custom-providers) in the [providers](https://ai-sdk.dev/providers) section. ### [Generate Embeddings](https://ai-sdk.dev/cookbook/guides/rag-chatbot#generate-embeddings) Let’s add a function to generate embeddings. Copy the following code into your `lib/ai/embedding.ts` file. lib/ai/embedding.ts 1import { embedMany } from 'ai';2 3const embeddingModel = 'openai/text-embedding-ada-002';4 5const generateChunks = (input: string): string[] => {6 return input7 .trim()8 .split('.')9 .filter(i => i !== '');10};11 12export const generateEmbeddings = async (13 value: string,14): Promise> => {15 const chunks = generateChunks(value);16 const { embeddings } = await embedMany({17 model: embeddingModel,18 values: chunks,19 });20 return embeddings.map((e, i) => ({ content: chunks[i], embedding: e }));21}; In this code, you first define the model you want to use for the embeddings. In this example, you are using OpenAI’s `text-embedding-ada-002` embedding model. Next, you create an asynchronous function called `generateEmbeddings`. This function will take in the source material (`value`) as an input and return a promise of an array of objects, each containing an embedding and content. Within the function, you first generate chunks for the input. Then, you pass those chunks to the [`embedMany`](https://ai-sdk.dev/docs/reference/ai-sdk-core/embed-many) function imported from the AI SDK which will return embeddings of the chunks you passed in. Finally, you map over and return the embeddings in a format that is ready to save in the database. ### [Update Server Action](https://ai-sdk.dev/cookbook/guides/rag-chatbot#update-server-action) Open the file at `lib/actions/resources.ts`. This file has one function, `createResource`, which, as the name implies, allows you to create a resource. lib/actions/resources.ts 1'use server';2 3import {4 NewResourceParams,5 insertResourceSchema,6 resources,7} from '@/lib/db/schema/resources';8import { db } from '../db';9 10export const createResource = async (input: NewResourceParams) => {11 try {12 const { content } = insertResourceSchema.parse(input);13 14 const [resource] = await db15 .insert(resources)16 .values({ content })17 .returning();18 19 return 'Resource successfully created.';20 } catch (e) {21 if (e instanceof Error)22 return e.message.length > 0 ? e.message : 'Error, please try again.';23 }24}; This function is a [Server Action](https://nextjs.org/docs/app/building-your-application/data-fetching/server-actions-and-mutations#with-client-components) , as denoted by the `“use server”;` directive at the top of the file. This means that it can be called anywhere in your Next.js application. This function will take an input, run it through a [Zod](https://zod.dev/) schema to ensure it adheres to the correct schema, and then creates a new resource in the database. This is the ideal location to generate and store embeddings of the newly created resources. Update the file with the following code: lib/actions/resources.ts 1'use server';2 3import {4 NewResourceParams,5 insertResourceSchema,6 resources,7} from '@/lib/db/schema/resources';8import { db } from '../db';9import { generateEmbeddings } from '../ai/embedding';10import { embeddings as embeddingsTable } from '../db/schema/embeddings';11 12export const createResource = async (input: NewResourceParams) => {13 try {14 const { content } = insertResourceSchema.parse(input);15 16 const [resource] = await db17 .insert(resources)18 .values({ content })19 .returning();20 21 const embeddings = await generateEmbeddings(content);22 await db.insert(embeddingsTable).values(23 embeddings.map(embedding => ({24 resourceId: resource.id,25 ...embedding,26 })),27 );28 29 return 'Resource successfully created and embedded.';30 } catch (error) {31 return error instanceof Error && error.message.length > 032 ? error.message33 : 'Error, please try again.';34 }35}; First, you call the `generateEmbeddings` function created in the previous step, passing in the source material (`content`). Once you have your embeddings (`e`) of the source material, you can save them to the database, passing the `resourceId` alongside each embedding. ### [Create Root Page](https://ai-sdk.dev/cookbook/guides/rag-chatbot#create-root-page) Great! Let's build the frontend. The AI SDK’s [`useChat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) hook allows you to easily create a conversational user interface for your agent. Replace your root page (`app/page.tsx`) with the following code. app/page.tsx 1'use client';2 3import { useChat } from '@ai-sdk/react';4import { useState } from 'react';5 6export default function Chat() {7 const [input, setInput] = useState('');8 const { messages, sendMessage } = useChat();9 return (10
11
12 {messages.map(m => (13
14
15
{m.role}
16 {m.parts.map(part => {17 switch (part.type) {18 case 'text':19 return

{part.text}

;20 }21 })}22
23
24 ))}25
26 27 {29 e.preventDefault();30 sendMessage({ text: input });31 setInput('');32 }}33 >34 setInput(e.currentTarget.value)}39 />40 41
42 );43} The `useChat` hook enables the streaming of chat messages from your AI provider (you will be using OpenAI via the Vercel AI Gateway), manages the state for chat input, and updates the UI automatically as new messages are received. Run the following command to start the Next.js dev server: pnpm run dev Head to [http://localhost:3000](http://localhost:3000/) . You should see an empty screen with an input bar floating at the bottom. Try to send a message. The message shows up in the UI for a fraction of a second and then disappears. This is because you haven’t set up the corresponding API route to call the model! By default, `useChat` will send a POST request to the `/api/chat` endpoint with the `messages` as the request body. You can customize the endpoint in the useChat configuration object ### [Create API Route](https://ai-sdk.dev/cookbook/guides/rag-chatbot#create-api-route) In Next.js, you can create custom request handlers for a given route using [Route Handlers](https://nextjs.org/docs/app/building-your-application/routing/route-handlers) . Route Handlers are defined in a `route.ts` file and can export HTTP methods like `GET`, `POST`, `PUT`, `PATCH` etc. Create a file at `app/api/chat/route.ts` by running the following command: mkdir -p app/api/chat && touch app/api/chat/route.ts Open the file and add the following code: app/api/chat/route.ts 1import { convertToModelMessages, streamText, UIMessage } from 'ai';2 3// Allow streaming responses up to 30 seconds4export const maxDuration = 30;5 6export async function POST(req: Request) {7 const { messages }: { messages: UIMessage[] } = await req.json();8 9 const result = streamText({10 model: 'openai/gpt-4o',11 messages: await convertToModelMessages(messages),12 });13 14 return result.toUIMessageStreamResponse();15} In this code, you declare and export an asynchronous function called POST. You retrieve the `messages` from the request body and then pass them to the [`streamText`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) function imported from the AI SDK, alongside the model you would like to use. Finally, you return the model’s response in `UIMessageStreamResponse` format. Head back to the browser and try to send a message again. You should see a response from the model streamed directly in! ### [Refining your prompt](https://ai-sdk.dev/cookbook/guides/rag-chatbot#refining-your-prompt) While you now have a working agent, it isn't doing anything special. Let’s add system instructions to refine and restrict the model’s behavior. In this case, you want the model to only use information it has retrieved to generate responses. Update your route handler with the following code: app/api/chat/route.ts 1import { convertToModelMessages, streamText, UIMessage } from 'ai';2 3// Allow streaming responses up to 30 seconds4export const maxDuration = 30;5 6export async function POST(req: Request) {7 const { messages }: { messages: UIMessage[] } = await req.json();8 9 const result = streamText({10 model: 'openai/gpt-4o',11 system: `You are a helpful assistant. Check your knowledge base before answering any questions.12 Only respond to questions using information from tool calls.13 if no relevant information is found in the tool calls, respond, "Sorry, I don't know."`,14 messages: await convertToModelMessages(messages),15 });16 17 return result.toUIMessageStreamResponse();18} Head back to the browser and try to ask the model what your favorite food is. The model should now respond exactly as you instructed above (“Sorry, I don’t know”) given it doesn’t have any relevant information. In its current form, your agent is now, well, useless. How do you give the model the ability to add and query information? ### [Using Tools](https://ai-sdk.dev/cookbook/guides/rag-chatbot#using-tools) A [tool](https://ai-sdk.dev/docs/foundations/tools) is a function that can be called by the model to perform a specific task. You can think of a tool like a program you give to the model that it can run as and when it deems necessary. Let’s see how you can create a tool to give the model the ability to create, embed and save a resource to your agents’ knowledge base. ### [Add Resource Tool](https://ai-sdk.dev/cookbook/guides/rag-chatbot#add-resource-tool) Update your route handler with the following code: app/api/chat/route.ts 1import { createResource } from '@/lib/actions/resources';2import { convertToModelMessages, streamText, tool, UIMessage } from 'ai';3import { z } from 'zod';4 5// Allow streaming responses up to 30 seconds6export const maxDuration = 30;7 8export async function POST(req: Request) {9 const { messages }: { messages: UIMessage[] } = await req.json();10 11 const result = streamText({12 model: 'openai/gpt-4o',13 system: `You are a helpful assistant. Check your knowledge base before answering any questions.14 Only respond to questions using information from tool calls.15 if no relevant information is found in the tool calls, respond, "Sorry, I don't know."`,16 messages: await convertToModelMessages(messages),17 tools: {18 addResource: tool({19 description: `add a resource to your knowledge base.20 If the user provides a random piece of knowledge unprompted, use this tool without asking for confirmation.`,21 inputSchema: z.object({22 content: z23 .string()24 .describe('the content or resource to add to the knowledge base'),25 }),26 execute: async ({ content }) => createResource({ content }),27 }),28 },29 });30 31 return result.toUIMessageStreamResponse();32} In this code, you define a tool called `addResource`. This tool has three elements: * **description**: description of the tool that will influence when the tool is picked. * **inputSchema**: [Zod schema](https://ai-sdk.dev/docs/foundations/tools#schema-specification-and-validation-with-zod)  that defines the input necessary for the tool to run. * **execute**: An asynchronous function that is called with the arguments from the tool call. In simple terms, on each generation, the model will decide whether it should call the tool. If it deems it should call the tool, it will extract the input and then append a new `message` to the `messages` array of type `tool-call`. The AI SDK will then run the `execute` function with the parameters provided by the `tool-call` message. Head back to the browser and tell the model your favorite food. You should see an empty response in the UI. Did anything happen? Let’s see. Run the following command in a new terminal window. pnpm db:studio This will start Drizzle Studio where we can view the rows in our database. You should see a new row in both the `embeddings` and `resources` table with your favorite food! Let’s make a few changes in the UI to communicate to the user when a tool has been called. Head back to your root page (`app/page.tsx`) and add the following code: app/page.tsx 1'use client';2 3import { useChat } from '@ai-sdk/react';4import { useState } from 'react';5 6export default function Chat() {7 const [input, setInput] = useState('');8 const { messages, sendMessage } = useChat();9 return (10
11
12 {messages.map(m => (13
14
15
{m.role}
16 {m.parts.map(part => {17 switch (part.type) {18 case 'text':19 return

{part.text}

;20 case 'tool-addResource':21 case 'tool-getInformation':22 return (23

24 call{part.state === 'output-available' ? 'ed' : 'ing'}{' '}25 tool: {part.type}26

27                          {JSON.stringify(part.input, null, 2)}28                        
29

30 );31 }32 })}33
34
35 ))}36
37 38 {40 e.preventDefault();41 sendMessage({ text: input });42 setInput('');43 }}44 >45 setInput(e.currentTarget.value)}50 />51 52
53 );54} With this change, you now conditionally render the tool that has been called directly in the UI. Save the file and head back to browser. Tell the model your favorite movie. You should see which tool is called in place of the model’s typical text response. Don't worry about the `tool-getInformation` tool case in the switch statement * we'll add that tool in a later section. ### [Improving UX with Multi-Step Calls](https://ai-sdk.dev/cookbook/guides/rag-chatbot#improving-ux-with-multi-step-calls) It would be nice if the model could summarize the action too. However, technically, once the model calls a tool, it has completed its generation as it ‘generated’ a tool call. How could you achieve this desired behavior? The AI SDK has a feature called [`stopWhen`](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling#multi-step-calls) which allows stopping conditions when the model generates a tool call. If those stopping conditions haven't been hit, the AI SDK will automatically send tool call results back to the model! Open your root page (`api/chat/route.ts`) and add the following key to the `streamText` configuration object: api/chat/route.ts 1import { createResource } from '@/lib/actions/resources';2import {3 convertToModelMessages,4 streamText,5 tool,6 UIMessage,7 stepCountIs,8} from 'ai';9import { z } from 'zod';10 11// Allow streaming responses up to 30 seconds12export const maxDuration = 30;13 14export async function POST(req: Request) {15 const { messages }: { messages: UIMessage[] } = await req.json();16 17 const result = streamText({18 model: 'openai/gpt-4o',19 system: `You are a helpful assistant. Check your knowledge base before answering any questions.20 Only respond to questions using information from tool calls.21 if no relevant information is found in the tool calls, respond, "Sorry, I don't know."`,22 messages: await convertToModelMessages(messages),23 stopWhen: stepCountIs(5),24 tools: {25 addResource: tool({26 description: `add a resource to your knowledge base.27 If the user provides a random piece of knowledge unprompted, use this tool without asking for confirmation.`,28 inputSchema: z.object({29 content: z30 .string()31 .describe('the content or resource to add to the knowledge base'),32 }),33 execute: async ({ content }) => createResource({ content }),34 }),35 },36 });37 38 return result.toUIMessageStreamResponse();39} Head back to the browser and tell the model your favorite pizza topping (note: pineapple is not an option). You should see a follow-up response from the model confirming the action. ### [Retrieve Resource Tool](https://ai-sdk.dev/cookbook/guides/rag-chatbot#retrieve-resource-tool) The model can now add and embed arbitrary information to your knowledge base. However, it still isn’t able to query it. Let’s create a new tool to allow the model to answer questions by finding relevant information in your knowledge base. To find similar content, you will need to embed the users query, search the database for semantic similarities, then pass those items to the model as context alongside the query. To achieve this, let’s update your embedding logic file (`lib/ai/embedding.ts`): lib/ai/embedding.ts 1import { embed, embedMany } from 'ai';2import { db } from '../db';3import { cosineDistance, desc, gt, sql } from 'drizzle-orm';4import { embeddings } from '../db/schema/embeddings';5 6const embeddingModel = 'openai/text-embedding-ada-002';7 8const generateChunks = (input: string): string[] => {9 return input10 .trim()11 .split('.')12 .filter(i => i !== '');13};14 15export const generateEmbeddings = async (16 value: string,17): Promise> => {18 const chunks = generateChunks(value);19 const { embeddings } = await embedMany({20 model: embeddingModel,21 values: chunks,22 });23 return embeddings.map((e, i) => ({ content: chunks[i], embedding: e }));24};25 26export const generateEmbedding = async (value: string): Promise => {27 const input = value.replaceAll('\\n', ' ');28 const { embedding } = await embed({29 model: embeddingModel,30 value: input,31 });32 return embedding;33};34 35export const findRelevantContent = async (userQuery: string) => {36 const userQueryEmbedded = await generateEmbedding(userQuery);37 const similarity = sql`1 - (${cosineDistance(38 embeddings.embedding,39 userQueryEmbedded,40 )})`;41 const similarGuides = await db42 .select({ name: embeddings.content, similarity })43 .from(embeddings)44 .where(gt(similarity, 0.5))45 .orderBy(t => desc(t.similarity))46 .limit(4);47 return similarGuides;48}; In this code, you add two functions: * `generateEmbedding`: generate a single embedding from an input string * `findRelevantContent`: embeds the user’s query, searches the database for similar items, then returns relevant items With that done, it’s onto the final step: creating the tool. Go back to your route handler (`api/chat/route.ts`) and add a new tool called `getInformation`: api/chat/route.ts 1import { createResource } from '@/lib/actions/resources';2import {3 convertToModelMessages,4 streamText,5 tool,6 UIMessage,7 stepCountIs,8} from 'ai';9import { z } from 'zod';10import { findRelevantContent } from '@/lib/ai/embedding';11 12// Allow streaming responses up to 30 seconds13export const maxDuration = 30;14 15export async function POST(req: Request) {16 const { messages }: { messages: UIMessage[] } = await req.json();17 18 const result = streamText({19 model: 'openai/gpt-4o',20 messages: await convertToModelMessages(messages),21 stopWhen: stepCountIs(5),22 system: `You are a helpful assistant. Check your knowledge base before answering any questions.23 Only respond to questions using information from tool calls.24 if no relevant information is found in the tool calls, respond, "Sorry, I don't know."`,25 tools: {26 addResource: tool({27 description: `add a resource to your knowledge base.28 If the user provides a random piece of knowledge unprompted, use this tool without asking for confirmation.`,29 inputSchema: z.object({30 content: z31 .string()32 .describe('the content or resource to add to the knowledge base'),33 }),34 execute: async ({ content }) => createResource({ content }),35 }),36 getInformation: tool({37 description: `get information from your knowledge base to answer questions.`,38 inputSchema: z.object({39 question: z.string().describe('the users question'),40 }),41 execute: async ({ question }) => findRelevantContent(question),42 }),43 },44 });45 46 return result.toUIMessageStreamResponse();47} Head back to the browser, refresh the page, and ask for your favorite food. You should see the model call the `getInformation` tool, and then use the relevant information to formulate a response! [Conclusion](https://ai-sdk.dev/cookbook/guides/rag-chatbot#conclusion) ------------------------------------------------------------------------ Congratulations, you have successfully built an AI agent that can dynamically add and retrieve information to and from a knowledge base. Throughout this guide, you learned how to create and store embeddings, set up server actions to manage resources, and use tools to extend the capabilities of your agent. [Troubleshooting Migration Error](https://ai-sdk.dev/cookbook/guides/rag-chatbot#troubleshooting-migration-error) ------------------------------------------------------------------------------------------------------------------ If you experience an error with the migration, open your migration file (`lib/db/migrations/0000_yielding_bloodaxe.sql`), cut (copy and remove) the first line, and run it directly on your postgres instance. You should now be able to run the updated migration. If you're using the Vercel setup above, you can run the command directly by either: * Going to the Neon console and entering the command there, or * Going back to the Vercel platform, navigating to the Quick Start section of your database, and finding the PSQL connection command (second tab). This will connect to your instance in the terminal where you can run the command directly. [More info](https://github.com/vercel/ai-sdk-rag-starter/issues/1) . On this page [RAG Agent Guide](https://ai-sdk.dev/cookbook/guides/rag-chatbot#rag-agent-guide) [What is RAG?](https://ai-sdk.dev/cookbook/guides/rag-chatbot#what-is-rag) [Why is RAG important?](https://ai-sdk.dev/cookbook/guides/rag-chatbot#why-is-rag-important) [Embedding](https://ai-sdk.dev/cookbook/guides/rag-chatbot#embedding) [Chunking](https://ai-sdk.dev/cookbook/guides/rag-chatbot#chunking) [All Together Now](https://ai-sdk.dev/cookbook/guides/rag-chatbot#all-together-now) [Project Setup](https://ai-sdk.dev/cookbook/guides/rag-chatbot#project-setup) [Clone Repo](https://ai-sdk.dev/cookbook/guides/rag-chatbot#clone-repo) [Create Database](https://ai-sdk.dev/cookbook/guides/rag-chatbot#create-database) [Setting up Postgres with Vercel](https://ai-sdk.dev/cookbook/guides/rag-chatbot#setting-up-postgres-with-vercel) [Migrate Database](https://ai-sdk.dev/cookbook/guides/rag-chatbot#migrate-database) [Vercel AI Gateway Key](https://ai-sdk.dev/cookbook/guides/rag-chatbot#vercel-ai-gateway-key) [Build](https://ai-sdk.dev/cookbook/guides/rag-chatbot#build) [Create Embeddings Table](https://ai-sdk.dev/cookbook/guides/rag-chatbot#create-embeddings-table) [Add Embedding Logic](https://ai-sdk.dev/cookbook/guides/rag-chatbot#add-embedding-logic) [Generate Chunks](https://ai-sdk.dev/cookbook/guides/rag-chatbot#generate-chunks) [Install AI SDK](https://ai-sdk.dev/cookbook/guides/rag-chatbot#install-ai-sdk) [Generate Embeddings](https://ai-sdk.dev/cookbook/guides/rag-chatbot#generate-embeddings) [Update Server Action](https://ai-sdk.dev/cookbook/guides/rag-chatbot#update-server-action) [Create Root Page](https://ai-sdk.dev/cookbook/guides/rag-chatbot#create-root-page) [Create API Route](https://ai-sdk.dev/cookbook/guides/rag-chatbot#create-api-route) [Refining your prompt](https://ai-sdk.dev/cookbook/guides/rag-chatbot#refining-your-prompt) [Using Tools](https://ai-sdk.dev/cookbook/guides/rag-chatbot#using-tools) [Add Resource Tool](https://ai-sdk.dev/cookbook/guides/rag-chatbot#add-resource-tool) [Improving UX with Multi-Step Calls](https://ai-sdk.dev/cookbook/guides/rag-chatbot#improving-ux-with-multi-step-calls) [Retrieve Resource Tool](https://ai-sdk.dev/cookbook/guides/rag-chatbot#retrieve-resource-tool) [Conclusion](https://ai-sdk.dev/cookbook/guides/rag-chatbot#conclusion) [Troubleshooting Migration Error](https://ai-sdk.dev/cookbook/guides/rag-chatbot#troubleshooting-migration-error) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) --- # Guides: Multi-Modal Agent [](https://vercel.com/) [](https://ai-sdk.dev/) Menu [Guides](https://ai-sdk.dev/cookbook/guides) [RAG Agent](https://ai-sdk.dev/cookbook/guides/rag-chatbot) [Multi-Modal Agent](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot) [Slackbot Agent Guide](https://ai-sdk.dev/cookbook/guides/slackbot) [Natural Language Postgres](https://ai-sdk.dev/cookbook/guides/natural-language-postgres) [Get started with Computer Use](https://ai-sdk.dev/cookbook/guides/computer-use) [Get started with Gemini 3](https://ai-sdk.dev/cookbook/guides/gemini) [Get started with Claude 4](https://ai-sdk.dev/cookbook/guides/claude-4) [OpenAI Responses API](https://ai-sdk.dev/cookbook/guides/openai-responses) [Google Gemini Image Generation](https://ai-sdk.dev/cookbook/guides/google-gemini-image-generation) [Get started with Claude 3.7 Sonnet](https://ai-sdk.dev/cookbook/guides/sonnet-3-7) [Get started with Llama 3.1](https://ai-sdk.dev/cookbook/guides/llama-3_1) [Get started with GPT-5](https://ai-sdk.dev/cookbook/guides/gpt-5) [Get started with OpenAI o1](https://ai-sdk.dev/cookbook/guides/o1) [Get started with OpenAI o3-mini](https://ai-sdk.dev/cookbook/guides/o3) [Get started with DeepSeek R1](https://ai-sdk.dev/cookbook/guides/r1) [Get started with DeepSeek V3.2](https://ai-sdk.dev/cookbook/guides/deepseek-v3-2) [Next.js](https://ai-sdk.dev/cookbook/next) [Generate Text](https://ai-sdk.dev/cookbook/next/generate-text) [Generate Text with Chat Prompt](https://ai-sdk.dev/cookbook/next/generate-text-with-chat-prompt) [Generate Image with Chat Prompt](https://ai-sdk.dev/cookbook/next/generate-image-with-chat-prompt) [Stream Text](https://ai-sdk.dev/cookbook/next/stream-text) [Stream Text with Chat Prompt](https://ai-sdk.dev/cookbook/next/stream-text-with-chat-prompt) [Stream Text with Image Prompt](https://ai-sdk.dev/cookbook/next/stream-text-with-image-prompt) [Chat with PDFs](https://ai-sdk.dev/cookbook/next/chat-with-pdf) [streamText Multi-Step Cookbook](https://ai-sdk.dev/cookbook/next/stream-text-multistep) [Markdown Chatbot with Memoization](https://ai-sdk.dev/cookbook/next/markdown-chatbot-with-memoization) [Generate Object](https://ai-sdk.dev/cookbook/next/generate-object) [Generate Object with File Prompt through Form Submission](https://ai-sdk.dev/cookbook/next/generate-object-with-file-prompt) [Stream Object](https://ai-sdk.dev/cookbook/next/stream-object) [Call Tools](https://ai-sdk.dev/cookbook/next/call-tools) [Call Tools in Multiple Steps](https://ai-sdk.dev/cookbook/next/call-tools-multiple-steps) [Model Context Protocol (MCP) Tools](https://ai-sdk.dev/cookbook/next/mcp-tools) [Share useChat State Across Components](https://ai-sdk.dev/cookbook/next/use-shared-chat-context) [Human-in-the-Loop Agent with Next.js](https://ai-sdk.dev/cookbook/next/human-in-the-loop) [Track Agent Token Usage](https://ai-sdk.dev/cookbook/next/track-agent-token-usage) [Send Custom Body from useChat](https://ai-sdk.dev/cookbook/next/send-custom-body-from-use-chat) [Streaming with Custom Format](https://ai-sdk.dev/cookbook/next/custom-stream-format) [Render Visual Interface in Chat](https://ai-sdk.dev/cookbook/next/render-visual-interface-in-chat) [Caching Middleware](https://ai-sdk.dev/cookbook/next/caching-middleware) [Node](https://ai-sdk.dev/cookbook/node) [Generate Text](https://ai-sdk.dev/cookbook/node/generate-text) [Generate Text with Chat Prompt](https://ai-sdk.dev/cookbook/node/generate-text-with-chat-prompt) [Generate Text with Image Prompt](https://ai-sdk.dev/cookbook/node/generate-text-with-image-prompt) [Stream Text](https://ai-sdk.dev/cookbook/node/stream-text) [Stream Text with Chat Prompt](https://ai-sdk.dev/cookbook/node/stream-text-with-chat-prompt) [Stream Text with Image Prompt](https://ai-sdk.dev/cookbook/node/stream-text-with-image-prompt) [Stream Text with File Prompt](https://ai-sdk.dev/cookbook/node/stream-text-with-file-prompt) [Generate Object with a Reasoning Model](https://ai-sdk.dev/cookbook/node/generate-object-reasoning) [Generate Object](https://ai-sdk.dev/cookbook/node/generate-object) [Stream Object](https://ai-sdk.dev/cookbook/node/stream-object) [Stream Object with Image Prompt](https://ai-sdk.dev/cookbook/node/stream-object-with-image-prompt) [Record Token Usage After Streaming Object](https://ai-sdk.dev/cookbook/node/stream-object-record-token-usage) [Record Final Object after Streaming Object](https://ai-sdk.dev/cookbook/node/stream-object-record-final-object) [Call Tools](https://ai-sdk.dev/cookbook/node/call-tools) [Call Tools in Parallel](https://ai-sdk.dev/cookbook/node/call-tools-in-parallel) [Call Tools with Image Prompt](https://ai-sdk.dev/cookbook/node/call-tools-with-image-prompt) [Call Tools in Multiple Steps](https://ai-sdk.dev/cookbook/node/call-tools-multiple-steps) [Model Context Protocol (MCP) Tools](https://ai-sdk.dev/cookbook/node/mcp-tools) [Manual Agent Loop](https://ai-sdk.dev/cookbook/node/manual-agent-loop) [Web Search Agent](https://ai-sdk.dev/cookbook/node/web-search-agent) [Model Context Protocol (MCP) Elicitation](https://ai-sdk.dev/cookbook/node/mcp-elicitation) [Embed Text](https://ai-sdk.dev/cookbook/node/embed-text) [Embed Text in Batch](https://ai-sdk.dev/cookbook/node/embed-text-batch) [Intercepting Fetch Requests](https://ai-sdk.dev/cookbook/node/intercept-fetch-requests) [Local Caching Middleware](https://ai-sdk.dev/cookbook/node/local-caching-middleware) [Repair Malformed JSON with jsonrepair](https://ai-sdk.dev/cookbook/node/repair-json-with-jsonrepair) [Dynamic Prompt Caching](https://ai-sdk.dev/cookbook/node/dynamic-prompt-caching) [Retrieval Augmented Generation](https://ai-sdk.dev/cookbook/node/retrieval-augmented-generation) [Knowledge Base Agent](https://ai-sdk.dev/cookbook/node/knowledge-base-agent) [API Servers](https://ai-sdk.dev/cookbook/api-servers) [Node.js HTTP Server](https://ai-sdk.dev/cookbook/api-servers/node-http-server) [Express](https://ai-sdk.dev/cookbook/api-servers/express) [Hono](https://ai-sdk.dev/cookbook/api-servers/hono) [Fastify](https://ai-sdk.dev/cookbook/api-servers/fastify) [Nest.js](https://ai-sdk.dev/cookbook/api-servers/nest) [React Server Components](https://ai-sdk.dev/cookbook/rsc) Copy markdown [Multi-Modal Agent](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#multi-modal-agent) ============================================================================================== In this guide, you will build a multi-modal agent capable of understanding both images and PDFs. Multi-modal refers to the ability of the agent to understand and generate responses in multiple formats. In this guide, we'll focus on images and PDFs - two common document types that modern language models can process natively. For a complete list of providers and their multi-modal capabilities, visit the [providers documentation](https://ai-sdk.dev/providers/ai-sdk-providers) . We'll build this agent using OpenAI's GPT-4o, but the same code works seamlessly with other providers - you can switch between them by changing just one line of code. [Prerequisites](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#prerequisites) -------------------------------------------------------------------------------------- To follow this quickstart, you'll need: * Node.js 18+ and pnpm installed on your local development machine. * A Vercel AI Gateway API key. If you haven't obtained your Vercel AI Gateway API key, you can do so by [signing up](https://vercel.com/d?to=%2F%5Bteam%5D%2F%7E%2Fai&title=Go+to+AI+Gateway) on the Vercel website. [Create Your Application](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#create-your-application) ---------------------------------------------------------------------------------------------------------- Start by creating a new Next.js application. This command will create a new directory named `multi-modal-agent` and set up a basic Next.js application inside it. Be sure to select yes when prompted to use the App Router. If you are looking for the Next.js Pages Router quickstart guide, you can find it [here](https://ai-sdk.dev/docs/getting-started/nextjs-pages-router) . pnpm create next-app@latest multi-modal-agent Navigate to the newly created directory: cd multi-modal-agent ### [Install dependencies](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#install-dependencies) Install `ai` and `@ai-sdk/react`, the AI SDK package and the AI SDK's React package respectively. The AI SDK is designed to be a unified interface to interact with any large language model. This means that you can change model and providers with just one line of code! Learn more about [available providers](https://ai-sdk.dev/providers) and [building custom providers](https://ai-sdk.dev/providers/community-providers/custom-providers) in the [providers](https://ai-sdk.dev/providers) section. pnpmnpmyarnbun pnpm add ai @ai-sdk/react ### [Configure your Vercel AI Gateway API key](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#configure-your-vercel-ai-gateway-api-key) Create a `.env.local` file in your project root and add your Vercel AI Gateway API key. This key authenticates your application with Vercel AI Gateway. touch .env.local Edit the `.env.local` file: .env.local 1AI_GATEWAY_API_KEY=your_api_key_here Replace `your_api_key_here` with your actual Vercel AI Gateway API key. The AI SDK's Vercel AI Gateway Provider is the default global provider, so you can access models using a simple string in the model configuration. If you prefer to use a specific provider like OpenAI directly, see the [provider management](https://ai-sdk.dev/docs/ai-sdk-core/provider-management) documentation. [Implementation Plan](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#implementation-plan) -------------------------------------------------------------------------------------------------- To build a multi-modal agent, you will need to: * Create a Route Handler to handle incoming chat messages and generate responses. * Wire up the UI to display chat messages, provide a user input, and handle submitting new messages. * Add the ability to upload images and PDFs and attach them alongside the chat messages. [Create a Route Handler](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#create-a-route-handler) -------------------------------------------------------------------------------------------------------- Create a route handler, `app/api/chat/route.ts` and add the following code: app/api/chat/route.ts 1import { streamText, convertToModelMessages, type UIMessage } from 'ai';2 3// Allow streaming responses up to 30 seconds4export const maxDuration = 30;5 6export async function POST(req: Request) {7 const { messages }: { messages: UIMessage[] } = await req.json();8 9 const result = streamText({10 model: 'openai/gpt-4o',11 messages: await convertToModelMessages(messages),12 });13 14 return result.toUIMessageStreamResponse();15} Let's take a look at what is happening in this code: 1. Define an asynchronous `POST` request handler and extract `messages` from the body of the request. The `messages` variable contains a history of the conversation between you and the agent and provides the agent with the necessary context to make the next generation. 2. Convert the UI messages to model messages using `convertToModelMessages`, which transforms the UI-focused message format to the format expected by the language model. 3. Call [`streamText`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text) , which is imported from the `ai` package. This function accepts a configuration object that contains a `model` provider and `messages` (converted in step 2). You can pass additional [settings](https://ai-sdk.dev/docs/ai-sdk-core/settings) to further customize the model's behavior. 4. The `streamText` function returns a [`StreamTextResult`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text#result-object) . This result object contains the [`toUIMessageStreamResponse`](https://ai-sdk.dev/docs/reference/ai-sdk-core/stream-text#to-ui-message-stream-response) function which converts the result to a streamed response object. 5. Finally, return the result to the client to stream the response. This Route Handler creates a POST request endpoint at `/api/chat`. [Wire up the UI](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#wire-up-the-ui) ---------------------------------------------------------------------------------------- Now that you have a Route Handler that can query a large language model (LLM), it's time to setup your frontend. [AI SDK UI](https://ai-sdk.dev/docs/ai-sdk-ui) abstracts the complexity of a chat interface into one hook, [`useChat`](https://ai-sdk.dev/docs/reference/ai-sdk-ui/use-chat) . Update your root page (`app/page.tsx`) with the following code to show a list of chat messages and provide a user message input: app/page.tsx 1'use client';2 3import { useChat } from '@ai-sdk/react';4import { DefaultChatTransport } from 'ai';5import { useState } from 'react';6 7export default function Chat() {8 const [input, setInput] = useState('');9 10 const { messages, sendMessage } = useChat({11 transport: new DefaultChatTransport({12 api: '/api/chat',13 }),14 });15 16 return (17
18 {messages.map(m => (19
20 {m.role === 'user' ? 'User: ' : 'AI: '}21 {m.parts.map((part, index) => {22 if (part.type === 'text') {23 return {part.text};24 }25 return null;26 })}27
28 ))}29 30 {32 event.preventDefault();33 sendMessage({34 role: 'user',35 parts: [{ type: 'text', text: input }],36 });37 setInput('');38 }}39 className="fixed bottom-0 w-full max-w-md mb-8 border border-gray-300 rounded shadow-xl"40 >41 setInput(e.target.value)}46 />47 48
49 );50} Make sure you add the `"use client"` directive to the top of your file. This allows you to add interactivity with JavaScript. This page utilizes the `useChat` hook, configured with `DefaultChatTransport` to specify the API endpoint. The `useChat` hook provides multiple utility functions and state variables: * `messages` - the current chat messages (an array of objects with `id`, `role`, and `parts` properties). * `sendMessage` - function to send a new message to the AI. * Each message contains a `parts` array that can include text, images, PDFs, and other content types. * Files are converted to data URLs before being sent to maintain compatibility across different environments. [Add File Upload](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#add-file-upload) ------------------------------------------------------------------------------------------ To make your agent multi-modal, let's add the ability to upload and send both images and PDFs to the model. In v5, files are sent as part of the message's `parts` array. Files are converted to data URLs using the FileReader API before being sent to the server. Update your root page (`app/page.tsx`) with the following code: app/page.tsx 1'use client';2 3import { useChat } from '@ai-sdk/react';4import { DefaultChatTransport } from 'ai';5import { useRef, useState } from 'react';6import Image from 'next/image';7 8async function convertFilesToDataURLs(files: FileList) {9 return Promise.all(10 Array.from(files).map(11 file =>12 new Promise<{13 type: 'file';14 mediaType: string;15 url: string;16 }>((resolve, reject) => {17 const reader = new FileReader();18 reader.onload = () => {19 resolve({20 type: 'file',21 mediaType: file.type,22 url: reader.result as string,23 });24 };25 reader.onerror = reject;26 reader.readAsDataURL(file);27 }),28 ),29 );30}31 32export default function Chat() {33 const [input, setInput] = useState('');34 const [files, setFiles] = useState(undefined);35 const fileInputRef = useRef(null);36 37 const { messages, sendMessage } = useChat({38 transport: new DefaultChatTransport({39 api: '/api/chat',40 }),41 });42 43 return (44
45 {messages.map(m => (46
47 {m.role === 'user' ? 'User: ' : 'AI: '}48 {m.parts.map((part, index) => {49 if (part.type === 'text') {50 return {part.text};51 }52 if (part.type === 'file' && part.mediaType?.startsWith('image/')) {53 return (54 61 );62 }63 if (part.type === 'file' && part.mediaType === 'application/pdf') {64 return (65 72 );73 }74 return null;75 })}76
77 ))}78 79 {82 event.preventDefault();83 84 const fileParts =85 files && files.length > 086 ? await convertFilesToDataURLs(files)87 : [];88 89 sendMessage({90 role: 'user',91 parts: [{ type: 'text', text: input }, ...fileParts],92 });93 94 setInput('');95 setFiles(undefined);96 97 if (fileInputRef.current) {98 fileInputRef.current.value = '';99 }100 }}101 >102 {107 if (event.target.files) {108 setFiles(event.target.files);109 }110 }}111 multiple112 ref={fileInputRef}113 />114 setInput(e.target.value)}119 />120 121
122 );123} In this code, you: 1. Add a helper function `convertFilesToDataURLs` to convert file uploads to data URLs. 2. Create state to hold the input text, files, and a ref to the file input field. 3. Configure `useChat` with `DefaultChatTransport` to specify the API endpoint. 4. Display messages using the `parts` array structure, rendering text, images, and PDFs appropriately. 5. Update the `onSubmit` function to send messages with the `sendMessage` function, including both text and file parts. 6. Add a file input field to the form, including an `onChange` handler to handle updating the files state. [Running Your Application](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#running-your-application) ------------------------------------------------------------------------------------------------------------ With that, you have built everything you need for your multi-modal agent! To start your application, use the command: pnpm run dev Head to your browser and open [http://localhost:3000](http://localhost:3000/) . You should see an input field and a button to upload files. Try uploading an image or PDF and asking the model questions about it. Watch as the model's response is streamed back to you! [Using Other Providers](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#using-other-providers) ------------------------------------------------------------------------------------------------------ With the AI SDK's unified provider interface you can easily switch to other providers that support multi-modal capabilities: app/api/chat/route.ts 1// Using Anthropic2const result = streamText({3 model: 'anthropic/claude-sonnet-4-20250514',4 messages: await convertToModelMessages(messages),5});6 7// Using Google8const result = streamText({9 model: 'google/gemini-2.5-flash',10 messages: await convertToModelMessages(messages),11}); Install the provider package (`@ai-sdk/anthropic` or `@ai-sdk/google`) and update your API keys in `.env.local`. The rest of your code remains the same. Different providers may have varying file size limits and performance characteristics. Check the [provider documentation](https://ai-sdk.dev/providers/ai-sdk-providers) for specific details. [Where to Next?](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#where-to-next) --------------------------------------------------------------------------------------- You've built a multi-modal AI agent using the AI SDK! Experiment and extend the functionality of this application further by exploring [tool calling](https://ai-sdk.dev/docs/ai-sdk-core/tools-and-tool-calling) . On this page [Multi-Modal Agent](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#multi-modal-agent) [Prerequisites](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#prerequisites) [Create Your Application](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#create-your-application) [Install dependencies](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#install-dependencies) [Configure your Vercel AI Gateway API key](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#configure-your-vercel-ai-gateway-api-key) [Implementation Plan](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#implementation-plan) [Create a Route Handler](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#create-a-route-handler) [Wire up the UI](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#wire-up-the-ui) [Add File Upload](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#add-file-upload) [Running Your Application](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#running-your-application) [Using Other Providers](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#using-other-providers) [Where to Next?](https://ai-sdk.dev/cookbook/guides/multi-modal-chatbot#where-to-next) Deploy and Scale AI Apps with Vercel Deliver AI experiences globally with one push. Trusted by industry leaders: * OpenAI * Photoroom * ![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-light.c72067fe.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![leonardo-ai Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fleonardo-ai-dark.5fcd9c34.svg&w=384&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) * ![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-light.b48931cb.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB)![zapier Logo](https://ai-sdk.dev/_next/image?url=%2F_next%2Fstatic%2Fmedia%2Fzapier-dark.bb119b02.svg&w=256&q=75&dpl=dpl_9AnV6nubitojdkd13kGrKwsTWhkB) [Sign Up](https://vercel.com/signup?utm_source=ai-sdk_site&utm_medium=docs_card&utm_content=sign-up) ---