ai-sdk-ui

Implement Vercel AI SDK v5 React hooks for streaming chat interfaces in Next.js applications.

Updated Jun 22, 2026
One-click install
npx skills add https://github.com/aicodepro/ai-agent-nexi --skill ai-sdk-ui-aicodepro
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: ai-sdk-ui
Source: https://github.com/aicodepro/ai-agent-nexi/tree/main/agent/skills/ai-sdk-ui
Command: npx skills add https://github.com/aicodepro/ai-agent-nexi --skill ai-sdk-ui-aicodepro

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires ai, @ai-sdk/openai, @ai-sdk/anthropic, @ai-sdk/google, react, react-dom, next, zod, and includes scripts (resource) and references (resource) components.

What problem does it solve? Building AI chat interfaces in React requires correctly wiring streaming responses, managing message state, and handling breaking changes between AI SDK versions, which commonly causes parse stream errors, missing responses, and stale state bugs. ## Core Features & Use Cases - Complete Hook References: Full API coverage for useChat, useCompletion, and useObject with v5 patterns including manual input management and sendMessage. - v4 to v5 Migration Guidance: Documents breaking changes such as the removal of input, handleInputChange, and append, with corrected code patterns. - Error Troubleshooting: Solutions for 12 common UI errors including stream parse failures, stale body values, and React maximum update depth loops. - Production Templates: Ready-to-use Next.js App Router and Pages Router chat components with auto-scroll, stop buttons, persistence, and markdown rendering. - Use Case: A developer building a Next.js chat app hits a "failed to parse stream" error; this Skill provides the fix (toDataStreamResponse vs pipeDataStreamToResponse) plus a complete working chat page template. ## Quick Start Ask the AI to build a streaming chat interface in Next.js using the Vercel AI SDK v5 useChat hook with a matching API route.

Frequently Asked Questions about ai-sdk-ui

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I use the useChat hook in AI SDK v5?

In v5, useChat no longer manages input state, so you create your own useState for input and call sendMessage({ content: input }) on submit. Import it from 'ai/react' and point the api option at your streaming route handler.

Why does useChat fail to parse the stream?

This error occurs when the API route does not return a proper data stream response. In App Router return result.toDataStreamResponse(), and in Pages Router use result.pipeDataStreamToResponse(res) instead of a plain Response.

What changed migrating from AI SDK v4 to v5?

v5 removed input, handleInputChange, and handleSubmit from useChat, replaced append() with sendMessage(), removed onResponse in favor of onFinish, and dropped maxSteps from the client. Input state must now be managed manually with useState.

Does useChat work with Next.js Pages Router?

Yes, useChat works with both routers, but the server-side streaming method differs. Pages Router API handlers use pipeDataStreamToResponse(res), while App Router route handlers return toDataStreamResponse().

How do I persist chat history with useChat?

Pass an id and initialMessages loaded from localStorage to useChat, then save messages to localStorage in a useEffect whenever they change. The skill includes SSR-safe helper functions and a full persistence template.

When should I not use the AI SDK UI hooks?

Avoid these hooks for backend-only AI logic, which belongs in ai-sdk-core with streamText and generateObject. They also do not cover Generative UI with React Server Components or non-React frameworks like Svelte and Vue.