ai-sdk-ui
Provides frontend React UI templates, examples, and migration guidance for the Vercel AI SDK v6. Includes instructions to read OPENAI_API_KEY from .env.local, call providers in API routes like app/api/chat/route.ts (e.g., openai('gpt-4-turbo')), and run developer commands such as npm install.
AI SDK UI - Frontend React Hooks
Version: AI SDK v6.0.6 (Stable) Status: Production-Ready ✅ Framework: React 18+/19, Next.js 14+/15+ Last Updated: 2026-01-03
What This Skill Does
Provides complete implementation patterns for Vercel AI SDK v6 frontend React hooks:
- useChat - Chat interfaces with streaming
- useCompletion - Text completions
- useObject - Streaming structured data
Focus: React UI layer for AI-powered applications.
Auto-Trigger Keywords
This skill should be automatically discovered when working with any of the following:
Primary Keywords (Highest Priority)
ai sdk uiuseChat hookuseCompletion hookuseObject hookreact ai chatai chat interfacechat ui reactai sdk reactvercel ai uiai react hooksstreaming ai uireact streaming chatnextjs ai chatnextjs ainext.js chatai chat componentreact ai components
Secondary Keywords (Medium Priority)
nextjs app router ainextjs pages router aichat message statemessage persistence aiai file attachmentsfile upload ai chatstreaming chat reactreal-time ai chattool calling uiai tools reactai completion reacttext completion uistructured data streaminguseObject streamingreact chat appreact ai application
Error-Based Keywords (Trigger on Errors)
useChat failed to parse streamparse stream erroruseChat no responsechat hook no responseunclosed streams aistream not closingstreaming not working deployedvercel streaming issuestreaming not working proxiedproxy bufferingstrange stream output0: characters streamstale body values useChatbody not updatingcustom headers not working useChatreact maximum update depthinfinite loop useChatrepeated assistant messagesduplicate messagesonFinish not calledstream abortedv5 migration useChatv6 migration useChatuseChat breaking changesinput handleInputChange removedsendMessage v5message parts v6m.content undefinedparts array v6
Framework Integration Keywords
nextjs ai integrationnext.js ai sdkvite react airemix ai chatvercel ai deployment
Provider Keywords
openai react chatanthropic react chatclaude chat uigpt chat interface
Quick Start
npm install ai @ai-sdk/react @ai-sdk/openai
5-minute chat interface (v6 with message parts):
// app/chat/page.tsx
'use client';
import { useChat } from '@ai-sdk/react';
import { useState } from 'react';
export default function Chat() {
const { messages, sendMessage, isLoading } = useChat({ api: '/api/chat' });
const [input, setInput] = useState('');
return (
<div>
{messages.map(m => (
<div key={m.id}>
{m.role}: {m.parts.map((part, i) => (
part.type === 'text' ? <span key={i}>{part.text}</span> : null
))}
</div>
))}
<form onSubmit={(e) => {
e.preventDefault();
sendMessage({ content: input });
setInput('');
}}>
<input value={input} onChange={(e) => setInput(e.target.value)} />
</form>
</div>
);
}
// app/api/chat/route.ts
import { streamText } from 'ai';
import { openai } from '@ai-sdk/openai';
export async function POST(req: Request) {
const { messages } = await req.json();
const result = streamText({ model: openai('gpt-5'), messages });
return result.toDataStreamResponse();
}
What's Included
Templates (11)
- use-chat-basic.tsx - Basic chat with v5 input management
- use-chat-tools.tsx - Chat with tool calling UI
- use-chat-attachments.tsx - File attachments support
- use-completion-basic.tsx - Text completion streaming
- use-object-streaming.tsx - Structured data streaming
- nextjs-chat-app-router.tsx - Next.js App Router complete example
- nextjs-chat-pages-router.tsx - Next.js Pages Router complete example
- nextjs-api-route.ts - API route for both routers
- message-persistence.tsx - localStorage persistence
- custom-message-renderer.tsx - Markdown & code highlighting
- package.json - Dependencies template
References (5)
- use-chat-migration.md - Complete v4→v5 migration guide
- streaming-patterns.md - UI streaming best practices
- top-ui-errors.md - 12 common UI errors with solutions
- nextjs-integration.md - Next.js setup patterns
- links-to-official-docs.md - Official docs organization
Scripts (1)
- check-versions.sh - Verify package versions
Critical v6 Changes
BREAKING: Message content is now accessed via .parts array!
v5 (OLD):
{messages.map(m => <div>{m.content}</div>)}
v6 (NEW):
{messages.map(m => (
<div>
{m.parts.map((part, i) => (
part.type === 'text' ? <span key={i}>{part.text}</span> : null
))}
</div>
))}
Part Types in v6:
text- Text content (.text)tool-invocation- Tool calls (.toolName,.args,.result)file- File attachments (.mimeType,.data)reasoning- Model reasoningsource- Source citations
Prior v4→v5 changes still apply:
input,handleInputChange,handleSubmitremovedappend()→sendMessage()onResponseremoved → useonFinish
See references/use-chat-migration.md for complete migration guide.
Token Savings
Without skill: ~15,500 tokens (research, trial-and-error, debugging) With skill: ~7,000 tokens (templates, references, examples)
Savings: ~55% (8,500 tokens)
Errors Prevented
This skill documents and prevents 12 common UI errors:
- useChat failed to parse stream
- useChat no response
- Unclosed streams
- Streaming not working when deployed
- Streaming not working when proxied
- Strange stream output (0:... characters)
- Stale body values
- Custom headers not working
- React maximum update depth
- Repeated assistant messages
- onFinish not called when aborted
- Type errors with message parts
When to Use This Skill
Use ai-sdk-ui when:
- Building React chat interfaces
- Implementing AI completions in UI
- Streaming AI responses to frontend
- Building Next.js AI applications
- Handling chat message state
- Displaying tool calls in UI
- Managing file attachments with AI
- Migrating from v4 to v5
- Encountering useChat/useCompletion errors
Don't use when:
- Need backend AI (use ai-sdk-core instead)
- Building non-React frontends (check official docs)
- Need Generative UI / RSC (advanced topic)
Related Skills
- ai-sdk-core - Backend text generation, structured output, tools, agents
- Compose both for full-stack AI applications
Package Versions
v6 (Recommended):
ai: ^6.0.6@ai-sdk/react: ^3.0.6@ai-sdk/openai: ^3.0.2react: ^18.3.0zod: ^3.24.2
Next.js:
next: ^14.0.0 or ^15.0.0react: ^18.3.0 or ^19.0.0react-dom: ^18.3.0 or ^19.0.0
Official Documentation
Core UI Hooks:
- AI SDK UI Overview: https://ai-sdk.dev/docs/ai-sdk-ui/overview
- useChat: https://ai-sdk.dev/docs/ai-sdk-ui/chatbot
- useCompletion: https://ai-sdk.dev/docs/ai-sdk-ui/completion
- useObject: https://ai-sdk.dev/docs/ai-sdk-ui/object-generation
Next.js:
- App Router: https://ai-sdk.dev/docs/getting-started/nextjs-app-router
- Pages Router: https://ai-sdk.dev/docs/getting-started/nextjs-pages-router
Migration:
Production Validation
Tested In: WordPress Auditor (https://wordpress-auditor.webfonts.workers.dev)
Verified:
- ✅ All 11 templates work copy-paste
- ✅ v5→v6 breaking changes documented
- ✅ Message parts structure documented
- ✅ 12 common errors prevented
- ✅ Package versions current (2026-01-03)
- ✅ Next.js App Router & Pages Router examples
- ✅ Token savings: 55%
Recent Updates
v1.1.0 (2026-01-03):
- AI SDK v6 Stable: Updated from v5.0.99/v6.0.0-beta to v6.0.6 stable
- Message Parts Structure: Added v6 breaking change documentation (.content → .parts)
- Package Updates: @ai-sdk/react 1.0.0→3.0.6, @ai-sdk/openai 2.0.68→3.0.2
- useAssistant Deprecation: Added deprecation notice (OpenAI Assistants sunset Aug 26, 2026)
- React 19 Support: Framework support expanded to React 19 and Next.js 15
v1.0.1 (2025-11-19):
- Updated Package Versions: AI SDK 5.0.95
- Added YAML frontmatter metadata
License: MIT