What you’ll build
A reusable widget that embeds the assistant directly in your application. The widget provides:- A floating button that opens a chat panel when clicked
- Real-time streaming responses based on information from your documentation
- Message rendering with Markdown support

Prerequisites
- The assistant enabled for your project
- Your domain name, which appears at the end of your dashboard URL. For example, if your dashboard URL is
https://app.mintlify.com/org-name/domain-name, your domain name isdomain-name - An assistant API key
- A Next.js app that uses the App Router
- Basic React knowledge
Get your assistant API key
- Navigate to the API keys page in your dashboard.
- Click Create Assistant API Key.
- Copy the assistant API key (starts with
mint_dsc_) and save it securely.
Your assistant API key controls access to your assistant quota. This tutorial keeps the key server-side using a backend proxy so the key never reaches the client bundle.
Build the widget
The widget uses the AI SDKuseChat hook to call the assistant message endpoint through a route in your app.
1
Install dependencies
2
Store your API key
Store your assistant API key as a server-side environment variable. Don’t use the Replace
NEXT_PUBLIC_ prefix, which bundles the value into your client code..env.local
mint_dsc_your_token_here with your assistant API key.3
Add a proxy route
Create a route that adds your API key to each request and forwards it to the Mintlify API. The route streams the response back unchanged and passes through the thread headers.Replace
app/api/assistant/route.js
your-domain with your domain name.4
Create the widget component
components/AssistantWidget.jsx
fp field identifies the user. Use anonymous or your own user ID.5
Add the widget to your layout
Render the widget in your root layout so it appears on every page.
app/layout.jsx
6
Start the development server
Customization ideas
Source citations
The assistant searches your documentation before it answers. Each search appears in the message as atool-search part, and its output.results array lists the pages it found. Extract them to show sources under each answer:
https://docs.example.com with the URL of your documentation site.
Track conversation threads
Store thread IDs and thread keys to maintain conversation history across sessions. When a user creates a new conversation thread, the server returns two values in the response headers:X-Thread-Id: The thread identifierX-Thread-Key: A secret key for the thread (only returned once, when you create the thread)
threadId and threadKey in the request body. If you send a threadId without the corresponding threadKey, the server returns a 404 error.
The transport reads its body function before each request, so the next request includes the saved values: