This widget is and is subject to change in minor versions.
Signature
Import
About this widget
Use thechat widget to display a chat interface that interacts with a generative AI assistant.
See also: Agent Studio
Examples
JavaScript
Options
The CSS Selector or
HTMLElement to insert the widget into.The unique identifier of the agent to connect to. You can find the
agentId in the Agent Studio dashboard.JavaScript
A custom transport object to handle the communication between the chat widget and the agent. The API endpoint must be compatible with Vercel AI SDK 5.
JavaScript
A function to return the URL of the main search page with the
nextUiState. This is used to navigate to the main search page when the user clicks on “View all” in the search tool.JavaScript
An object defining the client-side tools that the agent can use to interact with your application. A tool’s name must match what is defined in the Agent Studio dashboard.
JavaScript
The CSS classes you can override:
root. The root element of the widget.container. The container element.header. The header section of the widget.root. The root element.clear. The clear button.close. The close button.maximize. The maximize button.title. The title element.titleIcon. The title icon element.
messages. The messages section of the widget.root. The root element.content. The scrollable content.scroll. The scroll container.scrollToBottom. The scroll to bottom button.scrollToBottomHidden. The hidden state of the scroll to bottom button.
message. The message in the messages section.root. The root element.container. The message container.leading. The leading element (e.g., avatar).content. The content element.message. The message text element.actions. The action buttons container.footer. The footer element.
prompt. The prompt section of the widget.root. The root element.actions. The actions container.body. The body element.footer. The footer element.header. The header element.submit. The submit button.textarea. The textarea element.
toggleButton. The toggle button of the widget.root. The root element.
JavaScript
Templates
You can customize parts of a widget’s UI using the Templates API. Each template includes anhtml function,
which you can use as a tagged template.
This function safely renders templates as HTML strings and works directly in the browser—no build step required.
For details, see Templating your UI.
The
html function is available in InstantSearch.js version 4.46.0 or later.The template to use for each result. This template receives an object containing a single record. You can use Algolia’s highlighting feature with the
highlight function, directly from the template system.JavaScript
Templates to use for the header section of the widget.
clearLabelText. Accessible label for the clear button.closeIcon. The close icon template.closeLabel. Accessible label for the close button.maximizeIcon. The maximize icon template. Receives a parameter containing{ maximized: boolean }for conditional rendering.maximizeLabelText. Accessible label for the maximize button.minimizeIcon. The minimize icon template.minimizeLabelText. Accessible label for the minimize button.titleIcon. The title icon template (defaults to sparkles).titleText. The title text to display.
JavaScript
Templates to use for the messages section of the widget.
copyToClipboardLabelText. Accessible label for the copy to clipboard action.error. Custom template when there is an error loading messages.loader. Custom loader template.loaderText. Text to display in the loader.regenerateLabelText. Accessible label for the regenerate action.scrollToBottomLabelText. Accessible label for the scroll to bottom button.
JavaScript
Templates to use for an individual message in the messages section of the widget.
messageLabelText. Accessible label for the message.actionsLabelText. Accessible label for the actions container.
JavaScript
Templates to use for messages that come from the chat assistant.
leading. The leading element (e.g., avatar).footer. The footer element of the message.
JavaScript
Templates to use for messages that come from the user.
leading. The leading element (e.g., avatar).footer. The footer element of the message.
JavaScript
Templates to use for the prompt section of the widget.
disclaimerText. Disclaimer text shown in the prompt footer.emptyMessageTooltipText. Tooltip for the submit button when message is empty.footer. Custom footer template.header. Custom header template.sendMessageTooltipText. Tooltip for the send button.stopResponseTooltipText. Tooltip for the stop button.textareaLabelText. Accessible label for the textarea.textareaPlaceholderText. Placeholder text for the textarea.
JavaScript
Templates to use for the toggle button of the widget.
icon. Custom icon template. Receives a parameter containing{ isOpen: boolean }for conditional rendering.
JavaScript
HTML output
HTML