rapid-honey-43838
02/26/2026, 1:39 PMtall-airline-16756
02/26/2026, 1:39 PMtall-airline-16756
02/26/2026, 1:39 PMrapid-honey-43838
02/26/2026, 1:48 PMtall-airline-16756
02/26/2026, 1:49 PMrapid-honey-43838
02/26/2026, 1:51 PMtall-airline-16756
02/26/2026, 1:51 PMrapid-honey-43838
02/26/2026, 1:52 PMtall-airline-16756
02/26/2026, 1:52 PMlk sip inbound create --name "Twilio-Inbound" --numbers "+1234567890"
1. Configure any required authentication details (IP ACLs, credentials) in the inbound trunk so Twilio can successfully deliver calls.
Step 3 — Create a dispatch rule to dynamically create rooms and dispatch agents You want a dispatch rule that:
• Creates a new room per incoming call (use a room prefix like call- plus a generated ID).
• Dispatches an available agent (match by agent pool or agent name).
• Ensures the agent joins only when dispatched (explicit dispatch).
Example dispatch behavior (conceptual JSON):
{
"dispatch_rule": {
"rule": {
"dispatchRuleIndividual": {
"roomPrefix": "call-"
}
},
"roomConfig": {
"agents": [
{
"agentSelector": {
"pool": "support-agents"
},
"agentJoinMode": "explicit"
}
]
}
}
}
• roomPrefix: LiveKit will create rooms like call-<unique-suffix>.
• agentSelector: target either a named agent or an agent pool.
• agentJoinMode `explicit`: ensures agents only join when dispatched.
Apply the dispatch rule to LiveKit:
• Save the JSON as a file (e.g., dispatch-rule.json) and run:
lk sip dispatch create dispatch-rule.json
(Adapt the exact CLI/API command to your LiveKit version and fields.)
Step 4 — Configure agent behavior in LiveKit
1. Ensure agent sessions are created with explicit dispatch capability. An agent should be registered with the agentName or belong to the agent pool referenced by the dispatch rule.
2. Agents should use @server.rtc_session(agent_name="...") (or equivalent) so they only join when the dispatch triggers.
3. Once dispatched, the agent client receives the room details and joins the room to begin the call.
Step 5 — Caller connection and greeting
1. When LiveKit creates the room for the inbound SIP call, the SIP caller is connected into that room as a SIP participant.
2. You can configure server-side session code (e.g., session.generate_reply()) to play a greeting or IVR prompt while waiting for an agent to join.
Step 6 — Testing and verification
1. Place a call to the Twilio phone number.
2. Verify Twilio forwards the INVITE to your LiveKit SIP URI (check Twilio SIP logs).
3. In LiveKit, verify a new room with the call- prefix is created and a SIP participant is present.
4. Confirm the dispatch rule triggers and an agent is offered / joins the room.
5. If failure occurs, collect:
◦ Twilio trunk SID, timestamp, and SIP trace/logs.
◦ LiveKit inbound trunk logs and dispatch decision logs.
◦ Room ID created (if any) and agent status.
Notes and tips
• Caller ID preservation: If you want the original caller ID preserved when transferring/terminating calls, enable the appropriate Twilio transfer-caller-id settings.
• Region endpoints: Use region-specific LiveKit SIP endpoints to keep PSTN ingress low-latency when possible.
• Security: Use IP ACLs and credential authentication between Twilio and LiveKit to avoid unauthorized INVITEs.
If you’d like, I can now:
• Provide an exact dispatch-rule JSON tailored to your agent naming/pool scheme if you share agent pool names or how you identify agents.
• Give concrete LiveKit CLI/API commands for your environment (share your LiveKit CLI version or whether you’ll use the REST API).
• Walk through a sample end-to-end test and what logs to check if something fails.
Which of those would help you next?rapid-honey-43838
02/26/2026, 1:54 PMtall-airline-16756
02/26/2026, 1:54 PMcall-) and dispatches an agent pool.
• Agents should be set to join explicitly so they only enter when dispatched.
5) Logging and monitoring
• Enable SIP logging/traces on Twilio and LiveKit to quickly verify incoming INVITEs and dispatch decisions.
• Monitor for unusual traffic patterns (rate spikes or repeated failed auth attempts) after opening inbound acceptance.
Security notes and best practices
• Accepting calls without caller-number checks is functionally fine, but without transport/auth protections you risk unauthorized SIP traffic or toll fraud. Always enable IP ACLs and/or SIP credential authentication.
• If you must temporarily accept unauthenticated calls for testing, do so from restricted IP ranges and revert to authentication before going to production.
• Consider rate-limiting or SIP request filtering to block abusive patterns.
If you’d like, I can:
• Provide the exact LiveKit CLI/API command to create an inbound trunk that accepts any caller number (tell me whether you’ll use the CLI or REST API).
• Show example Twilio origination settings for the trunk (SIP URI, credential mapping).
• Draft a dispatch-rule JSON that creates dynamic rooms and dispatches agents.
Which of those would you like next?rapid-honey-43838
02/26/2026, 1:56 PMtall-airline-16756
02/26/2026, 1:56 PMauth_username and auth_password you set on the LiveKit inbound trunk exactly match the username/password in Twilio’s Credential List (case-sensitive, no extra spaces).
1. Credentials are present in LiveKit
◦ Ensure your inbound trunk in LiveKit actually has auth_username / auth_password set (not null). If you created the trunk without credentials, LiveKit will use IP-based auth only.
1. Twilio is configured to use that Credential List
◦ In the Twilio Console, the Credential List must be attached to your Trunk’s Termination settings so Twilio will send credentials when calling your termination URI.
1. Allowed IPs / firewall
◦ If you set allowed_addresses on the LiveKit trunk, confirm Twilio’s egress IPs are included. If Twilio’s IP is blocked, auth flow may fail.
1. SIP transport and port
◦ Confirm Twilio is targeting the same transport/port LiveKit expects (LiveKit typically uses port 5060 for UDP/UDP-like SIP). If you configured TLS on one side and UDP on the other, authentication can fail.
Targeted troubleshooting steps
1. Check LiveKit logs for the auth failure
◦ Look for entries like “Authentication failed for user …” or “Sending 407 response.” Note the username LiveKit evaluated and any reason text.
1. Collect the SIP INVITE/401/407 exchange
◦ If you can, capture the SIP trace (Twilio logs or packet capture). The flow should be:
▪︎ Twilio INVITE → LiveKit 401/407 challenge → Twilio re-INVITE with Authorization header
◦ If Twilio never sends the Authorization header after the challenge, the Credential List may not be attached or Twilio isn’t configured to use credential auth.
1. Verify Twilio credential settings
◦ In Twilio: ensure Credential List contains the exact username/password.
◦ Ensure Termination is set to use that Credential List for calls to your LiveKit termination URI.
1. Test with a simple SIP client (optional)
◦ Register a basic SIP client or run sipp against LiveKit with the same username/password to confirm LiveKit accepts those credentials. This isolates whether the issue is Twilio-side or LiveKit-side.
If you want, I can help more precisely — please share (masked if needed):
• The auth_username value you configured in LiveKit (mask part of the password; username is sufficient to check for exact match).
• Whether auth_password was set in LiveKit and the same password in Twilio (just confirm “same” / “different”).
• Whether you have allowed_addresses configured on the trunk and what IPs are listed.
• Any LiveKit log lines around the 407 (timestamped) or Twilio SIP trace entries.
What I’ll check or suggest next once you share that:
• If credentials mismatch: give exact commands/code snippets to update LiveKit or Twilio so they match.
• If allowed_addresses missing Twilio IPs: show which Twilio egress IPs to add.
• If Twilio never sends Authorization: walk through attaching the Credential List to your trunk termination settings.
If you prefer, tell me which step you want to try first and I’ll provide the exact CLI/API or Twilio Console steps to update and verify the settings.
Sources: Understanding TLS in SIP | LiveKit | sip | livekit/livekit_composite | DeepWiki | Agents telephony integration | LiveKit Documentationrapid-honey-43838
02/26/2026, 1:57 PMtall-airline-16756
02/26/2026, 1:57 PMallowed_addresses.
◦ If you must run without allowed addresses, enable detailed SIP logging and rate limiting and plan to add the allowlist before going live.
If you want, I can:
• Show the exact LiveKit CLI/API command to add Twilio’s IP ranges to your inbound trunk.
• Provide the minimal set of Twilio IPs commonly required for SIP egress, or link to Twilio’s IP ranges to copy into allowed_addresses.
Which would help you next?rapid-honey-43838
02/26/2026, 1:59 PMtall-airline-16756
02/26/2026, 1:59 PMsipp -sf uac.xml -s TO_NUM YOUR_LIVEKIT_HOST:5060 -rsa FROM_NUM -m 1 -trace_msg
• -sf uac.xml: path to a SIP scenario file (see note below for a minimal INVITE scenario).
• -s TO_NUM: Request-URI user/To header number.
• -rsa FROM_NUM: sets the From user/number.
• -m 1: send one call and exit.
• -trace_msg: prints SIP messages.
2) INVITE with Digest Authentication (test 407/401 challenge + response)
• This sends an initial INVITE, handles LiveKit’s 407/401 challenge, and resends the INVITE with Authorization using the provided username/password.
sipp -sf uac.xml -s TO_NUM YOUR_LIVEKIT_HOST:5060 -rsa FROM_NUM -au YOUR_USERNAME -ap YOUR_PASSWORD -m 1 -trace_msg
• -au / -ap: username/password for SIP digest auth. sipp will respond to the challenge automatically.
• Watch the trace: you should see INVITE → 407/401 → INVITE (with Authorization) → 200/180/183 or final response.
3) Using TCP or TLS
• TCP (port 5060):
sipp -sf uac.xml -s TO_NUM YOUR_LIVEKIT_HOST:5060 -transport tcp -rsa FROM_NUM -au YOUR_USERNAME -ap YOUR_PASSWORD -m 1 -trace_msg
• TLS (sips) — only if LiveKit is configured to accept TLS:
sipp -sf uac.xml -s TO_NUM YOUR_LIVEKIT_HOST:5061 -transport tls -rsa FROM_NUM -au YOUR_USERNAME -ap YOUR_PASSWORD -m 1 -trace_msg
• Note: TLS requires proper certificates on the server. If using self-signed certs you may need extra sipp options or an out-of-band test tool.
Minimal uac.xml scenario (simple INVITE)
• If you don’t have a scenario file, create a minimal UAC scenario that sends an INVITE and waits for OK. Save as `uac.xml`:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!DOCTYPE scenario SYSTEM "sipp.dtd">
<scenario name="Simple UAC">
<send retrans="500">
<![CDATA[
INVITE sip:[field0]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/UDP [local_ip]:[local_port];branch=[branch]
Max-Forwards: 70
From: "sipp" <sip:[field1]@[local_ip]>;tag=[call_number]
To: <sip:[field0]@[remote_ip]>
Call-ID: [call_id]
CSeq: 1 INVITE
Contact: <sip:[field1]@[local_ip]:[local_port]>
Content-Type: application/sdp
Content-Length: [len]
v=0
o=- 0 0 IN IP4 [local_ip]
s=-
c=IN IP4 [local_ip]
t=0 0
m=audio [media_port] RTP/AVP 0
a=rtpmap:0 PCMU/8000
]]>
</send>
<recv response="407|401"/>
<send>
<![CDATA[
ACK sip:[field0]@[remote_ip]:[remote_port] SIP/2.0
Via: SIP/2.0/UDP [local_ip]:[local_port];branch=[branch]
From: "sipp" <sip:[field1]@[local_ip]>;tag=[call_number]
To: <sip:[field0]@[remote_ip]>;tag=[peer_tag]
Call-ID: [call_id]
CSeq: 1 ACK
Content-Length: 0
]]>
</send>
<recv response="200" optional="true"/>
<recv response="180|183" optional="true"/>
</scenario>
• When running sipp, pass fields like TO_NUM and FROM_NUM as shown in the commands above.
Interpreting results
• Successful auth flow: you’ll see INVITE → 407/401 challenge → INVITE with Authorization → 200/180/183. If this completes, credentials are accepted.
• Persistent 407/401 after resubmission: credentials mismatch — confirm username/password in both LiveKit and Twilio.
• No response / ICMP unreachable / timeout: network/port/firewall issue; verify port and IP access.
• Immediate 503/403: server-side rejection or policy (check LiveKit logs).
Helpful log checks
• On LiveKit: look for auth log lines indicating which username was evaluated and whether authentication succeeded or failed.
• On Twilio: enable SIP logging to see whether Twilio includes the Authorization header after challenge.
If you want, tell me:
• The exact sipp command you ran and its trace output, or
• Whether your LiveKit trunk uses UDP/TCP/TLS and the auth username you expect (masked), so I can give a tailored sipp command and help interpret the trace.rapid-honey-43838
02/26/2026, 2:03 PMtall-airline-16756
02/26/2026, 2:03 PMauth_username you set in LiveKit
◦ Password: the auth_password
◦ Domain / Host: your LiveKit SIP host (example: your-livekit-host or your-livekit-host:5060)
◦ If Zoiper asks for a display name or auth username separately, put the same username in both places.
1. Transport settings:
◦ If LiveKit expects UDP: choose UDP (default).
◦ If you configured TCP: choose TCP.
◦ If LiveKit supports TLS and you set it up: choose TLS and use port 5061 (only if you configured TLS).
1. Outbound proxy / Registrar:
◦ If LiveKit expects direct INVITEs to the termination URI, set the Registrar to your LiveKit host (same as Domain).
◦ If you must use a full SIP URI, set the Registrar to sipyour livekit host5060.
1. Keep Alive / NAT:
◦ If Zoiper is behind NAT, enable SIP keepalive (options → network) so the server keeps the connection open.
1. Save and apply the account.
Placing a test call (simulate an inbound call)
• To test credential authentication and trunk behavior you can:
◦ From Zoiper, dial the username/URI that Twilio would use as the Request-URI. For example:
▪︎ Dial the number part used in your trunk request: sip:+1234567890@your-livekit-host
▪︎ Or dial the SIP target configured for your trunk: sip:TO_NUMBER@your-livekit-host
◦ Alternatively, place a direct SIP INVITE to the LiveKit host using the dial field in Zoiper (format can be sip:TO_NUMBER@your-livekit-host).
What to expect in a correct flow
• Zoiper sends REGISTER or INVITE (depending on account setup).
• LiveKit should challenge with 401/407 if credential auth is required.
• Zoiper responds with Authorization header automatically after challenge.
• If credentials match, you should see a 200 OK (or 180/183 provisional followed by 200).
• The call will connect and Zoiper should show audio RTP if a media path is negotiated.
If you want to emulate how Twilio sends calls (no REGISTER, direct INVITE)
• In Zoiper you can disable registration for that account (account advanced → disable registration) and directly dial the target SIP URI (sip:TO_NUMBER@your-livekit-host). That will send an INVITE without prior REGISTER, which mirrors Twilio unregistered INVITEs.
Troubleshooting tips
• Still getting 407/401 after Zoiper resubmits?
◦ Double-check username/password for exact match (case-sensitive, no trailing spaces).
◦ In Zoiper account settings ensure the auth username field matches the LiveKit auth_username exactly.
• No response / timeout:
◦ Check port and transport (UDP/TCP). Confirm LiveKit is reachable on that port from your network.
◦ Verify firewall allows outbound from Zoiper and inbound to LiveKit.
• Registration refused or rejected:
◦ LiveKit may not expect REGISTER; it may be expecting unregistered INVITE flows. Try disabling registration and sending the direct INVITE.
• Check logs:
◦ Enable Zoiper debug logs (Settings → Debug) to see SIP message flow from the client side.
◦ Check LiveKit server logs for the incoming INVITE and any auth failure messages.
• If NAT / audio issues (one-way audio or no audio):
◦ Ensure media ports are open/backed by ICE if LiveKit expects RTP via different addresses.
◦ Try using a client on a public network or adjust NAT traversal settings.
Optional advanced checks
• Capture the SIP exchange in Zoiper debug logs and compare with LiveKit logs to confirm the challenge/response sequence.
• If Zoiper can authenticate but Twilio cannot, compare the exact Authorization header parameters (nonce, realm) from Zoiper’s successful flow to Twilio’s failing flow — this helps reveal credential mismatches or transport differences.
If you want, tell me:
• Which transport/port your LiveKit SIP endpoint uses (UDP/TCP/TLS).
• Whether you want to simulate Twilio exactly (I’ll show the exact dial string to use).
• Paste (masked) the Zoiper debug trace or LiveKit log lines and I’ll help interpret them.
Would you like the exact dial string to simulate your Twilio number (give me the number format you expect: E.164 like +1234567890)?