Skip to main content
The WebSocket API is the lowest-level integration point for XUNA AI Conversational AI. Use it when you need to build integrations outside the browser — on a server, embedded hardware, or a platform not covered by the official SDKs. You send raw PCM audio and receive transcripts, agent audio, and conversation events over a persistent connection.

Connection

Connect to the WebSocket endpoint:
Public agents — append ?agent_id=YOUR_AGENT_ID to the URL:
Private agents — use a signed URL instead of the base endpoint. Generate the signed URL on your server (see Authentication) and connect to it directly:

Audio format

All audio sent to and received from the WebSocket uses the same format:

Message types — client to server

Your client sends JSON messages to control the session and stream audio.

conversation_initiation_client_data

Send this as the first message after connecting to configure the session. All fields are optional.

audio

Stream microphone audio to the server. Send chunks continuously while the user is speaking.

user_activity

Send this when you detect user activity (e.g., a keystroke or gesture) to signal that the user is present. Useful for non-audio interactions.

pong

Respond to server ping messages to keep the connection alive.

Message types — server to client

The server sends JSON messages for conversation events and agent audio.

conversation_initiation_metadata

Sent immediately after the connection is established. Contains the conversation ID and the audio format the agent will use for output.

audio

Agent speech as a base64-encoded PCM chunk. Decode and play it back in order.

agent_response

The agent’s response text. Arrives alongside or slightly before the corresponding audio chunks.

user_transcript

Transcription of the user’s speech. Use this to display what the user said in your UI.

ping

Sent by the server periodically to verify the connection is alive. Respond with a pong message using the same event_id.

interruption

Sent when the user interrupts the agent mid-response. Stop playing any buffered audio chunks when you receive this message.

Example: Node.js client

The following example shows a minimal WebSocket client that connects, sends audio from a file, and logs transcripts and agent responses.

Summary of message types

Next steps