Back to Blog
AI Development 10 min readJuly 15, 2026
Building Enterprise AI Chatbots with Next.js, Vercel AI SDK, and OpenAI
Muhammad Zain
TelGates Team
Building a chatbot is easy. Building an enterprise-grade, streaming, context-aware chatbot is hard. Here is how we build them at TelGates.
The Tech Stack
- Framework: Next.js (App Router)
- AI Tools: Vercel AI SDK, OpenAI API (GPT-4o)
- Database: PostgreSQL (Neon or Supabase) with pgvector for embeddings
- Styling: TailwindCSS + Radix UI
Core Features Required
- Real-time Streaming: Use `useChat` from Vercel AI SDK for instant responses without waiting for the full generation.
- Chat History: Store conversations in PostgreSQL to provide context across sessions.
- RAG Integration: Use pgvector to retrieve company knowledge before answering.
- Tool Calling: Allow the LLM to trigger actions (e.g., checking order status, booking meetings).
Implementing Tool Calling
With GPT-4o, you can define functions the model can call. For example, `getWeather(location)` or `checkInventory(productId)`. The LLM decides when to call these functions based on the user's intent, parses the JSON response, and generates a natural language reply.
Security Best Practices
- Implement rate limiting (Upstash Redis) to prevent API abuse.
- Never expose OpenAI keys on the client-side.
- Use system prompts to restrict the bot's domain (e.g., "You are a customer support agent. Do not answer questions outside of our product.").