Endpoint
WebSocket Connection
URL:
wss://api.thesavants.ai/voice-streamConnection Lifecycle
Authentication Handshake
1
Establish Connection
Open WebSocket connection to the endpoint
2
Send Token
Immediately send JWT token as first message (String)
3
Await Confirmation
Wait for
savant_voice_connected message from server4
Begin Streaming
Start sending audio data as binary messages
Connection States
| State | Description | Actions |
|---|---|---|
CONNECTING | WebSocket handshake in progress | Wait for connection |
AUTHENTICATING | JWT token sent, awaiting confirmation | Monitor for savant_voice_connected |
CONNECTED | Ready for audio streaming | Send/receive audio data |
ERROR | Connection failed or error occurred | Handle error, retry if appropriate |
CLOSED | Connection terminated | Clean up resources |
Message Protocol
Client → Server Messages
- Authentication Token
- Audio Data
Type: String
Timing: First message after connection
Format: Raw JWT token
Timing: First message after connection
Format: Raw JWT token
Server → Client Messages
- Connection Confirmed
- Error Messages
- Audio Data
Type: JSON String
Timing: After successful authentication
Timing: After successful authentication
Connection Parameters
URL Parameters
The WebSocket endpoint does not accept URL parameters.Headers
Standard WebSocket headers are used:Subprotocols
No custom subprotocols are required.Error Handling
Connection Errors
Connection Failed
Connection Failed
HTTP Status Codes:
400 Bad Request- Invalid WebSocket request401 Unauthorized- Authentication required (shouldn’t happen at connection)403 Forbidden- Access denied404 Not Found- Invalid endpoint500 Internal Server Error- Server error503 Service Unavailable- Server overloaded
- Verify endpoint URL
- Check network connectivity
- Implement exponential backoff for retries
Authentication Errors
Authentication Errors
After Connection Established:Client Actions:
- Request new JWT token
- Verify token format
- Check token expiration
Audio Format Errors
Audio Format Errors
- Verify audio configuration
- Check sample rate (16kHz)
- Ensure mono channel
- Confirm 16-bit PCM format
Implementation Examples
- JavaScript
- Flutter/Dart
Best Practices
Connection Management
Always handle connection states properly and implement reconnection logic
Error Recovery
Implement exponential backoff for reconnection attempts
Audio Buffering
Buffer audio data appropriately to handle network fluctuations
Resource Cleanup
Always clean up WebSocket connections and audio resources
Performance Considerations
- Latency: WebSocket provides low-latency communication
- Bandwidth: ~256 kbps for 16kHz 16-bit mono PCM
- Buffer Size: Recommended 20-100ms audio chunks
- Connection Pooling: Not applicable - use single connection per session