miniature-lifeguard-87511
07/10/2025, 10:05 AMtall-airline-16756
07/10/2025, 10:05 AMtall-airline-16756
07/10/2025, 10:06 AMLIVEKIT_API_KEY
, TWILIO_PHONE_NUMBER
, etc.) are required for a quick start and seamless integration.
For a complete step-by-step guide, configuration samples, and example projects, please refer to the official documentation and samples cited here. This will walk you through both Twilio and LiveKit setup, including all required commands and environment variable setups.
If you need a specific workflow, configuration detail, or troubleshooting steps for any particular part of the setup, let me know and I can provide targeted guidance.
Sources: Inbound calls with Twilio Voice | LiveKit Docs | .env.example | Integrating with Telephony | LiveKit Docs | Create and configure a Twilio SIP trunk | LiveKit Docsminiature-lifeguard-87511
07/10/2025, 10:25 AMtall-airline-16756
07/10/2025, 10:26 AM<http://pstn.twilio.com|pstn.twilio.com>
.
twilio api trunking v1 trunks create --friendly-name "My test trunk" --domain-name "<http://my-test-trunk.pstn.twilio.com|my-test-trunk.pstn.twilio.com>"
ii. Next, let's set up an Origination URI that points to your LiveKit SIP host. Think of it like giving Twilio a direct route to your system.
twilio api trunking v1 trunks origination-urls create --trunk-sid <twilio_trunk_sid> --friendly-name "LiveKit SIP URI" --sip-url "sip:<your_sip_host>" --weight 1 --priority 1 --enabled
iii. Now, connect your Twilio number to your SIP trunk. It's like introducing two friends who are perfect for each other! π
twilio api trunking v1 trunks phone-numbers create --trunk-sid <twilio_trunk_sid> --phone-number-sid <twilio_phone_number_sid>
β¦ Twilio Programmable Voice (Alternative)
i. Create a TwiML Bin in your Twilio Console with the following content (replace placeholders): <Response>
<Dial>
<Sip username="<sip_trunk_username>" password="<sip_trunk_password>">sip:<your_phone_number>@<your_sip_host></Sip>
</Dial>
</Response>
ii. Point your Twilio phone number's Voice handler to this TwiML Bin. Easy peasy! π
1. LiveKit Setup
β¦ Create an inbound SIP trunk configuration file (JSON): {
"trunk": {
"name": "My inbound trunk",
"auth_username": "<sip_trunk_username>",
"auth_password": "<sip_trunk_password>"
}
}
β¦ Register the inbound trunk using LiveKit CLI:
lk sip inbound create inbound-trunk.json
β¦ Set a dispatch rule (JSON): {
"rule": {
"dispatchRuleIndividual": {
"roomPrefix": "call"
}
}
}
β¦ Create the dispatch rule with LiveKit CLI:
lk sip dispatch-rule create dispatch-rule.json
1. Run Example Projects and Automations (Optional)
β¦ Install the official example project dependencies
β¦ Copy the .env.example
and fill in your environment variables:
βͺοΈ LIVEKIT_API_KEY
, LIVEKIT_API_SECRET
, LIVEKIT_URL
βͺοΈ LIVEKIT_SIP_URI
(pointing at your trunk)
βͺοΈ TWILIO_PHONE_NUMBER
, TWILIO_ACCOUNT_SID
, TWILIO_AUTH_TOKEN
βͺοΈ TWILIO_SIP_USERNAME
, TWILIO_SIP_PASSWORD
βͺοΈ (If using a voice assistant: OPENAI_API_KEY
)
β¦ Automated setup scripts:
npm run setup:twilio
and npm run setup:livekit
β¦ Start the agent: npm run agent
1. Test Calling
β¦ Call your Twilio phone number. The call should route into the LiveKit room, allowing your configured agent to join and interact. Time to see the magic happen! β¨
I know this might look a bit technical, but trust me, you've got this! If you need a little extra hand-holding or want me to dive deeper into any of these steps, just give me a shout. I'm here to help you every step of the way. πminiature-lifeguard-87511
07/10/2025, 10:29 AMtall-airline-16756
07/10/2025, 10:30 AMdispatch-rule.json
file is missing something crucial - the required rule
object. Think of it like a recipe that needs all its key ingredients to work properly.
Example: Individual Dispatch Rule (Most Common)
{
"rule": {
"dispatchRuleIndividual": {
"roomPrefix": "call-"
}
}
}
You've got a few options here: dispatchRuleDirect
, dispatchRuleCallee
, or the one I showed above. The key is to include just one type inside the rule
object.
My advice? Double-check your dispatch-rule.json
file, make sure you've got one of these rule structures, and give it another shot. If you're still stuck, no worries - just take a close look at your JSON syntax and make sure all the required fields are in place.
Sources: SIP dispatch rule | LiveKit Docs | cmd/lk/sip.gominiature-lifeguard-87511
07/10/2025, 10:38 AMtall-airline-16756
07/10/2025, 10:39 AM{
"rule": {
"dispatchRuleIndividual": {
"roomPrefix": "call-"
}
}
}
β’ Just a heads up - you'll need to create the dispatch rule manually β it won't happen automatically.
β’ Pro tip: Make sure you create an inbound trunk first before setting up your dispatch rule.
β’ Double-check that your API key and secret have SIP admin permissions.
β’ Quick check: Confirm your fields match one of these formats: dispatchRuleIndividual
, dispatchRuleDirect
, or dispatchRuleCallee
inside the rule
object, and stick to just one.
Still seeing the error? No worries! Take a quick look for any extra spaces in your JSON, make sure your trunk is set up, and verify your permissions. Remember, you'll need to do this manually through the CLI or API.
Sources: cmd/lk/sip.go | pkg/service/sip.go | Create and configure SIP trunk | LiveKit Docs | livekit-api/src/services/sip.rs | SIP dispatch rule | LiveKit Docsminiature-lifeguard-87511
07/10/2025, 10:41 AMtall-airline-16756
07/10/2025, 10:42 AMinbound-trunk.json
. Don't stress β I'll show you exactly what to put in it (just swap in your Twilio number): {
"trunk": {
"name": "My trunk",
"numbers": [
"+15105550100"
]
}
}
2. Now, run this super simple CLI command:
lk sip inbound create inbound-trunk.json
And that's it! This will get your trunk set up to handle incoming calls to the number you specified. Pro tip: If you need some extra customization, you can totally add optional parameters like krisp_enabled
or auth_username
.
Once you've done this, you'll be all set to create your dispatch rule. Easy peasy!
Sources: livekit/livekit_sip.twirp.go | Accepting incoming calls | LiveKit Docs | SIP inbound trunk | LiveKit Docs | SIP APIs | LiveKit Docsminiature-lifeguard-87511
07/10/2025, 10:49 AMtall-airline-16756
07/10/2025, 10:51 AMlk sip dispatch create
and lk sip dispatch-rule create
do the same thing, so the command isn't causing your issue. Here are a few things we can check together:
β’ Your JSON might have some sneaky formatting problems like hidden characters or tricky quote mismatches.
β’ You might be using a CLI version that's a bit out of date. Quick tip: run lk --version
to double-check.
β’ There's a chance the rule
key is a bit old-school. Some newer LiveKit versions prefer dispatch_rule
. Why don't you try switching your dispatch-rule.json
to use "dispatch_rule" instead of "rule":
{
"dispatch_rule": {
"dispatchRuleIndividual": {
"roomPrefix": "call-"
}
}
}
Pro tip: run your JSON through a strict linter and make sure you're giving the CLI the exact file name. If this doesn't solve it, let's compare your CLI and server versions to make sure they're playing nice together.
Sources: cmd/lk/sip.go | livekit/livekit_sip.twirp.go | SIP dispatch rule | LiveKit Docsminiature-lifeguard-87511
07/10/2025, 11:21 AMtall-airline-16756
07/10/2025, 11:22 AMlk sip dispatch list
, and the entry is right there, looking good for individual room dispatching.
You're all set to move forward! Feel free to test out your inbound call routing or explore more SIP features. If anything seems a bit off or you run into any hiccups, just let me know the details, and I'll be happy to help. But for now, your dispatch rule is totally ready to go!miniature-lifeguard-87511
07/10/2025, 11:47 AMtall-airline-16756
07/10/2025, 11:48 AM<http://my-trunk.pstn.twilio.com|my-trunk.pstn.twilio.com>
.
- Set up your login credentials - just like a secure password for your account.
- Linking a Twilio number is optional if you're just doing outbound calls, but good to know!
2. Create `outbound-trunk.json`:
{
"trunk": {
"name": "My outbound trunk",
"address": "<http://my-trunk.pstn.twilio.com|my-trunk.pstn.twilio.com>",
"numbers": [
"+15105550100"
],
"auth_username": "your_username",
"auth_password": "your_password"
}
}
- Pro tip: Make sure to swap out those placeholder values with your actual Twilio details!
3. Register the outbound trunk in LiveKit:
lk sip outbound create outbound-trunk.json
4. Want maximum flexibility? Use "numbers": ["*"]
to allow calling from any number.
5. Ready to make calls? You'll create a SIP participant through the API with these key details: I can totally help you with the exact schema if you need it!
β¦ `sip_trunk_id`: (your unique trunk ID)
β¦ `sip_call_to`: (who you're calling)
β¦ `sip_number`: (your authorized Twilio number, needed if using ["*"])
β¦ Your usual room and participant details
And voilΓ ! You're now set up to make outbound SIP calls through Twilio with LiveKit. π
Need a specific code example or have questions about implementation? Just ask! I'm here to help you nail this setup. π
Sources: Making calls using SIP | LiveKit Docs | Create and configure a Twilio SIP trunk | LiveKit Docs | Making outbound calls | LiveKit Docs | SIP outbound trunk | LiveKit Docs