An Open-Source AI Chatbot Template Built With Next.js and the AI SDK by Vercel.
Features · Model Providers · Deploy Your Own · Running locally
- Next.js App Router
- Advanced routing for seamless navigation and performance
- React Server Components (RSCs) and Server Actions for server-side rendering and increased performance
- AI SDK
- Unified API for generating text, structured objects, and tool calls with LLMs
- Hooks for building dynamic chat and generative user interfaces
- Supports OpenAI (default), Anthropic, Cohere, and other model providers
- shadcn/ui
- Styling with Tailwind CSS
- Component primitives from Radix UI for accessibility and flexibility
- Data Persistence
- Vercel Postgres powered by Neon for saving chat history and user data
- Vercel Blob for efficient file storage
- NextAuth.js
- Simple and secure authentication
- Analytics Database Integration
- Built-in database query tool for business analytics and insights
- Natural language interface for querying sales, user metrics, and marketing data
- Advanced security measures preventing destructive operations
- Sample analytics schema with realistic business data
This template ships with OpenAI gpt-4o as the default. However, with the AI SDK, you can switch LLM providers to OpenAI, Anthropic, Cohere, and many more with just a few lines of code.
You can deploy your own version of the Next.js AI Chatbot to Vercel with one click:
You will need to use the environment variables defined in .env.example to run Next.js AI Chatbot. It's recommended you use Vercel Environment Variables for this, but a .env file is all that is necessary.
Note: You should not commit your
.envfile or it will expose secrets that will allow others to control access to your various OpenAI and authentication provider accounts.
- Install Vercel CLI:
npm i -g vercel - Link local instance with Vercel and GitHub accounts (creates
.verceldirectory):vercel link - Download your environment variables:
vercel env pull
pnpm install
pnpm devYour app template should now be running on localhost:3000.
This chatbot includes a powerful database interaction tool that allows users to query business analytics data using natural language. The tool provides a secure interface for accessing sales metrics, user data, product performance, and marketing insights.
- Natural Language Queries: Ask questions like "How many sales did we have last month?" or "Show me our top performing products"
- Multiple Data Sources: Access user analytics, sales transactions, product performance, marketing campaigns, and user events
- Advanced Security: Built-in protection against SQL injection and destructive operations
- Sample Data: Pre-loaded with realistic business data for immediate testing
The analytics database includes these tables with sample data:
- analytics_users: User information and subscription tiers
- sales: Sales transactions with product details and revenue
- user_events: User interaction tracking and behavior analytics
- product_performance: Product metrics including views, purchases, and ratings
- marketing_campaigns: Campaign performance with budget, spend, and conversions
-
Environment Configuration: Add
ANALYTICS_DB_POSTGRES_URLto your environment variables# In .env.local ANALYTICS_DB_POSTGRES_URL=your_postgres_connection_string -
Initialize Database: The tool will automatically create tables and sample data on first use
-
Test the Tool: Run validation tests to ensure everything is working
pnpm test:db-tool
Once running, you can ask the chatbot questions like:
- "What's our total revenue this quarter?"
- "Show me user signups by month"
- "Which products have the highest conversion rates?"
- "How are our marketing campaigns performing?"
- "Add a new sale for $150 from user John Doe"
- Only SELECT, INSERT, UPDATE, and DELETE operations allowed
- DELETE and UPDATE operations require WHERE clauses
- No DDL operations (DROP, ALTER, TRUNCATE, etc.)
- Query results limited to 100 rows maximum
- Built-in SQL injection prevention