WebSocket Transport
Vapi’s WebSocket transport enables real-time, bidirectional audio communication directly between your application and Vapi’s AI assistants. Unlike traditional phone or web calls, this transport method lets you stream raw audio data instantly with minimal latency.
Key Benefits
- Low Latency: Direct streaming ensures minimal delays.
- Bidirectional Streaming: Real-time audio flow in both directions.
- Easy Integration: Compatible with any environment supporting WebSockets.
- Flexible Audio Formats: Customize audio parameters such as sample rate.
- Automatic Sample Rate Conversion: Seamlessly handles various audio rates.
Creating a WebSocket Call
To initiate a call using WebSocket transport:
Sample API Response
Audio Format Configuration
When creating a WebSocket call, the audio format can be customized:
Currently, Vapi supports only raw PCM (pcm_s16le
with raw
container). Additional formats may be supported in future updates.
Vapi automatically converts sample rates as needed. You can stream audio at 8kHz, 44.1kHz, etc., and Vapi will handle conversions seamlessly.
Connecting to the WebSocket
Use the WebSocket URL from the response to establish a connection:
Sending and Receiving Data
The WebSocket supports two types of messages:
- Binary audio data (PCM, 16-bit signed little-endian)
- Text-based JSON control messages
Sending Audio Data
Receiving Data
Sending Control Messages
Ending the Call
To gracefully end the WebSocket call:
Comparison: WebSocket Transport vs. Call Listen Feature
Vapi provides two WebSocket options:
Refer to Live Call Control for more on the Call Listen feature.
When using WebSocket transport, phone-based parameters (phoneNumber
or phoneNumberId
) are not permitted. These methods are mutually exclusive.