For the complete documentation index, see llms.txt. This page is also available as Markdown.

Real-time Voice (WebSocket)

WebSocket API for low-latency bidirectional voice with VAD, interruption, and streaming TTS.

Build natural, real-time voice conversations with your Amigo agents using WebSocket connections for low-latency, bidirectional audio streaming.

Real-time Capabilities This API supports sub-second latency voice conversations with automatic speech detection, interruption handling, and streaming responses.

Phone-based voice: this is WebSocket streaming for text-based apps. For enterprise phone calls, see Platform API: Voice Agent.

Quick Start

// 1. Connect to WebSocket with authentication
const ws = new WebSocket(
  'wss://api.amigo.ai/v1/your-org/conversation/converse_realtime?response_format=voice',
  ['bearer.authorization.amigo.ai.' + authToken]
);

// 2. Start a conversation when connected
ws.onopen = () => {
  ws.send(JSON.stringify({
    type: 'client.start-conversation',
    service_id: 'your-service-id',
    service_version_set_name: 'release'
  }));
};

// 3. Handle incoming messages
ws.onmessage = (event) => {
  const message = JSON.parse(event.data);
  
  if (message.type === 'server.conversation-created') {
    console.log('Ready to chat! Conversation ID:', message.conversation_id);
    // Now you can send audio or text messages
  }
  
  if (message.type === 'server.new-message' && message.message) {
    // Handle audio/text response from agent
    handleAgentResponse(message.message);
  }
};

// 4. Send a text message
ws.send(JSON.stringify({
  type: 'client.new-text-message',
  text: 'Hello, how can you help me?',
  message_type: 'user-message'
}));

What You Can Build

Use Case
Description

Voice Assistants

Natural voice conversations with automatic speech detection

Call Center Agents

Real-time customer support with interruption handling

Interactive Games

Voice-controlled gaming experiences

Healthcare Bots

Medical consultation assistants with voice interaction

Educational Tutors

Interactive learning with voice feedback

Key Features

Feature
Description

Real-time Streaming

Send and receive audio chunks as they are generated

Voice Activity Detection

Automatic detection of speech start and stop

Low Latency

Sub-second response times with streaming

Interruption Handling

Natural conversation flow management

Audio Fillers

Automatic filler phrases during processing delays

Feature
Description

PCM Voice Responses

Voice responses stream as raw 16-bit signed little-endian PCM at 16 kHz, mono

External Events

Inject context during conversations

Multi-stream Support

Handle multiple audio streams

Session Management

Continue existing conversations

Connection Setup

Endpoint

Regional Endpoints

Choose the endpoint closest to your users for best performance:

Region
Endpoint

US (default)

wss://api.amigo.ai/v1/{org}/conversation/converse_realtime

CA Central

wss://api-ca-central-1.amigo.ai/v1/{org}/conversation/converse_realtime

EU Central

wss://api-eu-central-1.amigo.ai/v1/{org}/conversation/converse_realtime

AP Southeast

wss://api-ap-southeast-2.amigo.ai/v1/{org}/conversation/converse_realtime

Query Parameters

Parameter
Type
Required
Description
Example

response_format

text | voice

Required

Agent response format

voice

current_agent_action_type

regex

Optional

Filter agent action events

^tool\..*

With response_format=voice, agent responses stream in a fixed audio format: raw 16-bit signed little-endian PCM at 16 kHz, mono. There is no client-selectable downlink encoding.

Authentication

WebSocket authentication uses the Sec-WebSocket-Protocol header with your bearer token:

Token Format The token format is bearer.authorization.amigo.ai. + your JWT token. This is passed as a WebSocket subprotocol, not a header.

Conversation Flow

Step 1: Connect & Authenticate

Step 2: Initialize Conversation

Once connected, you must initialize the conversation:

Option A: Start New Conversation

Option B: Continue Existing Conversation

Step 3: Exchange Messages

Now you can send text or audio messages and receive responses:

Sequence Diagram

Message Reference

Messages You Send (Client → Server)

Send Text

start_interaction is required on every external-event message. Messages that omit it fail validation and the connection is closed with code 1008.

Send Audio

Voice Activity Detection (VAD)

Finish Conversation

Standard Mode

VAD Mode

When in VAD mode, first disable VAD, wait for acknowledgment, then finish:

Graceful Close

Extend Timeout

Messages You Receive (Server → Client)

Conversation Lifecycle

Agent Responses

Voice Activity Detection Events

Voice Activity Detection (VAD) Mode

VAD mode enables hands-free, natural conversations with automatic speech detection.

How VAD Works

VAD with External Events

External events can interrupt ongoing conversations in VAD mode when marked with start_interaction: true:

