many-forest-60185
11/15/2025, 1:04 AMtall-airline-16756
11/15/2025, 1:04 AMtall-airline-16756
11/15/2025, 1:06 AMphone_number in the job metadata — if it’s there, it’s an outbound call; if not, it’s inbound. This way, you can tailor the agent’s logic to fit each call type.
5. Initiate outbound calls: When you’re ready to make outbound calls, use the CreateSIPParticipant API to get things started smoothly.
If you’d like more detailed examples and handy templates, I highly recommend checking out the Outbound Calling Agent template and the Telephony Integration Guide. They’re great resources to guide you through the process.
Sources: docs/index.yaml | SIP Integration & Telephony | livekit/livekit_composite | DeepWiki | Agents telephony integration | LiveKit Docs | src/setup-livekit.ts | livekit/livekit_sip.pb.gomany-forest-60185
11/15/2025, 1:07 AMtall-airline-16756
11/15/2025, 1:07 AMphone_number field exists in the job metadata. Here’s how it works:
• Inbound calls: If the phone_number isn’t there, you can set up an agent class that warmly greets the user and offers help right away.
• Outbound calls: If the phone_number is included, the agent can patiently wait for the other person to speak first before jumping in.
This way, you can easily tailor the agent’s behavior depending on whether the call is coming in or going out. If you have any questions or want to explore this further, I’m here to help!many-forest-60185
11/17/2025, 4:04 AMtall-airline-16756
11/17/2025, 4:04 AMphone_number field is present in the job metadata, and then adjust the agent's behavior accordingly. This way, your agent can respond just right for each call:
async def handle_call(session, job_metadata):
phone_number = job_metadata.get("phone_number")
if phone_number is None:
# Inbound call logic
await session.generate_reply(
instructions="Greet the user and offer your assistance."
)
else:
# Outbound call logic
await session.wait_for_user_input()
await session.generate_reply(
instructions="Respond to the user's input."
)
Here’s what’s happening:
• If phone_number is missing, the agent warmly greets the user right away, which is perfect for inbound calls.
• If phone_number is there, the agent patiently waits for the user to say something first, ideal for outbound calls.
You can easily plug this logic into your agent’s main handling function, so it naturally adapts based on whether the call is inbound or outbound. I hope this helps you get the behavior just right!many-forest-60185
11/17/2025, 4:12 AMtall-airline-16756
11/17/2025, 4:13 AMconst sipClient = new SipClient(
LIVEKIT_URL,
LIVEKIT_API_KEY,
LIVEKIT_API_SECRET,
);
// Create inbound trunk
const trunkName = 'inbound-trunk';
const trunk = await sipClient.createSipInboundTrunk(
trunkName,
[TWILIO_PHONE_NUMBER], // Phone numbers this trunk accepts calls for
{
auth_username: TWILIO_SIP_USERNAME,
auth_password: TWILIO_SIP_PASSWORD,
},
);
After you’ve created the trunk, you can easily link it with dispatch rules. This way, inbound calls will be routed smoothly to your LiveKit rooms and connect the right agent. If you have any questions along the way, I’m here to help!many-forest-60185
11/17/2025, 4:16 AMtall-airline-16756
11/17/2025, 4:17 AMlk sip inbound create --name "My trunk" --numbers "+15105550100" --auth-user "username" --auth-pass "password"
If you prefer, you can also use a JSON configuration file to make things even simpler:
lk sip inbound create inbound-trunk.json
Here’s what your inbound-trunk.json should look like:
{
"trunk": {
"name": "My trunk",
"numbers": [
"+15105550100"
],
"auth_username": "username",
"auth_password": "password"
}
}
After you’ve created the trunk, the next step is to set up dispatch rules. This will help route inbound calls smoothly to your LiveKit rooms. If you need any help with that, feel free to ask—I’m here to help!
Sources: cmd/lk/sip.go | Inbound calls with Twilio Voice | LiveKit docs | Create and configure a Twilio SIP trunk | LiveKit docs | SIP inbound trunk | LiveKit docs | lib/livekit/sip_service_client.rbmany-forest-60185
11/17/2025, 4:17 AMtall-airline-16756
11/17/2025, 4:18 AMkrisp_enabled setting is optional and it helps with noise cancellation during calls handled by the trunk. If you often have background noise on your calls or want to make the audio clearer, turning this feature on can really make a difference.
Here’s how you can add it to your configuration:
{
"trunk": {
"name": "My trunk",
"numbers": [
"+15105550100"
],
"auth_username": "username",
"auth_password": "password",
"krisp_enabled": true
}
}
But if noise cancellation isn’t something you need right now, it’s perfectly fine to leave this setting out. I hope this helps! Let me know if you have any other questions.many-forest-60185
11/17/2025, 4:18 AMtall-airline-16756
11/17/2025, 4:18 AMauth_username and auth_password should be your Twilio SIP credentials. You can usually find these in your Twilio Elastic SIP Trunking settings under the "Authentication" section.
Here are a couple of things to double-check:
• Make sure the username and password exactly match the credentials you set up in Twilio for your SIP trunk.
• Confirm that your Twilio trunk is set to use "Credential List" authentication.
If your Twilio trunk uses IP-based authentication instead, you won’t need to enter a username and password. Instead, you’ll want to make sure the allowed IP addresses are properly configured both in Twilio and LiveKit.many-forest-60185
11/17/2025, 4:22 AMtall-airline-16756
11/17/2025, 4:22 AMlk sip dispatch create --name "inbound-dispatch-rule" \
--trunk-id "your-inbound-trunk-id" \
--type "individual" \
--room-prefix "call"
Here’s what each part means:
• `--trunk-id`: This is the ID of your inbound trunk.
• `--type`: This sets the rule type. Using "individual" means a new room will be created for each call.
• `--room-prefix`: This adds a prefix to the names of rooms created for inbound calls.
Once you have your dispatch rule in place, your inbound calls will be smoothly routed to the right rooms, making it easier for your agents to assist your callers. If you have any questions while setting this up, I’m here to help!many-forest-60185
11/17/2025, 4:25 AMtall-airline-16756
11/17/2025, 4:26 AM--trunks, not --trunk-id. No worries though! Here’s the updated command for you:
lk sip dispatch create \
--name "inbound-dispatch-rule" \
--trunks "your-inbound-trunk-id" \
--caller "call-"
Just to clarify:
• `--trunks`: This is where you list the trunk IDs (you can separate multiple IDs with commas).
• `--caller`: This helps create individual caller dispatches using the room prefix you specify.
Give this updated command a try, and it should work smoothly for your setup. If you run into any other questions, I’m here to help!
Sources: cmd/lk/sip.go | README.md | Inbound calls with Twilio Voice | LiveKit docsmany-forest-60185
11/17/2025, 4:27 AMtall-airline-16756
11/17/2025, 4:27 AMagent_name in your dispatch rule or agent configuration.
Here’s a friendly guide to help you ensure only one agent joins:
1. Give each agent a unique name: When you’re setting up your agents, use the agent_name parameter to give each one a distinct identity.
2. Configure the dispatch rule to target that specific agent: In your agent logic, check the room metadata or job metadata so only the intended agent joins the room.
By following these steps, you’ll make sure the right agent handles each inbound call, keeping everything organized and conflict-free. If you need any more help, I’m here for you!many-forest-60185
11/17/2025, 4:45 AMtall-airline-16756
11/17/2025, 4:46 AM;transport=tcp, and that it’s pointing to your LiveKit SIP endpoint.
5. Test with a Simple Setup: Try using a basic TwiML Bin to route calls to your SIP trunk. This can help isolate where the issue might be.
If you’re still running into trouble, take another look at those Twilio call logs for specific error codes or messages. Feel free to reach out anytime—I’m here to help you through this!
Sources: packages/sip--um-actually/README.md | SIP troubleshooting guide | LiveKit docs | README.md | Inbound calls with Twilio Voice | LiveKit docsmany-forest-60185
11/17/2025, 4:47 AMtall-airline-16756
11/17/2025, 4:48 AM;transport=tcp.
5. STIR/SHAKEN Compliance: It’s also good to verify that your Twilio account and SIP trunk are set up with the right STIR/SHAKEN attestation level.
If you can share any specific SIP status codes or error messages from your Twilio logs, I’d be happy to help you dig deeper and find a solution together.
Sources: Agents telephony integration | LiveKit Docs | livekit-protocol/livekit/protocol/sip.pyi | SIP troubleshooting guide | LiveKit docs | README.md | Create and configure a Twilio SIP trunk | LiveKit docsmany-forest-60185
11/17/2025, 4:49 AM407 Proxy Authentication Required response from LiveKit, meaning LiveKit is asking for authentication credentials that Twilio isn’t providing (or is providing incorrectly).
The Flow
1. INVITE - Twilio sends call setup request to LiveKit
2. 100 Processing - LiveKit acknowledges receipt
3. 407 Unauthorized - LiveKit rejects with authentication challenge:
4. Proxy-Authenticate: Digest realm=“LiveKit”, nonce=“1763354615328833", algorithm=MD5
5. ACK - Twilio acknowledges the rejection
What’s Wrong
Twilio’s initial INVITE has no authentication credentials. LiveKit expects digest authentication but the request arrives without any Proxy-Authorization header.
How to Fix
You need to configure authentication in your Twilio SIP trunk settings:
1. In Twilio Console → Your SIP Trunk → Authentication
◦ Add LiveKit’s authentication credentials (username/password)
◦ These should match what LiveKit expects for the realm “LiveKit”
2. Or in LiveKit → SIP settings
◦ Configure to accept calls from Twilio’s IP addresses without authentication
◦ Add Twilio’s IP ranges to an allowlist
The typical fix is option 1 - configure Twilio with the correct SIP credentials that LiveKit is expecting. Check your LiveKit SIP trunk configuration for the username/password that should be used.tall-airline-16756
11/17/2025, 4:49 AM