To accept calls, see the Accepting incoming calls quickstart.
Prerequisites
The following are required to complete the steps in this guide:
- Phone number purchased from a SIP trunk provider like Twilio or Telnyx.
- SIP trunk configured as an outbound trunk for use with LiveKit SIP.
- LiveKit Cloud project or a self-hosted instance of LiveKit server
- SIP server (only required if you're self hosting the LiveKit server).
- LiveKit CLI installed.
For step-by-step instructions to set up a SIP trunk with Twilio or Telnyx, see Create and configure SIP trunk.
For instructions for self hosting, see Self-hosted SIP server.
Required data for creating LiveKit trunks
Copy the following data for use in the steps in this guide:
- The phone number you purchased.
- The domain name of your SIP trunk.
- Username and password configured for your outbound SIP trunk.
Step 1: Set up environment variables
Log in to see your real credentials populated in many places throughout this page
Set up the following environment variables to configure the LiveKit CLI to use your LiveKit Cloud or self-hosted LiveKit server instance:
export LIVEKIT_URL=<your LiveKit server URL>export LIVEKIT_API_KEY=<your API Key>export LIVEKIT_API_SECRET=<your API Secret>
Step 2: Create an outbound trunk
To make outgoing calls, the provider's outbound trunk needs to be registered with LiveKit. SIP trunking providers typically require authentication when accepting outbound SIP requests to ensure only authorized users are making calls with your number.
Create a file named
outbound-trunk.json
using your phone number, trunk domain name, andusername
andpassword
:{"trunk": {"name": "My outbound trunk","address": "<my-trunk>.pstn.twilio.com","numbers": ["+15105550100"],"auth_username": "<username>","auth_password": "<password>"}}Create the outbound trunk using the CLI:
lk sip outbound create outbound-trunk.jsonThe output of the command returns the trunk ID. Copy it for the next step:
SIPTrunkID: <your-trunk-id>
Step 3: Create a participant to make an outgoing call
Create a
sip-participant.json
file with the following participant details:{"sip_trunk_id": "<your-trunk-id>","sip_call_to": "<phone-number-to-dial>","room_name": "my-sip-room","participant_identity": "sip-test","participant_name": "Test Caller"}Create the SIP Participant using the CLI. After you run this command, the participant makes a call to the
sip_call_to
number configured in your outbound trunk. You can monitor the call status using the SIP participant attributes. When the call is picked up by the callee, thesip.callStatus
attribute isactive
.lk sip participant create sip-participant.json
Once the user picks up, they will be connected to my-sip-room
.
You can talk to the callee at the dialed phone number by joining the room from the meet example frontend using your LikeKit server URL and an access token.
lk token create \--api-key <your API Key> \--api-secret <your API Secret> \--join --room my-sip-room \--identity guest-user \--valid-for 24h
Next steps
This guide uses the LiveKit CLI to create the trunk and participant. For additional examples using the SIP API, see the following topics: