Skip to main content
All methods live on the Libra object exported from @libra/sdk (or window.Libra.Libra with the classic CDN script).

Libra.init(config)

Initializes the SDK and creates the iframe. Call after document.body exists. Startup is deferred until the first attach().
Call init() exactly once per page. A second call without an intervening destroy() is a no-op that logs a warning — and because the guard returns before validation, a changed productId, locale or proxy is silently ignored, with no error even for invalid values. To reconfigure, call destroy() and then init().
init() throws synchronously when:

Libra.attach(elementOrId)

Visually positions the widget over the given target element. The iframe is never moved in the DOM, only its CSS position is updated, so the chat session and any in-progress streaming response are fully preserved across re-attaches. Accepts a DOM element or a string element ID. Can be called while the iframe is still loading.
The target must stay in the DOM while the widget is visible. If a re-render removes it, the SDK detaches itself and logs Target element was removed from the DOM — widget detached. The session is preserved; call attach(newTarget) to bring it back. Hiding a conditionally-rendered container with CSS instead of unmounting it avoids this — see Panel and placement.

Libra.detach()

Hides the widget. The iframe stays alive so the session is preserved. Call attach() again to reposition it, even to a different container.

Libra.destroy()

Removes the iframe and cleans up all resources. To re-create the widget afterwards, call init() again.

Libra.setDocumentSuggestion(doc)

Suggests an external document the user is currently viewing; a chip above the message input lets the user attach it (and its attachments) to the conversation. Calling it again replaces the previous suggestion. Full behaviour, including the availability check, on Document suggestions.

Libra.clearDocumentSuggestion()

Clears the current document suggestion (e.g. when the user navigates away from the document).

Libra.openChatById(chatId)

Opens an existing Libra chat in an attached SDK session. Call it after Libra.attach(); it logs and does nothing when there is no active SDK session. See Chat handoff.

Libra.setLocale(locale)

Updates the widget’s UI language at runtime. Translated strings re-render in place, the chat session is preserved, and the locale is persisted in the iframe’s localStorage. The target locale must have been registered at init time (see Locales).

Libra.signOut()

Signs the user out and shows the login screen. In proxy mode, removes the user’s identity link on the backend (best-effort); the next re-authentication requires re-linking.

Request headers the SDK sends

In proxy mode your BFF adds X-Libra-SDK-Product-Access-Token, X-Libra-SDK-Product-ID-Token (opaque-token products only), X-Correlation-ID and Authorization; see Proxy mode.