WebSocket API Reference
Complete reference documentation for NextEVI’s real-time WebSocket API for Speech-to-Speech voice communication.Base URL
Connection
Endpoint
string
required
Unique connection identifier. Generate a UUID v4 for each new connection.
Authentication
- API Key (Query Parameter)
- JWT Token (Header)
- JWT Token (Query Parameter)
Pass your organization API key as a query parameter:
Query Parameters
string
Organization API key (starts with
oak_). Required if not using JWT authentication.string
required
Voice configuration identifier from your NextEVI dashboard.
string
Project identifier (optional, auto-detected from config if not provided)
string
JWT token as ‘Bearer token’ - alternative to Authorization header
Response
Connection establishment follows standard WebSocket handshake. Upon successful connection, server sends:- Connection Metadata - Connection details and configuration
- Ready for Messages - Client can now send session settings and audio
Connection Flow
- WebSocket Handshake: Client initiates WebSocket connection
- Authentication: Server validates API key or JWT token
- Connection Metadata: Server sends connection details
- Session Settings: Client configures audio and feature settings
- Ready: Connection ready for voice communication
Message Format
All WebSocket messages use consistent JSON structure:string
required
Message type identifier (see message types below)
number
required
Unix timestamp in seconds with millisecond precision
string
required
Unique identifier for this message (UUID recommended)
object
Message-specific data payload (varies by message type)
Client Messages
Messages sent from client to server.Session Settings
Configure audio settings and enable features for the connection.object
enabled(boolean): Enable real-time emotion detection
object
enabled(boolean): Enable intelligent turn detectionsilence_threshold(number): Silence duration to detect turn end (seconds)
object
required
sample_rate(number): Audio sample rate (24000 recommended)channels(number): Audio channels (1 for mono)encoding(string): Audio encoding format (“linear16”)
Audio Input
Send audio data for speech processing.string
required
Base64-encoded PCM audio data (16-bit, mono, 24kHz)
string
Optional identifier for audio chunk ordering
Keep Alive
Maintain connection during idle periods.Server Messages
Messages sent from server to client.Connection Metadata
Sent immediately after successful connection establishment.string
Confirmed connection identifier
string
Connection status (“connected”)
object
Audio configuration details
string
Associated project identifier
string
Voice configuration identifier
Transcription
Real-time speech-to-text results from user audio input.string
Transcribed text from speech input
number
Transcription confidence score (0-1)
boolean
Whether this transcription is final (true) or partial (false)
boolean
Whether the user has finished speaking this utterance
string
Session identifier for this connection
array
Word-level timing and confidence information
word(string): The wordstart(number): Start time in secondsend(number): End time in secondsconfidence(number): Word confidence score (0-1)
string
Complete accumulated text for this conversation turn
boolean
Whether the user’s conversation turn is still continuing
string
Original transcript fragment before accumulation
LLM Response Chunk
Streaming text responses from the language model.string
Text content chunk from language model
boolean
Whether this is the final chunk in the response
string
Unique identifier for this response generation
number
Sequential index of this chunk in the response
TTS Audio Chunk
Audio response chunks for playback to user.string
Base64-encoded audio data (WAV format) for playback
Emotion Update
Real-time emotion detection results from user speech.array
Top detected emotions with confidence scores
name(string): Emotion namescore(number): Confidence score (0-1)
object
Complete emotion analysis results with scores for all emotions
number
Time taken to process emotion detection (seconds)
number
Duration of analyzed speech segment (seconds)
string
Connection identifier
string
Session identifier
Turn Detection Events
Conversation turn management events. Turn Startstring
Unique identifier for this conversation turn
number
Duration of the turn in seconds (turn_end only)
boolean
Whether the turn was completed naturally (turn_end only)
TTS Interruption
Indicates AI speech was interrupted by user.Status Messages
System status updates and confirmations.string
Current system status
ready: System ready for voice communicationprocessing: Processing audio or generating responseerror: Error state
object
Additional status details and configuration
Error Messages
Error notifications and debugging information.string
Standardized error code (see Error Reference)
string
Human-readable error message
object
Additional error context and debugging information
Response Codes
WebSocket connections use standard HTTP status codes during handshake, then WebSocket close codes:HTTP Status Codes (Handshake)
WebSocket Close Codes
Rate Limits
Connection Limits
Audio Limits
Rate limits are enforced per API key and IP address. Exceeded limits result in HTTP 429 or WebSocket close code 4004.
Best Practices
Connection Management
- Generate unique connection IDs (UUID v4 recommended)
- Implement exponential backoff for reconnections
- Handle connection lifecycle properly (open/message/error/close)
- Use keep-alive messages for long idle periods
Audio Streaming
- Send audio in 100-200ms chunks for optimal latency
- Use 24kHz, 16-bit, mono PCM format
- Implement audio buffering on client side
- Use binary WebSocket frames for audio when possible
Error Handling
- Always handle WebSocket error and close events
- Implement retry logic with backoff for network errors
- Don’t retry authentication failures (4xxx codes)
- Log errors with sufficient context for debugging
Performance
- Minimize message payloads where possible
- Use efficient audio encoding (binary vs base64)
- Implement client-side audio processing (noise reduction)
- Monitor connection health and latency
Security
- Use secure WebSocket connections (wss://) only
- Validate all message payloads
- Implement proper authentication token refresh
- Don’t log sensitive data in error messages
Code Examples
JavaScript Connection
Python Connection
cURL Connection Test
Related Documentation
WebSocket Connection Guide
Learn how to establish connections
Message Protocol
Detailed message format guide
Authentication
Authentication methods and security
Error Reference
Complete error codes and solutions
