Skip to main content

WebSocket API Connection

Connect directly to NextEVI’s WebSocket API for maximum control and platform flexibility. This guide covers establishing connections, authentication, and basic message handling.

Quick Start

const ws = new WebSocket(
  `wss://api.nextevi.com/ws/voice/${connectionId}?api_key=oak_your_api_key&config_id=your_config_id`
);

ws.onopen = () => {
  console.log('Connected to NextEVI');
  
  // Configure session
  ws.send(JSON.stringify({
    type: "session_settings",
    timestamp: Date.now() / 1000,
    message_id: "settings-1",
    data: {
      emotion_detection: { enabled: true },
      turn_detection: { enabled: true, silence_threshold: 0.5 },
      audio: { sample_rate: 24000, channels: 1, encoding: "linear16" }
    }
  }));
};

WebSocket URL

wss://api.nextevi.com/ws/voice/{connection_id}
connection_id
string
required
Unique connection identifier. Generate a UUID v4 for each new connection.

Authentication Methods

Connection Examples

const connectionId = 'conn-' + Math.random().toString(36).substr(2, 9);

const ws = new WebSocket(
  `wss://api.nextevi.com/ws/voice/${connectionId}?api_key=oak_your_api_key&config_id=your_config_id`
);

ws.onopen = () => {
  console.log('Connected to NextEVI');
};

ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
  console.log('Received:', message);
};

ws.onerror = (error) => {
  console.error('WebSocket error:', error);
};

ws.onclose = (event) => {
  console.log('Disconnected:', event.code, event.reason);
};

Platform-Specific Examples

const ws = new WebSocket('wss://api.nextevi.com/ws/voice/conn-123?api_key=oak_your_api_key&config_id=your_config_id');

// With reconnection library
import ReconnectingWebSocket from 'reconnecting-websocket';
const ws = new ReconnectingWebSocket('wss://api.nextevi.com/ws/voice/conn-123?api_key=oak_your_api_key&config_id=your_config_id');

Connection Flow

  1. WebSocket Handshake: Client initiates WebSocket connection
  2. Authentication: Server validates API key or JWT token
  3. Connection Metadata: Server sends connection details
  4. Session Settings: Client configures audio and feature settings
  5. Ready: Connection ready for voice communication

Next Steps

Troubleshooting

Connection Issues

  • Ensure your API key starts with oak_
  • Verify your config_id is valid
  • Check network connectivity and firewall settings

Authentication Errors

  • Double-check API key format and permissions
  • Ensure JWT token is properly formatted and not expired
  • Verify project_id matches your configuration
See Error Reference for complete error codes and solutions.