Skip to main content
Asterisk is the world’s most popular open-source telephony platform. Rapida integrates with Asterisk using two transport methods — AudioSocket (native TCP protocol) and WebSocket (chan_websocket) — enabling real-time bidirectional audio streaming for AI-powered voice conversations.
Both transports follow the same two-phase flow: an HTTP webhook registers the call, then a media connection (TCP or WebSocket) carries the audio. Choose the transport that fits your Asterisk version and network topology.

Transport Comparison


Architecture Overview

Both transports share the same backend pipeline. The only difference is the Streamer layer that bridges the media connection to the AI pipeline.

Two-Phase Call Setup

Every Asterisk call (inbound or outbound, AudioSocket or WebSocket) follows this pattern:
  1. Phase 1 — Webhook: An HTTP request registers the call and gets a contextId
  2. Phase 2 — Media: A transport connection (TCP or WebSocket) streams audio using that contextId
This design decouples call setup from media transport, allowing the same webhook to serve both AudioSocket and WebSocket.

Prerequisites

Asterisk Server

Asterisk 16+ (AudioSocket) or 20+ (WebSocket) with the required module loaded

Rapida Account

Active Rapida account with an API key (rpd-xxx)

Voice Assistant

A configured Rapida voice assistant with phone deployment enabled

Network Access

TCP 4573 (AudioSocket) or HTTPS 443 (WebSocket) to Rapida
For outbound calls, you also need Asterisk ARI enabled with credentials stored in a Rapida vault credential.

Quick Start — Inbound Calls

Choose your transport and follow the matching setup:

1. Verify Module

If not loaded:

2. Configure Dialplan

3. Reload


Inbound Call Flow — Detailed

Sequence Diagram

What Happens at Each Step


Outbound Call Flow — Detailed

Outbound calls are initiated via the Rapida SDK (gRPC CreatePhoneCall RPC) or REST API. Rapida uses Asterisk’s ARI (Asterisk REST Interface) to originate the call.

Prerequisites for Outbound

1

Enable ARI on Asterisk

Reload:
2

Create Vault Credential in Rapida

In the Rapida dashboard, go to Credentials → Create Credential and select Asterisk. Provide:
3

Configure Outbound Dialplan

ARI can originate calls in two modes. Choose one:
4

Assign Credential to Phone Deployment

In the assistant’s Phone Deployment, select the Asterisk vault credential and configure:

Outbound Sequence Diagram

SDK Code Examples (Outbound)


AudioSocket Protocol Reference

Frame Format

Each frame has a 3-byte header followed by a variable-length payload:

Frame Types

Audio Format

Rapida handles all resampling and codec conversion transparently.

Status Callbacks

Rapida sends status updates to Asterisk via ARI events. You can also configure a webhook on the assistant to receive call lifecycle events.

Event Callback URL

This endpoint is automatically configured during outbound call setup. For inbound calls, Asterisk can optionally POST events to this URL.

Event Types


Credential Configuration

Vault Credential Fields

When creating an Asterisk credential in the Rapida vault, provide:
Vault credentials are encrypted at rest. The ARI password is never exposed in API responses or logs.

Phone Deployment Options

These options are configured on the assistant’s phone deployment:

Full Configuration Examples

Example 1: Inbound Only (AudioSocket)

Simplest setup — no ARI needed, no vault credential required for inbound-only.

Example 2: Inbound Only (WebSocket)

No firewall port needed beyond HTTPS — ideal for cloud-hosted Asterisk.

Example 3: Inbound + Outbound (Full Setup)

Complete setup with ARI for outbound calls and AudioSocket for media.

Example 4: WebSocket-Only (Inbound + Outbound)

Zero custom ports — everything runs over HTTPS.

Call Lifecycle

State Machine

Captured Metrics

Each call automatically records:

Troubleshooting

Symptoms: AudioSocket() returns immediately, no audioChecklist:
  • Verify Rapida host is reachable: nc -zv socket-01.in.rapida.ai 4573
  • Check firewall allows TCP 4573 outbound
  • Ensure res_audiosocket.so is loaded
  • Verify the contextId (token) is non-empty in the dialplan
Symptoms: WebSocket() fails, no audioChecklist:
  • Verify WSS URL is correct: wss://websocket-01.in.rapida.ai/v1/talk/asterisk/ctx/{contextId}?x-api-key={your-api-key}
  • Ensure chan_websocket.so is loaded
  • Check TLS certificate trust on the Asterisk server
  • Verify Asterisk version is 20+ for chan_websocket
Symptoms: Transport connects but immediately drops with “call context not found”Checklist:
  • Context ID expires after 5 minutes — ensure fast connection after webhook
  • Each contextId is single-use (atomically deleted on first connection)
  • Don’t reuse contextIds across calls
  • Verify the webhook returned a valid contextId (not an error message)
Symptoms: AI speaks but doesn’t hear, or vice versaChecklist:
  • Set CHANNEL(audioreadformat)=slin and CHANNEL(audiowriteformat)=slin
  • Verify res_audiosocket module is loaded
  • Check Asterisk timing: asterisk -rx "timing test"
Symptoms: Audio artifacts, long pausesChecklist:
  • Check network latency to Rapida: ping websocket-01.in.rapida.ai (target < 100ms)
  • Verify no packet loss on the path
  • For WebSocket: ensure no proxy is buffering WebSocket frames
  • Reduce network hops if possible
Symptoms: SDK call returns error, no ring on customer phoneChecklist:
  • Verify ARI is enabled: asterisk -rx "http show status"
  • Check ARI credentials in vault: ari_url, ari_user, ari_password
  • Verify endpoint format: PJSIP/trunk/number or PJSIP/number
  • Check ARI URL is reachable from Rapida: must not be behind NAT without port forwarding
  • Review Asterisk CLI: asterisk -rvvv for ARI request logs
Symptoms: Outbound call connects but AudioSocket/WebSocket has no contextChecklist:
  • Verify ARI channel variables are configured: {"variables": {"RAPIDA_CONTEXT_ID": "..."}}
  • Check the dialplan references ${RAPIDA_CONTEXT_ID} (exact case)
  • Verify deployment options include context and extension

Debug Commands


High Availability

Multi-Node Deployment

Dialplan with failover (AudioSocket):

API Reference

Inbound Webhook

Response: Plain text contextId (UUID)

WebSocket Media Endpoint

Status Callback

Receives ARI-style JSON events with a type field.

Voice Deployment Options

Overview of all voice deployment channels

Create an Assistant

Build your voice AI assistant

Webhooks

Configure event notifications

API Reference

Call API documentation