SIP Quickstart

Configure SIP to bridge phone calls to LiveKit rooms.

caution:

SIP is currently in Developer Preview.

Pre-requisites

You'll need the following for this quickstart:

Preparing SIP server

SIP is provisioned with every LiveKit Cloud project. If you are signed in to LiveKit Cloud, your SIP server URI is:

sip:<your SIP host>

Copy this URI as it will be used to configure your SIP trunk provider.

Create a SIP Trunk

SIP Trunks are provided by a external providers such as Twilio and Telnyx. They will terminate the phone number and route calls to your SIP server.

  1. Buy a phone number. This guide will assume +1234567890.
  2. Create SIP Trunk
  3. For inbound calling, enter your SIP URI from above as your Origination SIP URI.
  4. For outbound calling, configure Termination: 4.1. Copy Termination URI, it will be used later 4.2. Configure Authentication

Connecting your SIP Trunk

LiveKit allows you to programmatically configure SIP Trunks to the SIP server. We'll go ahead and add the Trunk that you'd just created.

Add SIP Trunk

Create sipTrunk.json file:

Assuming +1234567890 phone number for inbound:

{
"outbound_address": "<my-trunk>.pstn.twilio.com",
"outbound_number": "+1234567890",
"outbound_username": "<outbound-user>",
"outbound_password": "<outbound-pass>",
"inbound_addresses": [],
"inbound_numbers_regex": [],
"inbound_username": "",
"inbound_password": ""
}
note:

Setting outbound_number parameter is required for both inbound and outbound calls.

Create SIP Trunk using livekit-cli:

export LIVEKIT_URL=<your LiveKit server URL>
export LIVEKIT_API_KEY=<your API Key>
export LIVEKIT_API_SECRET=<your API Secret>
livekit-cli create-sip-trunk --request sipTrunk.json

It will print the Trunk ID:

SIPTrunkID: <your-trunk-id>

Add SIP Dispatch Rule

Dispatch Rules are used to route inbound SIP calls into LiveKit rooms. In this guide, we'll dispatch all callers into a specific room named my-sip-room.

Create sipDispatchRule.json file:

{
"trunk_ids": ["<your-trunk-id>"],
"rule": {
"dispatchRuleDirect": {
"roomName": "my-sip-room",
"pin": ""
}
},
}

Apply the dispatch rule using livekit-cli:

export LIVEKIT_URL=<your LiveKit server URL>
export LIVEKIT_API_KEY=<your API Key>
export LIVEKIT_API_SECRET=<your API Secret>
livekit-cli create-sip-dispatch-rule --request sipDispatchRule.json

Multiple Dispatch rules can be created for the same Trunk as long as their pins are different.

Testing

Inbound calls

Assuming +1234567890 phone number was acquired, calling this number should place you into my-sip-room.

You can talk to the caller by joining the room from our example app.

Outbound calls

You may also dial phone numbers and connect them to LiveKit rooms. Let's try connecting your phone number to my-sip-room.

Create sipParticipant.json file:

{
"sipTrunkId": "<your-trunk-id>",
"sipCallTo": "<phone-number-to-dial>",
"roomName": "my-sip-room",
"participantIdentity": "Test call"
}

Then create the SIP Participant using livekit-cli:

export LIVEKIT_URL=<your LiveKit server URL>
export LIVEKIT_API_KEY=<your API Key>
export LIVEKIT_API_SECRET=<your API Secret>
livekit-cli create-sip-participant --request sipParticipant.json

It should start dialing the phone number specified by sipTrunkId. Once the user picks up, they will be connected to my-sip-room.