export const metadata = { title: "AI SDK Integration" } # AI SDK Integration Use json-render with the Vercel AI SDK for seamless streaming. ## Installation ```bash npm install ai ``` ## API Route Setup ```typescript // app/api/generate/route.ts import { streamText } from 'ai'; import { catalog } from '@/lib/catalog'; export async function POST(req: Request) { const { prompt, currentTree } = await req.json(); // Generate system prompt from catalog const systemPrompt = catalog.prompt(); // Optionally include current UI state for context const contextPrompt = currentTree ? `\n\nCurrent UI state:\n${JSON.stringify(currentTree, null, 2)}` : ''; const result = streamText({ model: 'anthropic/claude-haiku-4.5', system: systemPrompt + contextPrompt, prompt, }); return result.toTextStreamResponse(); } ``` ## Client-Side Hook Use `useUIStream` on the client: ```tsx 'use client'; import { useUIStream, Renderer } from '@json-render/react'; function GenerativeUI() { const { spec, isStreaming, error, send } = useUIStream({ api: '/api/generate', }); return (
{error.message}
}