Lesson 183 of 1596
Deploying an AI App to Vercel
Streaming AI chat to production takes one framework and three env vars. Learn the deploy path that actually ships.
Creators · AI-Assisted Coding · ~30 min read
From Localhost to Public URL
Next.js plus the AI SDK plus Vercel gives you a streaming chatbot on the internet in 15 minutes. The trick is getting the streaming route and env vars right the first time.
maxDuration = 30 tells Vercel this function may stream for 30s. toUIMessageStreamResponse is what the useChat hook expects.
// app/api/chat/route.ts import { streamText, convertToModelMessages, UIMessage } from "ai"; import { anthropic } from "@ai-sdk/anthropic"; export const maxDuration = 30; export async function POST(req: Request) { const { messages }: { messages: UIMessage[] } = await req.json(); const result = streamText({ model: anthropic("claude-opus-4-7"), system: "You are a helpful assistant.", messages: convertToModelMessages(messages), }); return result.toUIMessageStreamResponse(); }useChat manages the message list and streaming state. Pair with AI Elements components for a polished UI.
// app/page.tsx "use client"; import { useState } from "react"; import { useChat } from "@ai-sdk/react"; export default function Chat() { const { messages, sendMessage, status } = useChat(); const [input, setInput] = useState(""); return ( <div> {messages.map((m) => ( <div key={m.id}><b>{m.role}:</b> {m.parts.map((p) => p.type === "text" ? p.text : "").join("")}</div> ))} <form onSubmit={(e) => { e.preventDefault(); sendMessage({ text: input }); setInput(""); }}> <input value={input} onChange={(e) => setInput(e.target.value)} disabled={status !== "ready"} /> </form> </div> ); }Link the project, add the secret, and deploy. Preview URLs come free on every push.
# deploy npm i -g vercel vercel link vercel env add ANTHROPIC_API_KEY production vercel --prodKey terms in this lesson
The big idea: AI SDK on the server, useChat on the client, Vercel in the middle. Three files and three env vars put a real AI app online.
End-of-lesson quiz
Check what stuck
6 questions · Score saves to your progress.
Tutor
Curious about “Deploying an AI App to Vercel”?
Ask anything about this lesson. I’ll answer using just what you’re reading — short, friendly, grounded.
Progress saved locally in this browser. Sign in to sync across devices.
Related lessons
Keep going
Creators · 50 min
AI-Assisted Code Review Workflows (for Teams)
Code review is the highest-leverage touchpoint in a team. Automating the noise with AI frees humans to focus on the irreducibly human parts. Let's design the workflow.
Creators · 50 min
Deploy Pipelines With AI in the Loop
AI belongs in CI/CD too. From PR previews to rollback judgment calls, agents can operate inside your pipeline safely — if you scope them right.
Creators · 75 min
Capstone: Ship a Real Full-Stack AI-Assisted Project
The creators capstone. You scope, design, build, test, deploy, and document a real full-stack project using an agentic workflow — end to end.
