Skip to main content
Next.js Chatbot SDK

Add a custom AI chatbot to Next.js

Use @openstaticfish/chattybox inside a focused client boundary while the rest of your App Router application stays server-rendered. ChattyBox handles retrieval, citations, conversations, and scaling.

Crawls published docs pages
Source-cited answers
Embeds with one script
No docs migration required
No credit card requiredYour content stays yours
Ask ChattyBox
x
Where should I start if I need a reliable answer from this site?
Start by adding your website URL to ChattyBox. It crawls your content, answers from the pages it finds, and shows visitors the sources behind each response.
iSources3^
Next.js guide
chattybox.ai
Analytics
chattybox.ai
Home
chattybox.ai
Ask a question...
Powered by ChattyBox
Built for Next.js App Router teams

Launch a source-cited chatbot without rebuilding your docs stack

ChattyBox crawls your existing documentation, indexes the content for retrieval, and embeds a chatbot that answers using your docs instead of generic model memory.

Keep the interactive chat surface in a small use client boundary.
Expose only a public, origin-restricted widget key through NEXT_PUBLIC variables.
Render cited answers with your existing Next.js design system and application shell.
Keep crawling, retrieval, vector storage, answer generation, and scaling managed by ChattyBox.
Workflow step

Install @openstaticfish/chattybox in the Next.js application.

Workflow step

Add the public widget API key and API URL as NEXT_PUBLIC environment variables.

Workflow step

Create a client component for chat state and browser interaction.

Workflow step

Import that client component from a Server Component page or layout.

Three-step launch

Paste your Next.js URL, test cited answers, then install the widget.

Build a Next.js chatbot
App Router integration

Add interactivity without giving up server rendering

Keep the SDK at the client edge where chat interaction happens and preserve Server Components for the rest of the application.

01

Small client boundary

Mark only the interactive chat module with use client instead of moving an entire page or layout to the browser.

02

Public key clarity

Use a browser-safe project key with allowed origins; never expose management credentials through NEXT_PUBLIC variables.

03

Custom product UI

Render messages and citations in your own navigation, account area, docs shell, or support workflow.

04

No custom RAG service

Avoid adding route handlers solely to proxy a managed browser API unless your product has a concrete server-side requirement.

Install path

Create a Next.js App Router chat client

The SDK uses fetch and browser-visible project credentials, so initialize it in a client module. Keep secrets and management APIs out of NEXT_PUBLIC variables.

  1. 1Install the npm package and configure an origin-restricted public key.
  2. 2Create a use client component that owns message and conversation state.
  3. 3Render the component from your server-rendered page without converting the whole route to a client component.
Build a Next.js chatbot
app/components/chat.tsx
tsx
'use client';

import { useState } from 'react';
import { Chattybox } from '@openstaticfish/chattybox';

const chattybox = new Chattybox({
  apiKey: process.env.NEXT_PUBLIC_CHATTYBOX_API_KEY!,
  baseUrl: process.env.NEXT_PUBLIC_CHATTYBOX_API_URL!,
});

export function Chat() {
  const [answer, setAnswer] = useState('');

  async function ask(message: string) {
    const response = await chattybox.sendMessage({ message });
    setAnswer(response.message);
  }

  return <div aria-live="polite">{answer}</div>;
}
FAQ

Common questions

1

Does the ChattyBox SDK work with the Next.js App Router?

Yes. Use it in a client component for interactive chat state and render that component from an App Router page or layout.

2

Do I need a Next.js route handler for ChattyBox?

Not for the normal browser integration. Public widget keys are designed for client use and can be restricted to approved origins.

3

Are NEXT_PUBLIC ChattyBox keys secrets?

The public widget key identifies a project but is not a management credential. Restrict it to your production and preview origins, and never expose administrative secrets.

4

Can I use the hosted ChattyBox widget with Next.js?

Yes. The hosted installation guide shows the next/script path when you prefer a maintained UI instead of a custom SDK interface.

Start free

No credit card required. Your content is not used for model training.

Create free chatbot

Free tier. No card needed.