Technology

AI Chat Assistant

Configure and use the built-in AI chat panel powered by OpenRouter in this Fumadocs site.

Preview First

The AI chat opens from the floating Ask AI button in the bottom-right corner on both home and docs pages.

What It Does

Answers questions about your docs, can run internal doc search, and streams responses in real time.

Best Query Style

Ask specific questions like: "How do I use Git branching in this site docs?" for better grounded answers.

Important Limitation

AI can be inaccurate. Always verify critical details against source docs.

Configuration

Required Environment Variables

.env
OPENROUTER_API_KEY=your_openrouter_api_key
OPENROUTER_MODEL=minimax/minimax-m2.5:free
OPENROUTER_BASE_URL=https://openrouter.ai/api/v1

OPENROUTER_API_KEY is required. OPENROUTER_MODEL and OPENROUTER_BASE_URL are optional and use defaults when unset.

You can place these values in either .env or .env.local. Next.js loads both automatically.

For Netlify/Vercel, set the same variables in the project environment settings (do not commit secrets to git).

API Route

The chat backend is served from /api/chat and streams responses to the UI.

Usage

Open and Ask

Click the floating Ask AI button in the bottom-right corner.

Type your question, then press Enter to send.

Use Shift + Enter for a new line.

Use Retry to regenerate or Clear Chat to reset.

Keyboard Shortcuts

ActionmacOSWindows/Linux
Open panelCmd + /Ctrl + /
Close panelEscEsc
Send messageEnterEnter
New lineShift + EnterShift + Enter

Internal Components

import { AIChatWidget } from '@/components/ai/chat-widget';

// docs layout
<AIChatWidget mode="docs" />

// home layout
<AIChatWidget mode="overlay" />

Troubleshooting

No Response or Error

Check that OPENROUTER_API_KEY, OPENROUTER_MODEL, and OPENROUTER_BASE_URL are present in .env or .env.local, then restart the dev server.

  1. Confirm the server is running (pnpm dev).
  2. Open browser devtools and verify POST /api/chat is successful.
  3. If the API returns an error JSON, fix the missing config and retry.
  4. If answers are weak, ask a narrower query with clearer domain terms.

On this page