External Event Behavior in VAD Mode:

  • When the agent hasn't detected the user speaking: an external event with start_interaction: true interrupts any existing interaction and starts a new interaction immediately with the external event.

  • When the user is speaking (agent has detected): the external event is queued. The agent waits until the user finishes speaking (indicated by server.vad-speech-ended), then triggers a new interaction with the external event.

Audio Configuration

PCM Format (Best for real-time & VAD)

MP3 Format (Bandwidth-efficient)

The MP3 variant carries only the type tag. The server decodes whatever the MP3 container declares; bit rate, sample rate, and channel count are not part of the API config.

Language Support

Voice transcription (speech-to-text) and voice synthesis (text-to-speech) support different language sets.

Voice Transcription (Speech-to-Text)

Language
Code

English

en

Spanish

es

Arabic

ar (including ar-SA and ar-EG accent variants)

If the conversation's resolved language (the user's preferred_language, falling back to the agent's default_spoken_language) is outside this set, the connection is rejected with WebSocket close code 4000 "not supported for voice transcription" when audio input or VAD mode is used.

Voice Synthesis (Text-to-Speech)

Language
Code

English

en

Spanish

es

French

fr

German

de

Italian

it

Portuguese

pt

Polish

pl

Turkish

tr

Russian

ru

Dutch

nl

Czech

cs

Arabic

ar

Chinese

zh

Japanese

ja

Hungarian

hu

Korean

ko

Hindi

hi

Language is determined by: 1) User's preferred_language setting (stored in ISO 639-3 format, for example eng), 2) Agent's default_spoken_language fallback. The codes above identify the supported languages; they are not the values of the preferred_language field.

Error Handling

WebSocket Close Codes

Code
Error
Common Cause
Solution

3000

Unauthorized

Invalid/expired token

Refresh auth token

3003

Forbidden

Missing permissions

Check user permissions

3008

Timeout

No activity for 30s

Send extend-timeout every 15s

4000

Bad Request

Invalid message format

Check message structure

4004

Not Found

Service/conversation doesn't exist

Verify IDs

4009

Conflict

Conversation locked/finished

Check conversation state

4015

Unsupported Media

Wrong audio format

Use PCM for VAD, check config

4029

Rate Limited

Too many messages

Implement backoff, max 1200/min

Error Handling Example

Performance & Limits

Rate Limits

Limit
Value
Notes

Messages/minute

1200

Includes all message types

Connection timeout

30 seconds

Reset by any message

Keep-alive interval

15 seconds

Send extend-timeout

Concurrent connections

1 per user/service

One active connection at a time

Audio chunk size

20-60ms

Optimal for real-time streaming

Max message size

1MB

For audio chunks

Keep Connection Alive

Complete Implementation

The collapsed example below is a full WebSocket client covering connection setup, keep-alive, VAD, audio capture, playback, and graceful shutdown.

Production-ready client example

Common Patterns & Troubleshooting

Connection Flow Diagram

Common Issues and Solutions

Issue
Symptom
Solution

No audio playback

Audio received but silent

Configure playback for 16 kHz, mono, 16-bit signed little-endian (s16le) PCM

Connection drops

Disconnects after 30s

Implement keep-alive with extend-timeout

VAD not working

Speech not detected

Make sure you are using PCM format, not MP3

Authentication fails

Code 3000 on connect

Check token format: bearer.authorization.amigo.ai.{token}

Conversation locked

Code 4009

Only one connection per user/service is allowed

Empty transcripts

VAD returns empty text

Check microphone permissions and audio levels

Choppy audio

Broken playback

Buffer audio chunks before playing

High latency

Slow responses

Use regional endpoints and PCM format

Best Practices

  1. Connection Management

    • Implement reconnection logic for network interruptions.

    • Send periodic extend-timeout messages during long idle periods.

    • Close connections properly with client.close-connection.

  2. Audio Streaming

    • Use PCM format for the lowest latency in VAD mode.

    • Stream audio chunks as they become available rather than buffering the whole message.

    • Include audio_config only in the first chunk.

  3. Error Recovery

    • Handle WebSocket close events gracefully.

    • Implement exponential backoff for reconnections.

    • Save the conversation ID so you can continue after disconnection.

  4. Performance

    • Reuse WebSocket connections when possible.

    • Process audio chunks immediately on receipt.

    • Use appropriate audio buffer sizes (typically 20-60ms chunks).

  5. Security

    • Never expose authentication tokens in client-side code.

    • Use secure WebSocket connections (wss://).

    • Refresh tokens before they expire.

SDK & Framework Support

Current Support

Platform
Status
Notes

JavaScript/Browser

Full support

Native WebSocket API

Node.js

Full support

Use ws package

TypeScript SDK

Not yet available

Use WebSocket API directly

Python

Supported

Use websockets library

React Native

Supported

Built-in WebSocket support

Flutter

Supported

Use web_socket_channel

Framework Examples

Node.js

Python

Last updated

Was this helpful?