Connection Options: WebRTC, Telephony, and WebSockets
The Ultravox API allows you to create AI-powered voice applications that can interact through various protocols:
- WebRTC → Default protocol for browser and mobile applications.
- Regular Phone Numbers → Receive incoming or make outgoing phone calls (via Telnxy, Twilio, or Plivo).
- WebSockets → Direct server-to-server integration.
Choosing a Protocol
Choose your integration method based on your needs:
- WebRTC: Best for most integrations, especially for any client deployment (for example, browsers or mobile clients). This is the default. Get started with the Ultravox client SDK.
- Phone: For traditional phone network integration. Ultravox integrates directly with Telnyx, Twilio, and Plivo.
- WebSocket: For server-to-server integration, especially when you already have high-bandwidth connections between your server and clients.
Phone Integration
Ultravox integrates with multiple telephony providers, enabling you to create AI-powered voice applications that can interact through regular phone networks. You can build AI agents that make outgoing calls and answer incoming calls, opening up possibilities for customer service, automated outreach, and other voice-based AI applications.
Supported Providers
- Twilio → Uses Twilio Media Streams.
- Telnyx → Uses Telnyx Media Streaming.
- Plivo → Uses Plivo AudioStream.
Prerequisites
Creating a Phone Call
Creating an Ultravox call that works with phone integration is similar to creating a WebRTC call, but requires specific parameters in the Create Call command:
medium | object | Tells Ultravox which protocol to use. For phone calls, must be set to one of: {"telnyx": {}} , {"twilio": {}} , or {"plivo": {}} . Defaults to {"webRtc": {}} . |
firstSpeaker | string | Tells Ultravox who should speak first. For outgoing calls, typically set to "FIRST_SPEAKER_USER" . The default is "FIRST_SPEAKER_AGENT" . |
Example request body for an outgoing phone call:
Provider-Specific Integration
Outgoing Calls with Telnyx
-
Create an Ultravox Call → Create a new call as shown above with
medium: { "telnyx": {} }
,firstSpeaker: "FIRST_SPEAKER_USER"
, and get ajoinUrl
. -
Initiate Telnyx Phone call → Use the
joinUrl
with a TeXML<Stream>
:Or using TeXML:
Incoming Calls with Telnyx
-
Create an Ultravox Call → Create a new call with
medium: { "telnyx": {} }
andfirstSpeaker
set to “FIRST_SPEAKER_AGENT”. -
Handle Inbound Call → Use the
joinUrl
with a TeXML<Stream>
:
For more details, see the Telnyx documentation.
Outgoing Calls with Twilio
-
Create an Ultravox Call → Create a new call as shown above with
medium: { "twilio": {} }
,firstSpeaker: "FIRST_SPEAKER_USER"
, and get ajoinUrl
. -
Initiate Twilio Phone call → Use the
joinUrl
with a Twilio<Stream>
:
Incoming Calls with Twilio
-
Create an Ultravox Call → Create a new call with
medium: { "twilio": {} }
andfirstSpeaker
set to “FIRST_SPEAKER_AGENT”. -
Handle Inbound Call → Use the
joinUrl
with a Twilio<Stream>
:
For more details, see the Twilio documentation.
Outgoing Calls with Plivo
-
Create an Ultravox Call → Create a new call as shown above with
medium: { "plivo": {} }
,firstSpeaker: "FIRST_SPEAKER_USER"
, and get ajoinUrl
. -
Initiate Plivo Phone call → Use the
joinUrl
with AudioStream:The answer URL should return:
Note: For best audio quality, we recommend
audio/x-l16;rate=16000
. However, any contentType supported by Plivo will work with Ultravox.
Incoming Calls with Plivo
-
Create an Ultravox Call → Create a new call with
medium: { "plivo": {} }
andfirstSpeaker
set to “FIRST_SPEAKER_AGENT”. -
Handle Inbound Call → Use the
joinUrl
with AudioStream:
For more details, see the Plivo documentation.
WebSocket Integration
Creating a WebSocket Call
Creating a WebSocket-based call with Ultravox requires setting medium
to serverWebSocket
and passing in parameters for sample rates and buffer size.
- inputSampleRate (required): Sample rate for input (user) audio (e.g., 48000).
- outputSampleRate (optional): Sample rate for output (agent) audio (defaults to inputSampleRate).
- clientBufferSizeMs (optional): Size of the client-side audio buffer in milliseconds. Smaller buffers allow for faster interruptions but may cause audio underflow if network latency fluctuates too greatly. For the best of both worlds, set this to some large value (e.g. 30000) and implement support for PlaybackClearBuffer messages. (Defaults to 60).
Example: Creating an Ultravox Call with WebSockets
Example: Joining a Call with Websockets
See Data Messages for more information on all available messages.