Skip to main content
If you’re using the embed widget npm package, you don’t need this page — the widget handles all postMessage communication internally. This protocol is for developers who embed the agent using a direct iframe and want programmatic control.
The Thesys agent iframe communicates with the parent window using the browser’s postMessage API. Messages are plain objects with a type field that identifies the action.

Parent → Iframe

Send messages to the agent by calling postMessage on the iframe’s contentWindow:
Always use a specific targetOrigin (e.g. new URL(iframe.src).origin) instead of "*" to prevent leaking data if the iframe navigates to an unexpected URL.

Message Types


Iframe → Parent

The agent sends messages to the parent window. Listen for them with addEventListener:
Always validate event.origin against the expected iframe origin to prevent unauthorized windows from triggering actions.

Message Types

If you’re using the embed widget npm package, you can use the higher-level Events API instead of listening for raw postMessage events.

Allowed Parent Origins

For security, the agent splits its outgoing messages into two classes:
  • Protocol events — the handshake (THESYS_APP_READY), widget controls (THESYS_WIDGET_OPEN/CLOSE/TOGGLE), and THESYS_IDENTITY_TOKEN_REFRESH_NEEDED. These are required for the embed to function and are always sent to '*' with their full payload.
  • Data events — anything that carries information about the user’s conversation: THESYS_THREAD_CHANGED, THESYS_NEW_THREAD, THESYS_USER_MESSAGE_SENT, THESYS_GENERATION_STARTED, THESYS_GENERATION_ENDED, THESYS_AGENT_ERROR, THESYS_TOOL_EXECUTION_STARTED/ENDED, and THESYS_IDENTITY_TOKEN_ERROR.
Data events are only delivered with their full payload to parent origins on the playground’s Allowed Parent Origins allowlist. When the allowlist is empty, the event still fires, but the payload is stripped to just { type } so non-opted-in embedders cannot read private conversation data.

Configuring the allowlist

  1. Open your playground in the Thesys Console.
  2. Click Deploy, expand the Embed on your website section.
  3. Under Allowed parent origins, add each origin (e.g. https://app.example.com, http://localhost:3000) that should receive full event payloads.
  4. Republish the playground — the new allowlist applies to all subsequent loads of the iframe.
Origins must be exact scheme://host[:port] matches. No paths, no trailing slashes, no wildcards.

Identity Token Refresh

When a BYOI identity token expires during an active session, the agent sends THESYS_IDENTITY_TOKEN_REFRESH_NEEDED to the parent. The parent should fetch a new token from its backend and reply with THESYS_IDENTITY_TOKEN_REFRESHED:
If the parent doesn’t respond within 10 seconds, the agent shows an error modal to the user.

URL Parameters

When embedding via a direct iframe, you can configure the agent through URL query parameters: