Live Conversation WebSocket (Preview)
Live Conversation WebSocket (Preview)
The Live Conversation WebSocket provides real-time updates about an active conversation’s state. It is a server-to-client only connection — the client does not send any messages after connecting.
Endpoint
Authentication
Server-side clients can pass an API key in the
Authorization: Bearer PHONIC_API_KEY header. Browser clients should have
their backend create a short-lived session token, then pass it as a query
parameter:
Never expose a Phonic API key in browser code. Session tokens are organization-scoped and expire after their configured TTL.
Connection flow
- Connect to the WebSocket with valid credentials
- Receive a
conversation-audiomessage containing the live HLS playlist URL - Receive an initial
conversation-updatedmessage with the current conversation state - Continue receiving
conversation-updatedmessages as the conversation progresses - Receive
conversation-endedwhen the call finishes, while Phonic saves it - Receive
conversation-saved, after which the socket closes normally
Server-to-client messages
conversation-updated
Sent whenever the conversation state changes. Contains the full conversation object.
The conversation object has the same shape as the Conversation returned by the REST API, with is_live always set to true.
conversation-audio
Sent after authentication and authorization succeed. The URL is stable and contains no credentials.
Server-side clients fetch the playlist and every segment it references with
the same Authorization: Bearer ... header used for the WebSocket. Browser
clients add the same session_token query parameter to every playlist refresh
and segment request. The playlist is a growing HLS event playlist, typically a
few seconds behind the call. Caller audio is mixed into the left channel and
assistant audio into the right channel.
The playlist and segment endpoints are live-only. After conversation-saved,
use the regular Conversation API response and its final audio_url.
conversation-ended
Sent when the call has ended and Phonic has started saving it. Keep the
WebSocket open until conversation-saved so you know when the saved
conversation is available.
conversation-saved
Sent after the conversation has been stored. Phonic then closes the WebSocket
with close code 1000.
error
Sent on authentication failure, authorization failure, or other errors. The error may appear in error.message or the top-level message field.
Close codes
Example usage
Playing live audio in a browser
Browsers generally need an HLS client such as HLS.js
because a native <audio src="..."> request cannot add a session token to
playlist refreshes and segment requests.
The session token must remain valid for the WebSocket, playlist, and segment requests. For longer conversations, renew it through your backend before it expires and update the token used by your HLS request hook.
Do not embed a Phonic API key in browser code. Create the short-lived session token on a trusted backend. For an API-key integration, consume or proxy the stream from your trusted backend.
Live audio errors
Playlist and segment requests can return: