Skip to main content

Add an AI chat widget to your documentation site so visitors can ask questions and get instant answers powered by your library’s documentation on Context7.

The widget is a lightweight JavaScript snippet that renders a floating chat button. When clicked, it opens a chat panel where users can ask questions about your library and receive AI-generated answers grounded in your documentation.

Note
The chat widget is available to library owners who have claimed their library.

Chat widget panel showing AI-powered documentation assistant

How It Works#

  1. A visitor clicks the chat bubble on your site
  2. They type a question about your library
  3. The widget searches your library’s documentation on Context7
  4. An AI model generates an answer using the relevant documentation
  5. The response streams back in real time with markdown formatting

Setup#

Claim Your Library

You must be a verified owner of the library on Context7. If you haven’t claimed it yet, follow the Claim Your Library guide.

Enable the Widget

Navigate to your library’s admin page:

Open the Chat tab and toggle Enabled on.

Add Allowed Domains

Add the domains where the widget will be embedded. The widget will only work on domains you explicitly allow.

Examples:

  • docs.example.com — exact domain match
  • *.example.com — matches all subdomains (e.g., docs.example.com, blog.example.com) and example.com itself
  • example.com — matches the root domain only
Warning

The widget will not work on any external site until you add at least one allowed domain.

Save Settings

Click Save changes to persist your widget configuration.

Add the Script Tag

Copy the embed code from the admin panel and add it to your site’s HTML:

Place this tag in your root layout or HTML file so the widget loads on every page. The script loads asynchronously and does not block page rendering.

Adding with AI#

You can use an AI coding assistant to add the widget automatically. Copy the following prompt and paste it into Claude Code, Cursor, or any AI coding assistant. Replace /owner/repo with your library ID. The assistant will detect your framework and place the script tag in the correct location.

Framework Examples#

Use the next/script component in your root layout so the widget loads on every page:

app/layout.tsx

Customization#

The widget supports optional attributes for customization:

AttributeDescriptionDefault
data-libraryYour library ID (required)—
data-colorBrand color for the widget (hex code)#059669
data-positionWidget position on the pagebottom-right
data-placeholderPlaceholder text in the input fieldAsk about the docs...
data-welcome-messageInitial assistant message shown when the chat opensGenerated from library ID
data-widthChat panel width in pixels (320-1200)400
data-heightChat panel height in pixels (400-1200)600

Examples#

Custom color and position:

Custom placeholder text:

Custom welcome message:

Custom size:

The panel never grows larger than the browser window. On screens 640px wide or less, the widget always opens as a full-width sheet and ignores these values.

Position Options#

ValueDescription
bottom-rightFixed to the bottom-right corner
bottom-leftFixed to the bottom-left corner

Domain Configuration#

Allowed Domains#

You can configure up to 20 allowed domains per library. The widget validates the requesting origin against this list on every chat request.

PatternMatches
docs.example.comOnly docs.example.com
*.example.comAny subdomain: docs.example.com, blog.example.com, and example.com itself
example.comOnly the root domain example.com
Note

Domain validation is enforced server-side. Requests from domains not in your allowed list are rejected with a 403 error.

Adding and Removing Domains#

Manage domains from the Chat tab on your library’s admin page:

  1. Click Add domain to add a new entry
  2. Enter the domain (e.g., docs.example.com or *.example.com)
  3. Click Save changes to apply changes

To remove a domain, click the X icon next to it and save.