WebSocket Message Protocol
This guide covers the complete message protocol for NextEVI’s WebSocket API, including message types, data formats, and communication patterns.Message Format
All messages use consistent JSON structure:string
required
Message type identifier
number
required
Unix timestamp in seconds with millisecond precision
string
required
Unique identifier for this message (UUID recommended)
object
Message-specific data payload
Client-to-Server Messages
Session Settings
Configure audio settings and enable features:Audio Input
Send audio data for processing:Keep Alive
Maintain connection during idle periods:Server-to-Client Messages
Connection Metadata
Sent immediately after successful connection:Transcription
Real-time speech-to-text results:LLM Response Chunk
Streaming text responses from the language model:TTS Audio Chunk
Audio response chunks for playback:Emotion Update
Real-time emotion detection results:Turn Detection Events
Conversation turn management:TTS Interruption
Indicates AI speech was interrupted:Status Messages
System status updates:Error Messages
Error notifications:Binary Audio Messages
For efficiency, audio can be sent as binary WebSocket messages instead of base64-encoded JSON. Send raw PCM audio data (16-bit, mono, 24kHz) directly as binary frames.Message Flow Examples
Basic Voice Conversation
Error Handling
Best Practices
Message IDs
- Use UUIDs for message_id fields
- Include sequence numbers for audio chunks
- Track message correlation for debugging
Error Handling
- Implement exponential backoff for reconnections
- Handle partial message scenarios
- Log all error messages for debugging
Performance
- Send audio in 100-200ms chunks for optimal latency
- Use binary messages for audio when possible
- Implement client-side audio buffering
Next Steps
Connection Examples
See complete working examples
Error Reference
Common errors and solutions
