Skip to Content
Embedding

Host-page bridge

Control the embedded player from a site or kiosk with the avatarstudio v1 postMessage protocol.

Use /s/{slug} to share a standalone player with chat and microphone controls. To drive the player from a parent page, load /embed/{slug} in an iframe and pass the host page's URL-encoded origin in hostOrigin.

https://studio.example/embed/{slug}?hostOrigin=https%3A%2F%2Fkiosk.example

Add the exact origin (scheme://host[:port]) to the publication's allowed_origins. If the list is empty, Studio uses its configured origins. For local development, Studio accepts localhost, 127.0.0.1, and [::1]. The player accepts a command only when event.origin matches hostOrigin and event.source === window.parent. The host should check the Studio origin and the iframe's window before consuming an event.

Message envelope

{
  "protocol": "avatarstudio",
  "version": 1,
  "type": "host.startListening",
  "sessionId": "{slug}",
  "payload": {}
}

Include requestId with host.setPresentation and host.endVisit. Copy the request ID from each action event into its host.action-result response.

Host commands

TypePurpose
host.configureSet host and visit parameters. Repeating the configuration is safe.
host.startCompatibility command. Use host.startListening to start a voice session.
host.startListeningConnect the session if needed and enable the microphone.
host.stopListeningDisable the microphone.
host.sendTextSend a message from the guest with { "text": "..." }.
host.interruptInterrupt the character's speech.
host.resetReset the session between guests.
host.endVisitEnd a visit using schemaVersion: 1, visitId, visitGeneration, and reason.
host.setPresentationSet schemaVersion: 1, the visit ID and generation, mode (interactive or attract), and motionPreference (full or reduced).
host.setViewportSet schemaVersion: 1, layoutRevision, width, height, and safeInsets.
host.destroyEnd the session and release resources.
host.action-resultReport the outcome of a client tool.
host.contextStore context in the player. To pass context to the agent, include it in host.action-result.

See agent tools for the action request and response.

Player events

TypePayload
readycapabilities, the available features
capabilitiesChangedUpdated capabilities
stateBoolean fields connected, listening, and speaking
transcriptrole (participant or character), text, and final
actionaction, arguments, and requestId
rendererStatestatus (connecting, ready, disconnected, or error), optional reason and overlay
presentationStateCurrent presentation state, sent when it changes
visitEndedlocalClosed, backendClosed, and optional reason
errormessage and, for a rejected visit command, code

Check capabilities before sending commands that need them. Values include voice, text, transcripts, state, reset, tool-calls, visit-lifecycle, renderer-state, and presentation-v1. The player sends ready again after a reconnect, so repeat your configuration on each ready event and restore the host's controls.

Visits and reconnects

For kiosks, send visitId and visitGeneration to bind a guest to the conversation, tool outcomes, and presentation state. An old command can return stale_visit. Other visit command errors include visit_active and request_conflict.

With visit tracking, host.reset and host.endVisit clear the conversation context and keep the room and renderer connected. In a standard embed, host.reset reconnects the session.

The embedded player retries renderer connections. Use rendererState.reason to display the cause of a failure in your host UI. To use the typed wrapper, follow the Embed SDK quickstart and SDK reference.