Overview
The Websocket integration lets you drive a LemonSlice avatar from any audio stack. Send PCM audio and control events to LemonSlice over a WebSocket. Synchronized audio and video is streamed to a LiveKit or Daily room that you control.Prerequisites
- A LemonSlice account and API key associated with an active subscription. Create a key at lemonslice.com/developers.
- A reference image for your avatar. See our guide for recommendations on how to design your avatar image to achieve the best quality possible.
- A LiveKit or Daily room with separate credentials for:
- LemonSlice to join and publish audio and video.
- Your client to join and subscribe to the avatar stream.
How to use
1
Create a session
Send a request to the LemonSlice sessions endpoint with your avatar and the credentials LemonSlice should use to publish into your room.You can also provide
agent_image_base64 for a local image or agent_id to use an avatar created in the LemonSlice web app instead of agent_image_url.A successful response includes the WebSocket address:2
Open the WebSocket
Connect a standard WebSocket client to No additional authentication header is required. All messages are JSON text frames, and only one WebSocket client may be connected to a session at a time.
websocket_address:3
Stream an audio turn
Send mono PCM16 audio as base64-encoded chunks. We recommend chunks containing approximately 80–100 ms of audio. You can send them as quickly as they become available. They do not need to be paced in real time.A complete turn is
End every response with
audio_end:audio → audio → … → audio_end. The final command commits the turn so LemonSlice can finish rendering it. Without audio_end, trailing audio may be dropped and your avatar will freeze between turns.4
Subscribe to the avatar
Join the LiveKit or Daily room from your client using its viewer credentials. LemonSlice publishes the generated avatar audio and video into this room.
Handle playback completion
LemonSlice sends aplayback_finished event over the WebSocket when avatar A/V playback completes:
- After sending audio for a response, treat playback as active until you receive its
playback_finishedevent. - If the user interrupts before that event arrives, send an
interruptcommand even if your TTS provider has finished sending audio or the estimated playback duration has elapsed. - Once
playback_finishedarrives, the response is complete and aninterruptfor that response is unnecessary.
Interrupt playback
To stop the current avatar response, send aninterrupt event over the websocket and drop any queued audio chunks that had not yet been sent over the websocket:
Heartbeats
Use heartbeats to confirm that the WebSocket is responsive:heartbeat_ack, echoing event_id and timestamp when present.
End the session
When the call is complete, shut down the LemonSlice session by sending aterminate event, then close the WebSocket:

