--- name: vercel-ai-sdk description: Guide for integrating Vercel AI SDK into Remix apps. Build AI chatbots, text completion, and agents within your Shopify app. --- # Vercel AI SDK for Remix Integration The Vercel AI SDK is the standard for building AI UIs. It abstracts streaming, state management, and provider differences. ## 1. Setup ```bash npm install ai @ai-sdk/openai ``` ## 2. Server-side Streaming (`action` function) Remix uses `Response` objects. The AI SDK has a helper `StreamingTextResponse`. ```typescript // app/routes/api.chat.ts import { streamText } from 'ai'; import { openai } from '@ai-sdk/openai'; import { ActionFunctionArgs } from "@remix-run/node"; export const action = async ({ request }: ActionFunctionArgs) => { const { messages } = await request.json(); const result = await streamText({ model: openai('gpt-4-turbo'), messages, }); return result.toDataStreamResponse(); }; ``` ## 3. Client-side UI hooks Use `useChat` to manage message state and input automatically. ```tsx // app/routes/app.assistant.tsx import { useChat } from 'ai/react'; export default function AssistantPage() { const { messages, input, handleInputChange, handleSubmit } = useChat({ api: '/api/chat', // points to the action above }); return (