Chatbot is a Next.js + AI SDK starter for building chat applications with model routing, auth, and persistent storage.
- Next.js (App Router)
- AI SDK
- Auth.js
- Drizzle ORM + Postgres
- Vercel AI Gateway
- Vercel Blob (optional)
- Redis (optional)
- Node.js 20+
pnpm10+
Install pnpm if needed:
npm install -g pnpmCopy .env.example to .env.local:
cp .env.example .env.localOn Windows PowerShell:
Copy-Item .env.example .env.localThen replace all **** values in .env.local.
AUTH_SECRET- session and auth encryption secretAI_GATEWAY_API_KEY- required when running outside VercelPOSTGRES_URL- required for DB operations and migrations
REDIS_URL- enables production rate limiting/resumable stream supportBLOB_READ_WRITE_TOKEN- required for blob/file storage features
Important: this project reads migrations from
.env.local(lib/db/migrate.ts), so setting only.envis not enough forpnpm db:migrate.
pnpm install
pnpm db:migrate
pnpm devOpen http://localhost:3000.
pnpm dev- run development serverpnpm build- run migrations and build production apppnpm start- start production serverpnpm db:migrate- apply database migrationspnpm db:studio- open Drizzle Studiopnpm check- run lint/check toolspnpm fix- auto-fix issues where possible
This app uses Vercel AI Gateway to route models defined in lib/ai/models.ts.
- On Vercel: OIDC auth is handled automatically.
- Locally/non-Vercel: you must set
AI_GATEWAY_API_KEY.
You can also switch to direct providers via AI SDK if desired.
Deploy on Vercel using the template:
Cause: pnpm db:migrate cannot find POSTGRES_URL in .env.local.
Fix:
- Ensure
.env.localexists. - Add
POSTGRES_URL=...to.env.local. - Re-run
pnpm db:migrate.
Set AI_GATEWAY_API_KEY in .env.local and restart the dev server.
- Never commit
.env,.env.local, or real secrets. - Keep
.env.examplewith placeholders only.