Next.js AI Chatbot — Vercel Reference App Template
Production-ready AI chatbot template by Vercel using Next.js, AI SDK, shadcn/ui, and Auth.js. Supports Claude, GPT-4, and Gemini. Streaming, tool use, file uploads, and conversation history. 8,000+ stars.
What it is
Next.js AI Chatbot is Vercel's official reference application for building production AI chatbots. It ships with Next.js App Router, Vercel AI SDK, shadcn/ui components, and Auth.js authentication. The template supports Claude, GPT-4, and Gemini out of the box with streaming responses, tool use, file uploads, and conversation history stored in PostgreSQL.
This template targets developers who need a battle-tested starting point for AI chat applications rather than building from scratch. Setup takes under five minutes with npx create-next-app.
How it saves time or tokens
The template eliminates weeks of boilerplate work: streaming SSE setup, conversation persistence, authentication flows, and responsive UI are all pre-built. The Vercel AI SDK handles provider abstraction so switching between Claude, GPT-4, and Gemini requires changing one environment variable. Token usage is managed through the SDK's built-in streaming pipeline, which sends tokens to the client as they arrive rather than waiting for full completion.
How to use
- Run
npx create-next-app --example https://github.com/vercel/ai-chatbot my-chatbotto scaffold the project. - Copy
.env.exampleto.env.localand add your API key (ANTHROPIC_API_KEY or OPENAI_API_KEY). - Run
npm run devand openhttp://localhost:3000to start chatting.
Example
# Scaffold the project
npx create-next-app --example https://github.com/vercel/ai-chatbot my-chatbot
cd my-chatbot
# Configure environment
cp .env.example .env.local
# Edit .env.local: add ANTHROPIC_API_KEY=sk-ant-...
# Start development server
npm run dev
# Open http://localhost:3000
Related on TokRepo
- AI tools for coding -- more AI-powered development templates and tools
- Prompt library -- reusable prompts for chatbot system instructions
Common pitfalls
- Forgetting to set up the PostgreSQL database for conversation history causes the app to crash on first message send.
- The default model configuration uses GPT-4o; switch to Claude by updating the model provider in the route handler.
- Auth.js session cookies require HTTPS in production; local development works on HTTP but deployed apps need proper SSL.
Frequently Asked Questions
The template supports Claude (Anthropic), GPT-4 (OpenAI), and Gemini (Google) through the Vercel AI SDK. You can switch between models by changing the provider configuration. The SDK abstracts provider differences so your UI code stays the same.
Yes. The template uses Auth.js (formerly NextAuth.js) with GitHub and Google OAuth providers pre-configured. Each user gets their own conversation history. You can add additional OAuth providers by extending the Auth.js configuration.
Conversations are stored in PostgreSQL via Drizzle ORM. Each message includes the role (user or assistant), content, and metadata like token usage. The schema supports multiple conversations per user with full chat history.
Yes. The template is a standard Next.js application that runs anywhere Next.js runs: AWS, Docker, Railway, or any Node.js host. Vercel deployment is the simplest path but not required. You need a PostgreSQL database regardless of hosting.
The template uses Server-Sent Events (SSE) via the Vercel AI SDK. The API route streams tokens from the LLM provider to the client as they are generated. The React frontend renders tokens incrementally, giving users immediate feedback.
Citations (3)
- Vercel AI Chatbot GitHub— Next.js AI Chatbot official reference application by Vercel
- Vercel AI SDK Documentation— Vercel AI SDK for multi-model support
- Auth.js Documentation— Auth.js for authentication
Related on TokRepo
Source & Thanks
Created by Vercel. Licensed under MIT.
ai-chatbot — ⭐ 8,000+
Thanks to Vercel for the definitive AI chatbot starting point.
Discussion
Related Assets
Claude-Flow — Multi-Agent Orchestration for Claude Code
Layers swarm and hive-mind multi-agent orchestration on top of Claude Code with 64 specialized agents, SQLite memory, and parallel execution.
ccusage — Real-Time Token Cost Tracker for Claude Code
CLI that reads ~/.claude logs and breaks down Claude Code token spend by day, session, and project — pluggable into your statusline.
SuperClaude — Workflow Framework for Claude Code
Adds 16+ slash commands, 9 cognitive personas, and a smart flag system to Claude Code in one pipx install.