Skip to content
Last updated

AI assistant web component

Plans:ScaleEnterprise

The AI assistant web component adds the AI assistant of your Redocly project to any website, for example your app or your support portal. Users ask questions on your site, and the assistant answers from your docs.

AI assistant and protected docs

By default, the assistant uses only the content that anonymous users can read. To use protected content, send identity tokens.

Add the assistant to your site

  1. 1

    Allow requests from your site

    You must have the Admin role in the project.

    1. In the Redocly platform, open your project, and select Settings > Environment variables.
    2. Add the REDOCLY_CORS_ORIGINS variable with the address of your site as the value, for example https://app.acme.com. To allow more sites, separate the addresses with commas.
  2. 2

    Redeploy the project

    1. Navigate to Deployments.
    2. On the latest production deployment, select More actions > Redeploy. The variable takes effect after the redeploy.
  3. 3

    Add the snippet

    1. Configure the assistant in the playground.
    2. Follow the install steps under the preview.
Live preview

Install AI assistant

  1. 1

    Enter the URL of your Redocly project.

  2. 2

    Copy the snippet to your site.

    index.html
    <script src="https://cdn.redocly.com/ai-assistant/releases/latest/main.js"></script>
    
    <redocly-ai-assistant
      api-url="https://your-project.com"
      color-mode="system"
      welcome-message="Hi! Ask me anything about these docs."
      suggestions='["How do I get started?","How do I authenticate?"]'
    ></redocly-ai-assistant>

See the AI assistant web component options to reference all available attributes.

Control the assistant from your code

The script adds the window.RedoclyAssistant object to your page. Use it in your scripts after the <script> tag of the assistant. The examples below show some common uses.

<button id="help-button" type="button">Help</button>

<redocly-ai-assistant
  api-url="https://docs.acme.com"
  trigger-hide
></redocly-ai-assistant>

<script>
  document.getElementById('help-button').addEventListener('click', () => {
    window.RedoclyAssistant.open();
  });
</script>

For all the methods, keys, and events, see Web component API.

Match your brand

To change the colors and the font, set CSS variables on the redocly-ai-assistant element:

redocly-ai-assistant {
  --font-family-base: 'Inter', sans-serif;
  --button-bg-color-primary: #0f766e;
  --search-ai-user-bg-color: #0f766e;
}

See CSS variables to reference all available variables.

Let users contact your support team

The assistant can display a Contact support button that sends the conversation to your support team by email. To turn it on, see Configure AI assistant support escalation.

Troubleshoot

Something went wrong

The browser blocks the request to your project. The browser console shows a CORS error.

  • Make sure that REDOCLY_CORS_ORIGINS has the exact address of your site: the scheme, the host, and the port. Wildcards, such as *, do not work.
  • Redeploy the project after you change the variable.
  • If your project uses a path prefix, add the prefix to api-url, for example https://acme.com/docs.
  • Each IP address can send 25 requests in 5 minutes.
Authentication Required

The project does not let anonymous users use the AI assistant. If you set access.rbac.features.aiSearch, add anonymous: read to it.

Feature Unavailable

The AI assistant is off for the project. Make sure that aiAssistant.hide is not true in redocly.yaml, and that your plan includes the AI assistant web component.

The assistant does not use your docs
  • The content requires login. Send identity tokens.
  • The locale, product, or version attributes do not match your content.
  • The pages are new. The assistant uses a page only after the next production deployment.
The Ask AI button does not show
  • The api-url attribute is missing. The browser console displays a warning.
  • The Content Security Policy of your site blocks the script. See Content Security Policy.

Resources