Create and configure a Twilio SIP trunk

Step-by-step instructions for creating inbound and outbound SIP trunks using Twilio.

Note

If you're using LiveKit Cloud as your SIP server and you're signed in, your SIP URI is automatically included in the code blocks where appropriate.

Use the following steps to configure inbound and outbound SIP trunks using Twilio.

Creating a SIP trunk for inbound and outbound calls

Create a Twilio SIP trunk for incoming or outgoing calls, or both, using the following steps. To use the Twilio console, see Configure a SIP trunk using the Twilio UI.

Note

For inbound calls, you can use TwiML for Programmable Voice instead of setting up Elastic SIP Trunking. To learn more, see Inbound calls with Twilio Voice.

Prerequisites

Step 1. Create a SIP trunk

The domain name for your SIP trunk must end in pstn.twilio.com. For example to create a trunk named My test trunk with the domain name my-test-trunk.pstn.twilio.com, run the following command:

twilio api trunking v1 trunks create \
--friendly-name "My test trunk" \
--domain-name "my-test-trunk.pstn.twilio.com"

The output includes the trunk SID. Copy it for use in the following steps.

Step 2: Configure your trunk

Configure the trunk for inbound calls or outbound calls or both. To create a SIP trunk for both inbound and outbound calls, follow the steps in both tabs:

For inbound trunks, configure an origination URI. If you're using LiveKit Cloud and are signed in, your <your SIP host> is filled in below:

twilio api trunking v1 trunks origination-urls create \
--trunk-sid <twilio_trunk_sid> \
--friendly-name "LiveKit SIP URI" \
--sip-url "sip:<your SIP host>;transport=tcp" \
--weight 1 --priority 1 --enabled

Step 3: Associate phone number and trunk

The Twilio trunk SID and phone number SID are included in the output of previous steps. If you didn't copy the SIDs, you can list them using the following commands:

  • To list phone numbers: twilio phone-numbers list
  • To list trunks: twilio api trunking v1 trunks list
twilio api trunking v1 trunks phone-numbers create \
--trunk-sid <twilio_trunk_sid> \
--phone-number-sid <twilio_phone_number_sid>

Configure a SIP trunk using the Twilio UI

  1. Sign in to the Twilio console.

  2. Purchase a phone number.

  3. Create SIP Trunk on Twilio:

    • Select Elastic SIP Trunking » Manage » Trunks.
    • Create a SIP trunk.
    Tip

    Using your Twilio API key, you can skip the next two steps by using this snippet to set your origination and termination URLs automatically.

  4. For inbound calls:

    • Navigate to Voice » Manage » Origination connection policy, and create an Origination Connection Policy
    • Select the policy you just created and set the Origination SIP URI to sip:<your SIP URI>;transport=tcp. For example, if your SIP URI is 1abcdefgh2i.sip.livekit.cloud then enter sip:1abcdefgh2i.sip.livekit.cloud;transport=tcp.
  5. For outbound calls, configure termination and authentication:

    • Navigate to Elastic SIP Trunking » Manage » Trunks.

    • Copy the Termination SIP URI to use when you create an outbound trunk for LiveKit.

    • Configure Authentication:

      1. Select Elastic SIP Trunking » Manage » Credential lists and create a new credential list with a username and password of your choice.

      2. Associate your trunk with the credential list:

        • Select Elastic SIP Trunking » Manage » Trunks and select the outbound trunk created in the previous steps.
        • Select Termination » *Authentication » Credential Lists and select the credential list you just created.

Next steps

To accept inbound calls, use the following steps:

  1. Create a SIP inbound trunk.
  2. Create a SIP dispatch rule.
  3. Create an AI voice agent to accept phone calls.

To make outbound calls, use the following steps:

  1. Create a SIP outbound trunk.
  2. Create an AI voice agent to make phone calls or make an outbound call using the SIP API.