How it works
The SDK is served as JavaScript at/public/listen-sdk. When you call AnyReach.listen(...), it injects a hidden iframe into your page and brokers all audio and transcript traffic through it over postMessage. You never handle the LiveKit connection directly.
Load the script
Add the script tag to your page. Point it at your Anyreach host.AnyReach.listen on window.
Get a token
AnyReach.listen requires a url and token, which you mint from the API.
conversations:read_sensitive or conversations:manage scope. Authenticate with Authorization: Bearer <token>; user PATs (pat_) also need X-Anyreach-Org: <organization_id>.
The conversation must be in progress. If it is not active, the endpoint returns 409. If the conversation has no associated LiveKit room, it returns 404.
| Field | Type | Description |
|---|---|---|
url | string | LiveKit server URL. Pass as url. |
token | string | Subscribe-only listener JWT. Pass as token. |
room_name | string | The LiveKit room the conversation is in. |
expires_at | string (ISO 8601, UTC) | When the listener token expires. |
Start a session
Wire your event handlers first, then callconnect().
Connect
connect() returns a promise that resolves once the listener is subscribed. It rejects on error or after a 15-second timeout.Session API
AnyReach.listen({ url, token }) returns a session object with these methods.
| Method | Returns | Description |
|---|---|---|
connect() | Promise<void> | Connects the listener. Resolves when subscribed, rejects on error or after a 15-second timeout. Calling it again while connecting returns the in-flight promise. |
startAudio() | Promise<void> | Resumes audio playback. Call from a user-gesture handler to satisfy browser autoplay policy. |
mute() | void | Mutes the listener’s audio output. |
unmute() | void | Unmutes the listener’s audio output. |
isMuted() | boolean | Returns the current mute state. |
getState() | string | Returns the current connection state. |
end() | Promise<void> | Ends the session and removes the hidden iframe. Resolves once teardown completes (forced after 3 seconds). |
on(event, fn) | session | Registers an event handler. Returns the session for chaining. |
off(event, fn) | session | Removes a previously registered handler. Returns the session for chaining. |
mute() and unmute() control your local audio output only. They do not affect what the agent or caller hear.Events
Subscribe withsession.on(event, handler).
| Event | Payload | Description |
|---|---|---|
stateChange | string | Fires when the connection state changes. |
transcript | { id, role, text, final } | A transcript segment. final is false for in-progress (interim) text and true once the segment is settled. |
agentDisconnected | { participantIdentity } | The agent participant left the room. |
error | { message } | An error occurred. Also rejects an in-flight connect(). |
ended | — | The session ended and the iframe was torn down. |
getState() and the stateChange event report idle, connecting, connected, or disconnected.Full example
Next steps
Live monitoring
Listen to in-progress conversations from the Anyreach dashboard.
Agent Assist overview
See the full set of real-time assist capabilities.

