How to Build an AI App with Next.js and Vercel

Full-stack AI in a weekend — Vercel AI SDK end to end

Ad placeholder (leaderboard)

What you are building

This tutorial takes you from an empty folder to a deployed, streaming AI chat app in a weekend. You scaffold a Next.js App Router project, add the Vercel AI SDK, wire a streaming chat endpoint with the useChat hook so responses appear word by word, and deploy to Vercel with your provider key stored as an encrypted environment variable. The whole stack is serverless: no servers to manage, and the model call runs on the server side so your key never reaches the browser.

How it works

You create a Next.js project and install the AI SDK plus a provider package, then put your provider key in .env.local. A route handler under app/api/chat calls streamText with the conversation messages and returns the stream directly. On the client, a component uses the useChat hook, which posts messages to that route and appends the streamed tokens to the assistant reply as they arrive. When you push to a Git repo connected to Vercel, the route deploys as a serverless or edge function; you add the same provider key under the project’s Environment Variables so production reads it from process.env without ever shipping it to the client. The SDK’s provider abstraction means swapping models later is a one-line change.

Tips and the planner below

Keep your key out of any NEXT_PUBLIC_ variable — that prefix ships to the browser. Run chat routes on the edge runtime for low-latency streaming, and only move a route to the Node.js runtime when you need a Node-only API or longer execution. Use the SDK’s provider abstraction so you can A/B different models without rewrites. Hosting the app itself is often free on Vercel’s hobby tier; the spend that matters is the model API. The planner below estimates your monthly model cost from daily conversations, turns per conversation, and average input and output token sizes.

Ad placeholder (rectangle)