A sleek, production-ready AI chat application built with Next.js 14, OpenAI API, and Tailwind CSS. Features real-time streaming responses, conversation history, model selection, and a dark/light theme switcher.
- 🔴 Streaming responses — token-by-token output via Server-Sent Events
- 💬 Conversation history — full multi-turn context sent with every request
- 🌗 Dark / Light theme — persisted to localStorage
- 🤖 Model selector — switch between GPT-4o, GPT-4o mini, GPT-3.5 Turbo
- ⏹ Stop generation — abort mid-stream at any time
- 📱 Responsive design — collapsible sidebar on mobile
- 🎨 Custom UI — JetBrains Mono + Syne fonts, CSS variable theming, grain overlay
- 🧹 Clear conversation — reset chat history instantly
ai-chat-interface/
├── app/
│ ├── api/
│ │ └── chat/
│ │ └── route.ts # Streaming API route (OpenAI SSE)
│ ├── globals.css # Global styles + CSS variables
│ ├── layout.tsx # Root layout
│ └── page.tsx # Entry page
├── components/
│ ├── ChatInterface.tsx # Main layout container
│ ├── ChatInput.tsx # Auto-resizing textarea + send/stop button
│ ├── Header.tsx # Top bar with theme toggle + model badge
│ ├── MessageBubble.tsx # User & assistant message with markdown rendering
│ ├── Sidebar.tsx # Model selector + actions sidebar
│ └── WelcomeScreen.tsx # Empty state with prompt suggestions
├── lib/
│ ├── types.ts # Shared TypeScript types
│ ├── useChat.ts # Streaming chat logic (custom hook)
│ ├── useTheme.ts # Dark/light theme hook
│ └── utils.ts # Helpers (generateId, formatTime, etc.)
├── .env.local.example # Environment variable template
├── next.config.js
├── tailwind.config.ts
├── tsconfig.json
└── package.json
cd ai-chat-interfacenpm install
# or
yarn installcp .env.local.example .env.localOpen .env.local and add your OpenAI API key:
OPENAI_API_KEY=sk-your-key-hereGet your API key at platform.openai.com/api-keys
npm run devOpen http://localhost:3000 in your browser.
npm run build
npm start- Push the project to a GitHub repository
- Go to vercel.com and import the repo
- Add the environment variable
OPENAI_API_KEYin the Vercel dashboard - Click Deploy
| Variable | Description |
|---|---|
OPENAI_API_KEY |
Your OpenAI API secret key (required) |
Edit app/page.tsx:
const [model, setModel] = useState<ModelId>("gpt-4o"); // change default hereEdit app/api/chat/route.ts to prepend a system message:
messages: [
{ role: "system", content: "You are a helpful assistant." },
...messages,
],| Technology | Purpose |
|---|---|
| Next.js 14 | React framework with App Router |
| OpenAI Node SDK | GPT API integration |
| Tailwind CSS | Utility-first styling |
| TypeScript | Type safety |
| Lucide React | Icon set |
MIT — free to use, modify, and distribute.