ChatAI Docs

Widget

Embed ChatAI with a script tag (hosted or self-hosted chat.js).

The embeddable widget is an IIFE bundle (chat.js) with a Shadow DOM launcher. Copy the exact snippet from the assistant Install tab.

Zero-install (recommended): load hosted chat.js from your ChatAI deployment — no npm package required.

Programmatic embed: install @nightzeros/chatai-widget or @nightzeros/chatai-react from npm when you need mountWidget / <ChatWidget /> in your bundler (see React). The hosted IIFE is not published to npm.

Browser baseline: modern evergreen browsers with Shadow DOM and fetch / streaming support.

Load chat.js from your ChatAI origin. Production hosted URL:

<script
  src="https://app.nightzeros.com/widget/chat.js"
  data-assistant-id="asst_your_public_id"
  async
></script>

Self-hosted ChatAI instance:

<script
  src="https://your-chatai-instance.example/widget/chat.js"
  data-assistant-id="asst_your_public_id"
  async
></script>

Locally:

<script
  src="http://localhost:3000/widget/chat.js"
  data-assistant-id="asst_your_public_id"
  async
></script>

Self-hosted script

Serve chat.js from your static origin and point API calls at ChatAI:

<script
  src="https://static.example.com/chat.js"
  data-assistant-id="asst_your_public_id"
  data-api-url="https://your-chatai-instance.example"
  async
></script>

From this monorepo:

pnpm examples:prepare-widget
# writes examples/html-widget/chat.js

Open examples/html-widget/self-host.html.

If data-api-url is missing or wrong, the launcher may appear while config/chat fail (CORS, 404, wrong host).

Data attributes

AttributeRequiredMeaning
data-assistant-idYesAssistant publicId
data-api-urlSelf-host onlyAbsolute ChatAI API origin
data-voiceNoSet to off to hide the Voice button on this page even when the assistant offers Voice
data-voice-experienceNoclassic (default), orb, dock, guided, companion, or side-panel — overrides the assistant Customize setting for this page
data-voice-captionsNoon or off — default visibility of the stage captions panel (ignored by Classic)

Appearance (colors, position, suggested questions, Voice experience) is controlled from Customize on the assistant and loaded at runtime — keep Customize saved so embeds match the draft preview.

Voice (preview)

When the assistant owner turns on Offer Voice in the public widget (assistant Settings → Privacy) and the instance has a Voice provider configured, the widget shows a microphone button next to the message box. Visitors can switch between typing and speaking in the same conversation.

Choose the layout under Customize → Voice experience (ChatAI 1.4+):

ExperienceBehavior
Classic (default)Mic toggle and waveform strip — the pre-1.4 layout.
OrbCentered stage replaces the transcript and composer while Voice is active.
DockTalk beside the launcher opens a compact voice card. Opening Talk never starts the mic; Start does. Talk and text chat are mutually exclusive.
GuidedWelcome canvas with the assistant name, welcome text, and real suggested questions, then the shared stage.
CompanionAbstract character stage with the assistant name and welcome speech; mouth, eyes, and body react to live audio (reduced motion stays calm).
Side panelTall edge sheet beside the page; shared Orb stage while Voice is live. Layout only — no page scraping.

Also:

  • Answers come from the same Purpose, instructions and Knowledge as text chat; provider keys never reach the browser.
  • Voice needs HTTPS (or localhost), microphone permission and WebRTC. Otherwise the widget explains why and text chat keeps working.
  • The Voice bar / stage meta shows Not saved, Voice transcript not saved or Recording depending on privacy settings. Recording always asks Agree and start first.
  • Hide Voice on a page with data-voice="off".
  • Voice plays only speech ChatAI has approved (the playback gate). Hosted chat.js updates with the server; npm @nightzeros/chatai-widget needs 1.2.0+ for Voice and 1.4.0+ for stage experiences.

Setup, recordings, consent, usage minutes and troubleshooting: Voice (preview). npm upgrade notes: Upgrading to 1.4.

Auth model

Widget chat uses publicId in the request body and no API key. REST SDK access uses Bearer sk_ keys — see API and SDK.