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 theconversation_initiation_metadatamessage. Sending audio before initialization will cause the connection to close with code1008.
Messages: Client → Server
Send Audio
Stream microphone audio as base64-encoded PCM16 chunks:JavaScript Example: Capture and Send Microphone Audio
Pong (Keepalive Response)
Reply toping 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
Related
- Voice Agents Overview — Architecture and features
- JavaScript SDK — Recommended for web apps
- Python Integration — Server-side integration