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.
postMessage API. Messages are plain objects with a type field that identifies the action.
Parent → Iframe
Send messages to the agent by callingpostMessage on the iframe’s contentWindow:
Message Types
Iframe → Parent
The agent sends messages to the parent window. Listen for them withaddEventListener:
Message Types
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), andTHESYS_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, andTHESYS_IDENTITY_TOKEN_ERROR.
{ type } so non-opted-in embedders cannot read private conversation data.
Configuring the allowlist
- Open your playground in the Thesys Console.
- Click Deploy, expand the Embed on your website section.
- Under Allowed parent origins, add each origin (e.g.
https://app.example.com,http://localhost:3000) that should receive full event payloads. - Republish the playground — the new allowlist applies to all subsequent loads of the iframe.
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 sendsTHESYS_IDENTITY_TOKEN_REFRESH_NEEDED to the parent. The parent should fetch a new token from its backend and reply with THESYS_IDENTITY_TOKEN_REFRESHED: