init() & destroy()

Initialize Inline AI in programmatic mode with your publisher ID, and tear it down cleanly with destroy() when you need to reinitialize or navigate away.

Call init() to activate programmatic mode: the SDK skips auto-rendering and waits for you to mount() placements explicitly. After a successful call, the SDK emits the ready event and is ready to accept mount() calls. You can tear down the entire SDK at any time with destroy(), which unmounts all placements and resets state so you can call init() again if needed.

Enum constants like window.InlineAI.Placement and window.InlineAI.Events are available on window.InlineAI before init() is called. You can reference them safely in the command queue or in any setup code that runs before the SDK loads.

init(config)

init(config: SDKConfig): void

Initializes the SDK in programmatic mode. The SDK creates an API client, loads your publisher configuration, and emits 'ready' when setup is complete.

If init() is called when the SDK is already initialized, it logs a warning and returns without doing anything. Call destroy() first if you need to reinitialize with a different configuration.

If auto mode has already initialized the widget (for example, because your script tag loaded before the init() call was processed), init() attaches the SDK in hybrid mode instead of creating a duplicate registry. You will still receive the 'ready' event.

Parameters

configSDKConfigRequired

Configuration object for the SDK.

Error behavior

init() never throws to your code. All internal errors are caught, logged to the console, and execution stops gracefully. Check the browser console for [SDK]-prefixed messages if initialization does not behave as expected.

Examples

window.InlineAI.init({ publisherId: 'YOUR_PUBLISHER_ID' });
 
window.InlineAI.on('ready', function() {
  window.InlineAI.mount(window.InlineAI.Placement.SearchEmbed, 'header-search');
  window.InlineAI.mount(window.InlineAI.Placement.Widget);
});

destroy()

destroy(): void

Tears down the SDK: unmounts all SDK-controlled placements, removes internal event listeners, and resets the initialized state. After calling destroy(), you can call init() again to start fresh.

In hybrid mode (where auto mode initialized the widget), destroy() only removes placements and listeners that were added through the SDK API. It does not tear down the shared auto-mode registry or affect placements rendered automatically by the widget.

When to use destroy()

  • Single-page applications: call destroy() when navigating to a new route, then init() again with updated configuration.
  • Reinitializing with different options: you cannot call init() twice in a row; call destroy() first.
  • Cleanup on page unload: remove all Inline AI UI before the page tears down.

Example

// Initialize and mount
window.InlineAI.init({ publisherId: 'YOUR_PUBLISHER_ID' });
window.InlineAI.on('ready', function() {
  window.InlineAI.mount(window.InlineAI.Placement.SearchEmbed, 'search-box');
});
 
// Later: tear down and reinitialize
window.InlineAI.destroy();
 
window.InlineAI.init({ publisherId: 'YOUR_PUBLISHER_ID' });
window.InlineAI.on('ready', function() {
  window.InlineAI.mount(window.InlineAI.Placement.BasicEmbed, 'new-container');
});
© 2026 Inline AI