ai-sdk-5 — Claude Code skill: what it does, how to install
Guides code generation for Vercel AI SDK 5, covering breaking syntax shifts from v4.
Apache-2.0 138 installs ★ 678 updated 2026-03-28
npx skills add Gentleman-Programming/Gentleman-Skills --skill ai-sdk-5 -a claude-codeWhat ai-sdk-5 does
The skill supplies patterns for Vercel AI SDK 5 so coding agents avoid outdated v4 conventions. In v5, useChat is exported by @ai-sdk/react, while transport configuration relies on DefaultChatTransport imported from ai.
Message payloads no longer provide a single content string. The UIMessage format uses a parts array containing typed objects for text, images, tool executions, and returned tool results. The skill provides reference logic to iterate through and render those parts correctly.
Server setups cover streamText endpoints with toDataStreamResponse(), LangChain piping with toUIMessageStream, and schema-based tools using zod. Codebases still passing raw api strings directly to client hooks will encounter TypeScript compilation errors.
What it helps with
- Migrate client hooks from AI SDK 4 to
@ai-sdk/reactwithDefaultChatTransport - Render messages via
UIMessage.partsinstead of deprecated text strings - Implement route handlers using
streamTextwith typedtooldefinitions - Stream LangChain model responses into Vercel AI SDK UI clients
Example prompts for the agent
- Build a chat UI component using Vercel AI SDK 5 and DefaultChatTransport
- Write an API route with streamText and a zod-validated tool call
- Convert UIMessage parts array into rendered React elements
How to install ai-sdk-5
1Skills CLI (Vercel)
npx skills add Gentleman-Programming/Gentleman-Skills --skill ai-sdk-5 -a claude-code2Manually: put the files in place
~/.claude/skills/ai-sdk-5/SKILL.mdCopy the whole skill folder; for one project use .claude/skills/ai-sdk-5/
1Skills CLI (Vercel)
npx skills add Gentleman-Programming/Gentleman-Skills --skill ai-sdk-5 -a codex2Manually: put the files in place
.agents/skills/ai-sdk-5/SKILL.mdFor all projects use ~/.agents/skills/
1Skills CLI (Vercel)
npx skills add Gentleman-Programming/Gentleman-Skills --skill ai-sdk-5 -a cursor2Manually: put the files in place
.cursor/skills/ai-sdk-5/SKILL.mdCursor also reads .agents/skills/ and .claude/skills/
1GitHub CLI
gh skill install Gentleman-Programming/Gentleman-Skills curated/ai-sdk-5/SKILL.md2Manually: put the files in place
.github/skills/ai-sdk-5/SKILL.md1Skills CLI (Vercel)
npx skills add Gentleman-Programming/Gentleman-Skills --skill ai-sdk-5 -a gemini-cli2Platform CLI
gemini skills install https://github.com/Gentleman-Programming/Gentleman-Skills --path curated/ai-sdk-5Manually: put the files in place
.devin/skills/ai-sdk-5/SKILL.mdThe legacy .windsurf/skills/ path still works
Skills CLI (Vercel)
npx skills add Gentleman-Programming/Gentleman-Skills --skill ai-sdk-5 -a opencodeClaude.ai
Zip the folder and upload it in Settings → Capabilities → Skills
Step by step, with commands for each platform: How to install skills in Claude Code: five ways
Questions about ai-sdk-5
How to install ai-sdk-5 in Claude Code?
Run npx skills add Gentleman-Programming/Gentleman-Skills --skill ai-sdk-5 -a claude-code in your terminal.
What does the ai-sdk-5 skill do?
It teaches your coding assistant the updated APIs, types, and streaming conventions of Vercel AI SDK 5.
Which packages are referenced by this skill?
Patterns depend on @ai-sdk/react, ai, @ai-sdk/openai, and zod, alongside @ai-sdk/langchain for LangChain pipelines.
Source text
SKILL.md · Apache-2.0
---
name: ai-sdk-5
description: >
Vercel AI SDK 5 patterns.
Trigger: When building AI chat features - breaking changes from v4.
license: Apache-2.0
metadata:
author: gentleman-programming
version: "1.0"
---
## Breaking Changes from AI SDK 4
```typescript
// ❌ AI SDK 4 (OLD)
import { useChat } from "ai";
const { messages, handleSubmit, input, handleInputChange } = useChat({
api: "/api/chat",
});
// ✅ AI SDK 5 (NEW)
import { useChat } from "@ai-sdk/react";
import { DefaultChatTransport } from "ai";
const { messages, sendMessage } = useChat({
transport: new DefaultChatTransport({ api: "/api/chat" }),
});
```
## Client Setup
```typescript
import { useChat } from "@ai-sdk/react";
import { DefaultChatTransport } from "ai";
import { useState } from "react";
export function Chat() {
const [input, setInput] = useState("");
const { messages, sendMessage, isLoading, error } = useChat({
transport: new DefaultChatTransport({ api: "/api/chat" }),
});
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
if (!input.trim()) return;
sendMessage({ text: input });
setInput("");
};
return (
<div>
<div>
{messages.map((message) => (
<Message key={message.id} message={message} />
))}
</div>
<form onSubmit={handleSubmit}>
<input
value={input}
onChange={(e) => setInput(e.target.value)}
placeholder="Type a message..."
disabled={isLoading}
/>
<button type="submit" disabled={isLoading}>
Send
</button>
</form>
{error && <div>Error: {error.message}</div>}
</div>
);
}
```
## UIMessage Structure (v5)
```typescript
// ❌ Old: message.content was a string
// ✅ New: message.parts is an array
interface UIMessage {
id: string;
role: "user" | "assistant" | "system";
parts: MessagePart[];
}
type MessagePart =
| { type: "text"; text: string }
| { type: "image"; image: string }
| { type: "tool-call"; toolCallId: string; toolName: string; args: unknown }
| { type: "tool-result"; toolCallId: string; result: unknown };
// Extract text from parts
function getMessageText(message: UIMessage): string {
return message.parts
.filter((part): part is { type: "text"; text: string } => part.type === "text")
.map((part) => part.text)
.join("");
}
// Render message
function Message({ message }: { message: UIMessage }) {
return (
<div className={message.role === "user" ? "user" : "assistant"}>
{message.parts.map((part, index) => {
if (part.type === "text") {
return <p key={index}>{part.text}</p>;
}
if (part.type === "image") {
return <img key={index} src={part.image} alt="" />;
}
return null;
})}
</div>
);
}
```
## Server-Side (Route Handler)
```typescript
// app/api/chat/route.ts
import { openai } from "@ai-sdk/openai";
import { streamText } from "ai";
export async function POST(req: Request) {
const { messages } = await req.json();
const result = await streamText({
model: openai("gpt-4o"),
messages,
system: "You are a helpful assistant.",
});
return result.toDataStreamResponse();
}
```
## With LangChain
```typescript
// app/api/chat/route.ts
import { toUIMessageStream } from "@ai-sdk/langchain";
import { ChatOpenAI } from "@langchain/openai";
import { HumanMessage, AIMessage } from "@langchain/core/messages";
export async function POST(req: Request) {
const { messages } = await req.json();
const model = new ChatOpenAI({
modelName: "gpt-4o",
streaming: true,
});
// Convert UI messages to LangChain format
const langchainMessages = messages.map((m) => {
const text = m.parts
.filter((p) => p.type === "text")
.map((p) => p.text)
.join("");
return m.role === "user"
? new HumanMessage(text)
: new AIMessage(text);
});
const stream = await model.stream(langchainMessages);
return toUIMessageStream(stream).toDataStreamResponse();
}
```
## Streaming with Tools
```typescript
import { openai } from "@ai-sdk/openai";
import { streamText, tool } from "ai";
import { z } from "zod";
const result = await streamText({
model: openai("gpt-4o"),
messages,
tools: {
getWeather: tool({
description: "Get weather for a location",
parameters: z.object({
location: z.string().describe("City name"),
}),
execute: async ({ location }) => {
// Fetch weather data
return { temperature: 72, condition: "sunny" };
},
}),
},
});
```
## useCompletion (Text Generation)
```typescript
import { useCompletion } from "@ai-sdk/react";
import { DefaultCompletionTransport } from "ai";
const { completion, complete, isLoading } = useCompletion({
transport: new DefaultCompletionTransport({ api: "/api/complete" }),
});
// Trigger completion
await complete("Write a haiku about");
```
## Error Handling
```typescript
const { error, messages, sendMessage } = useChat({
transport: new DefaultChatTransport({ api: "/api/chat" }),
onError: (error) => {
console.error("Chat error:", error);
toast.error("Failed to send message");
},
});
// Display error
{error && (
<div className="error">
{error.message}
<button onClick={() => sendMessage({ text: lastInput })}>
Retry
</button>
</div>
)}
```
## Keywords
ai sdk, vercel ai, chat, streaming, langchain, openai, llm
© gentleman-programming · Apache-2.0 · Gentleman-Programming/Gentleman-Skills