Skip to main content

WebSocket Protocol

This page documents the raw WebSocket protocol for Perf Voice Agents. Use this if you need full control over the audio pipeline or are integrating from a platform where the JavaScript SDK isn’t available.
For most web applications, the JavaScript SDK is the recommended approach — it handles all of the protocol details described here.

Connection

Endpoint

Query Parameters

Example

Protocol Flow

Important: Do not send audio until you receive the conversation_initiation_metadata message. Sending audio before initialization will cause the connection to close with code 1008.

Messages: Client → Server

Send Audio

Stream microphone audio as base64-encoded PCM16 chunks:
Audio format: PCM 16-bit signed integer, 16kHz, mono, little-endian. Base64-encode the raw bytes. Recommended chunk size: 2048 samples (128ms at 16kHz).

JavaScript Example: Capture and Send Microphone Audio

Pong (Keepalive Response)

Reply to ping messages to keep the connection alive:

Messages: Server → Client

conversation_initiation_metadata

Sent once after connection is established. Signals that the voice pipeline is ready.
Start sending audio only after receiving this message.

audio

Agent speech audio. Base64-encoded PCM16, same format as input.

JavaScript Example: Play Agent Audio

agent_response

The agent’s text response (transcript of what the agent is saying).

user_transcript

Transcript of what the user said.

interruption

Sent when the user speaks while the agent is talking. You must stop all currently playing agent audio immediately to avoid the agent’s voice overlapping with the new response.

ping

Keepalive ping. You must respond with a pong to keep the connection alive.

Complete JavaScript Example

A full working implementation using raw WebSocket (no SDK):

WebSocket Close Codes

Troubleshooting