All posts
Build a chatbot in Next.js — streaming, memory, and UI
Tutorials 12 min read· 9 Aug 2026· By Tutorials

Build a chatbot in Next.js — streaming, memory, and UI

A complete Next.js 15 chatbot with server-sent streaming and message history.

Next.js + Vercel AI SDK is the shortest path to a production chatbot. Streaming out of the box, edge runtime friendly.

The route handler#

typescript
import { streamText } from "ai";
import { createOpenAI } from "@ai-sdk/openai";

const tb = createOpenAI({ apiKey: process.env.TB_KEY!, baseURL: "https://tokenbaazar.in/api/public/v1" });

export async function POST(req: Request) {
  const { messages } = await req.json();
  const result = await streamText({ model: tb("openai/gpt-5.4-mini"), messages });
  return result.toDataStreamResponse();
}

The UI#

Use the AI SDK's useChat hook — it handles the streaming state, message list, and input for you.

Ready to build?

Grab a key, keep your OpenAI SDK, and pay in INR.

Start free