Complete reference for the rtpengine-compatible NG (Next Generation) protocol implemented by Karl.
The NG protocol is a UDP-based protocol using bencode encoding for communication between SIP proxies and media servers.
- Default Port: UDP 22222
- Encoding: Bencode
- Request/Response: Synchronous
SIP Proxy Karl
│ │
│ ping │
│─────────────────────────►│
│ │
│ pong │
│◄─────────────────────────│
│ │
<cookie> <bencoded-dictionary>
- cookie: Unique identifier to match responses (string)
- bencoded-dictionary: Command and parameters
abc123 d7:command5:offer7:call-id10:call-567898:from-tag9:tag-12345 3:sdp...e
| Type | Format | Example |
|---|---|---|
| String | <length>:<data> |
4:ping |
| Integer | i<number>e |
i42e |
| List | l<items>e |
l4:spam4:eggse |
| Dictionary | d<key><value>...e |
d3:cow3:mooe |
Health check command.
Request:
d7:command4:pinge
Response:
d6:result4:ponge
Use: Keepalive, health monitoring
Process SDP offer for new or existing call.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | offer |
call-id |
string | Unique call identifier |
from-tag |
string | SIP From-tag |
sdp |
string | SDP offer body |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
to-tag |
string | SIP To-tag (for re-INVITE) |
flags |
list | Processing flags |
replace |
list | SDP elements to replace |
direction |
list | Interface selection hints (see Direction-Based Interface Selection) |
ICE |
string | ICE handling mode |
DTLS |
string | DTLS handling mode |
SDES |
string | SDES handling mode |
transport-protocol |
string | Force transport protocol |
media-address |
string | Override media address |
Example Request:
d7:command5:offer7:call-id10:call-567898:from-tag9:tag-123453:sdpX:v=0...e
Response:
d6:result2:ok3:sdpX:v=0...e
Process SDP answer for existing call.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | answer |
call-id |
string | Call identifier |
from-tag |
string | SIP From-tag |
to-tag |
string | SIP To-tag |
sdp |
string | SDP answer body |
Optional Parameters:
Same as offer.
Example Request:
d7:command6:answer7:call-id10:call-567898:from-tag9:tag-123456:to-tag9:tag-678903:sdpX:v=0...e
Response:
d6:result2:ok3:sdpX:v=0...e
Terminate call and release resources.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | delete |
call-id |
string | Call identifier |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
from-tag |
string | Delete specific leg |
to-tag |
string | Delete specific leg |
flags |
list | Processing flags |
Example Request:
d7:command6:delete7:call-id10:call-56789e
Response:
d6:result2:oke
Get real-time statistics for a call.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | query |
call-id |
string | Call identifier |
Response Fields:
| Field | Type | Description |
|---|---|---|
result |
string | ok or error |
totals |
dict | Aggregate statistics |
tags |
dict | Per-tag statistics |
created |
int | Creation timestamp |
last-signal |
int | Last signaling timestamp |
Example Response:
d6:result2:ok6:totalsd12:packets-sent i1000e16:packets-receivedi950e...ee
List all active calls.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | list |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
limit |
int | Max results |
Response:
d6:result2:ok5:callsl d7:call-id10:call-12345 8:from-tag9:tag-11111 6:to-tag9:tag-22222 5:state6:active e ...ee
Begin call recording.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | start recording |
call-id |
string | Call identifier |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
from-tag |
string | Record specific leg |
to-tag |
string | Record specific leg |
Response:
d6:result2:oke
End call recording.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | stop recording |
call-id |
string | Call identifier |
Inspect a SIPREC (RFC 7865/7866) recording session for a call.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | siprec |
call-id |
string | Call identifier |
Response (when a SIPREC session exists):
| Field | Type | Description |
|---|---|---|
siprec-session-id |
string | SIPREC session ID |
call-id |
string | Call identifier |
status |
string | initial, active, paused, complete or failed |
start-time |
int | Unix timestamp of recording start |
metadata-xml |
string | RFC 7865 recording metadata XML |
Example:
d6:result2:ok14:siprec-session-id... 8:metadata-xml...eee
SIPREC sessions are started by the start recording command when the call was flagged with SIPREC (or siprec) in the offer/answer flags. Metadata collected from the call (siprec- prefixed metadata and session SIPREC metadata) is included in the session and is returned in the metadata XML.
Request a forked media subscription to one or more call participants (used by SIPREC / SRS forking media to an external recording server).
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | subscribe request |
call-id |
string | Call identifier |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
from-tag |
string | Select source participant (single) |
from-tags |
list | Select source participants (multiple) |
all |
flag | Select every participant |
to-tag |
string | Tag for the new subscription (generated if absent) |
set-label |
string | Label for the subscription |
Response: ok + sdp (sendonly offer SDP advertising the subscription),
to-tag (the subscription's tag) and from-tags (the selected source legs' tags).
Re-requesting an existing to-tag first removes the existing subscription.
Answer a subscribe request. Media from the selected source legs starts
flowing to the endpoint given in this answer's SDP.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | subscribe answer |
call-id |
string | Call identifier |
to-tag |
string | Subscription tag (from the subscribe request reply) |
sdp |
string | Answer SDP (the sink endpoint) |
Response: ok or error.
Stop an established subscription.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | unsubscribe |
call-id |
string | Call identifier |
to-tag |
string | Subscription tag |
Response: ok or error.
Mute media in one or both directions.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | block media |
call-id |
string | Call identifier |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
from-tag |
string | Specific leg |
direction |
list | from-tag, to-tag, or both |
Unmute media.
Parameters: Same as block media.
Inject DTMF tones.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | play DTMF |
call-id |
string | Call identifier |
dtmf |
string | DTMF digits (0-9, *, #) |
Optional Parameters:
| Parameter | Type | Description |
|---|---|---|
from-tag |
string | Inject toward this leg |
duration |
int | Tone duration (ms) |
pause |
int | Inter-digit pause (ms) |
Get server-wide statistics.
Required Parameters:
| Parameter | Type | Description |
|---|---|---|
command |
string | statistics |
Response Fields:
| Field | Description |
|---|---|
currentstatistics |
Current counters |
totalstatistics |
Lifetime counters |
sessions |
Active session count |
uptime |
Server uptime (seconds) |
The direction parameter is a list of two strings that tells Karl which named network interface to use for each call leg. This is how SIP proxies like OpenSIPS and Kamailio select between internal and external media addresses.
"direction": ["<from-interface>", "<to-interface>"]
direction[0]— the interface name for the originating side (used duringoffer)direction[1]— the interface name for the terminating side (used duringanswer)
d7:command5:offer ... 9:directionl8:internal8:externale ... e
This tells Karl: "the caller is on the internal network, the callee is on the external network." Karl will:
- Bind media sockets on the interface's
address(the local/private IP) - Advertise the interface's
advertise_addrin the SDPc=line (e.g., the public Elastic IP forexternal)
When selecting an interface, Karl checks in this order:
- Explicit
interfaceorfrom-interface/to-interfaceflag directionarray (as described above)- Peer address auto-detection (private →
internal, public →external) - Default interface from config (
media_ip/public_ip)
# Internal PBX calling an external carrier
rtpengine_manage("RTP/AVP replace-origin replace-session-connection direction=internal direction=external");
# Internal PBX calling an external carrier
rtpengine_manage("RTP/AVP replace-origin replace-session-connection direction=internal direction=external");
See Configuration Reference — Named Interfaces for how to define interfaces.
| Flag | Description |
|---|---|
RTP/AVP |
Plain RTP (Audio/Video Profile) |
RTP/AVPF |
RTP with feedback |
RTP/SAVP |
SRTP (Secure AVP) |
RTP/SAVPF |
SRTP with feedback |
UDP/TLS/RTP/SAVP |
DTLS-SRTP |
UDP/TLS/RTP/SAVPF |
DTLS-SRTP with feedback |
| Flag | Description |
|---|---|
replace-origin |
Replace SDP origin line |
replace-session-connection |
Replace session-level connection |
trust-address |
Trust SDP addresses |
SIP-source-address |
Use SIP source as media address |
symmetric |
Force symmetric RTP |
asymmetric |
Allow asymmetric RTP |
| Flag | Description |
|---|---|
ICE=remove |
Remove all ICE attributes |
ICE=force |
Force ICE negotiation |
ICE=force-relay |
Force TURN relay |
| Flag | Description |
|---|---|
DTLS=off |
Disable DTLS |
DTLS=passive |
DTLS passive role |
DTLS=active |
DTLS active role |
| Flag | Description |
|---|---|
SDES-off |
Disable SDES |
SDES-on |
Enable SDES |
SDES-unencrypted_srtp |
Allow unencrypted SRTP |
SDES-unencrypted_srtcp |
Allow unencrypted SRTCP |
| Flag | Description |
|---|---|
codec-strip-all |
Remove all codecs |
codec-offer-XXXX |
Add codec XXXX to offer |
codec-mask-XXXX |
Remove codec XXXX |
transcode-XXXX |
Transcode to codec XXXX |
| Flag | Description |
|---|---|
record-call |
Enable call recording |
| Flag | Description |
|---|---|
direction=X |
Interface selection hint (provide twice: from, to). See Direction-Based Interface Selection |
interface=X |
Explicit interface name for this leg |
in-iface=X / from-interface=X |
Interface for the originating (offer) side |
out-iface=X / to-interface=X |
Interface for the terminating (answer) side |
media-address=X |
Override the media IP entirely (bypasses interface selection) |
| Flag | Description |
|---|---|
media-timeout=N |
Media timeout in seconds |
receive-only |
Receive-only mode |
send-only |
Send-only mode |
d6:result2:ok...e
d6:result5:error12:error-reason18:Invalid parameterse
| Error | Description |
|---|---|
Unknown call-id |
Session not found |
Invalid SDP |
Malformed SDP |
Port allocation failed |
No available ports |
Codec negotiation failed |
No common codecs |
Session limit reached |
Max sessions exceeded |
If no response within timeout:
- Retry the request (up to configured retries)
- Mark instance as failed
- Failover to backup instance
Invalid bencode results in:
d6:result5:error12:error-reason14:Parse error: ...e
Attempting operations on invalid session state:
d6:result5:error12:error-reason20:Invalid session statee
# Ping test
echo -n "test123 d7:command4:pinge" | nc -u localhost 22222
# Expected response contains "pong"# In SIP proxy config, enable debug logging for rtpengine module
# Then make a test call and check logs