Free How much of your firm runs on you? Take the 2-minute Key Man Score.
Lesson reading
0%

Lesson 7 / Unit 2: Self-Hosted Stack

SIP Integration

Port 5060, a configured RTP range and two API objects sit between your carrier and your agent. The config, the firewall rules, and a first-call checklist in failure order.

Your agent answers in the browser. Now it has to answer a phone.

Between the carrier and the room sits one more binary: the LiveKit SIP service, listening on port 5060 with its own 10,000-port RTP range. It deploys separately from the SFU, and it inherits every sharp edge of telephony.

SIP Bridge

The SIP service turns rooms into phone calls. It answers SIP from your carrier, negotiates codecs, and joins the caller into a room as a participant, where your agent is waiting.

It talks to LiveKit server over Redis, which is also where it keeps SIP session state, and it needs a public IP address of its own so the carrier can reach it. If you followed the multi-node lesson, that Redis is already running.

Service Configuration

The split matters. The service’s config.yaml holds infrastructure: addresses, ports, Redis. Trunks and dispatch rules are API objects stored by LiveKit server, so you create them with the lk CLI or a server SDK.

The service config

This is the essential config from LiveKit’s SIP server self-hosting guide, with the defaults written out:

# config.yaml for livekit-sip
api_key: <your-api-key>
api_secret: <your-api-secret>
ws_url: wss://livekit.example.com
redis:
# must be the same Redis address your LiveKit nodes use
address: redis.internal:6379
sip_port: 5060
rtp_port: 10000-20000
# discover and advertise the public IP in SDP
use_external_ip: true
logging:
level: info

Run it natively with livekit-sip --config=config.yaml, or in Docker. The container needs host networking, because publishing thousands of individual UDP ports adds avoidable container-networking complexity:

docker run --rm \
-e SIP_CONFIG_BODY="$(cat config.yaml)" \
--network host \
livekit/sip

The inbound trunk and the dispatch rule

An inbound trunk says which calls you accept, and a dispatch rule says which room an accepted call lands in and which agent gets dispatched.

{
"trunk": {
"name": "carrier-main",
"numbers": ["+15105550100"],
"allowed_addresses": ["203.0.113.0/24"]
}
}
{
"dispatch_rule": {
"rule": { "dispatchRuleIndividual": { "roomPrefix": "call-" } },
"name": "inbound-to-agent",
"trunk_ids": ["ST_REPLACE_WITH_CREATED_TRUNK_ID"],
"roomConfig": { "agents": [{ "agentName": "inbound-agent" }] }
}
}
lk sip inbound create inbound-trunk.json
lk sip dispatch create dispatch-rule.json

Replace the example CIDR with your carrier’s signalling addresses (an empty allowed_addresses list accepts traffic from anywhere), or set auth_username and auth_password on the trunk instead, whichever your provider supports. The individual rule gives every caller a fresh room. Its agentName must match the name your agent registers with.

SIP Ports

Two groups: SIP signalling and the service’s own RTP range. The SIP service’s media ports are separate from the SFU’s range, and they follow the same rule as lesson 5: the firewall must cover the configured range.

PortProtocolConfig keyOpened to
5060UDP, TCPsip_portYour carrier’s SIP addresses
10000-20000UDPrtp_portYour carrier’s media sources
50000-60000UDPSFU rtc.*Already open from lesson 5

The last row is the SFU’s range, listed so you don’t merge the two: they belong to different processes, and often to different machines.

On the carrier side, the SIP service’s public address is your trunk provider’s origination target. Your firewall must admit the carrier’s addresses inbound for both signalling and media, so take both lists from your provider’s documentation. Authentication is IP allowlisting or SIP credentials, depending on the provider.

First Call

Work down this list in order. Each step only matters once the one above it passes.

  1. The carrier reaches the service. SIP arrives on 5060. Check with a packet capture on the SIP host (tcpdump -n -i any port 5060) while you dial.
  2. The trunk matches. The dialled number is in an inbound trunk’s numbers, and the source address or credentials pass.
  3. Dispatch fires. A rule creates the room and requests the agent. If the call rings and nobody answers, compare the rule’s agentName with your agent’s.
  4. Media flows both ways. This is the step that fails with no error at all, and it gets the whole next lesson.

The first call in the order failures occur: INVITE, trunk match, dispatch, agent join, then media in both directions.

Open full size

If you need to read the INVITE itself, RFC 3261 is the reference for every header you’ll see in the capture.

Service Isolation

For independently scaled production tiers, deploy SIP separately from the SFU. It has a different scaling profile, different port needs and a different restart cadence, and when you read a packet capture you want one service’s traffic on the wire, with nothing interleaved.

How that instance scales once call volume grows is its own problem, covered in scaling inbound SIP.

Try it

Keep one test trunk with a real phone number pointed at every environment, including staging. The number of telephony defects that only reproduce with a real carrier, real NAT and a real handset is high enough that calling it from your phone is a legitimate test method, and the cheapest one you will ever run.

Common questions

What ports does the self-hosted LiveKit SIP service need open?

SIP signalling on 5060 (UDP and TCP) and the RTP media range, 10000-20000 UDP by default, set by rtp_port in the SIP config. That range is separate from the SFU's RTP range, and the firewall rule must cover the configured range.

What is the difference between a LiveKit inbound trunk and a dispatch rule?

An inbound trunk decides which calls you accept: the numbers dialled and, optionally, the carrier addresses or credentials allowed. A dispatch rule decides where an accepted call goes: which room it lands in and which agent is dispatched to that room.

Does the LiveKit SIP service need Redis?

Yes. The SIP service and LiveKit server communicate over Redis, so the SIP config must point at the same Redis address as every LiveKit node.

We do this work for teams shipping voice agents: Self-Hosted Voice Agent .

Edit this lesson on GitHub ↗

Discussion

Questions, corrections and war stories welcome. Sign in with GitHub to comment.

Free guide

Be The 10x Entrepreneur

Get the firm out of your head.

  • 8 chapters
  • 7 worksheets
  • 30 day plan