I have a livekit server deployed locally and I am ...
# ask-ai
a
I have a livekit server deployed locally and I am able to run my agent in the command prompt, i now need to connect this with telephony I have a twilio number
t
Thanks for reaching out, Bipin. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — great progress getting LiveKit and your agent running locally. I’m responding to your need to connect that setup to telephony using a Twilio number. Below are the practical next steps and options to get calls from your Twilio number into your local LiveKit agent. Quick summary of what you need to do • Use Twilio SIP trunking (or Twilio’s SIP Domains) to route calls from your Twilio number to your LiveKit server. • Configure LiveKit to accept those SIP calls and dispatch them to the running agent. • Ensure network access (public IP / port routing / NAT) and that your agent is registered with a matching agent name for dispatch. Step-by-step checklist 1. Make your LiveKit server reachable from Twilio ◦ Your LiveKit server must be reachable over the internet. Twilio will send SIP to your server’s public IP or domain. ◦ Open/forward SIP signaling (usually UDP/TCP port 5060) and RTP media port range used by LiveKit. Confirm your firewall/NAT forwards these ports to the machine running LiveKit. 1. Create a SIP domain/trunk in Twilio ◦ In Twilio, create a SIP Domain and configure the trunk to forward incoming calls to your LiveKit SIP endpoint (your public IP/domain and port). ◦ Use Twilio’s SIP credentials or allowed IP addresses depending on the security model you choose. 1. Configure an inbound trunk in LiveKit ◦ Add an inbound SIP trunk in LiveKit that allows Twilio’s SIP endpoints (IP or domain). ◦ Create a dispatch rule in LiveKit to map incoming calls to rooms/agents. A dispatch rule routes incoming SIP invites to a room prefix and the agent you want to handle the call. 1. Ensure your agent uses a matching agent name ◦ Your agent must be started with the same name referenced in the dispatch rule. Example pattern in agent code:
Copy code
@server.rtc_session(agent_name="my-telephony-agent")
     async def my_agent(ctx: JobContext):
         # agent logic
• If your dispatch rule lists agentName "my-telephony-agent", the running agent must use that exact name. 1. (Optional) Enable outbound calls from the agent ◦ Configure an outbound trunk in LiveKit with Twilio SIP credentials if your agent needs to place calls. ◦ Use the agent API (for example
ctx.api.sip.create_sip_participant()
) to programmatically create a SIP participant and initiate outbound calls. 1. Test the flow ◦ Dial the Twilio number. Twilio should forward the call to your LiveKit SIP endpoint. ◦ LiveKit’s dispatch rule should match and connect the call to a room where your agent is present. Common areas that cause issues • Network reachability: Twilio must reach your server. If your server is only on localhost behind NAT without port forwarding or a public hostname, Twilio cannot reach it. • Ports: SIP (5060) + media RTP ports need to be open/forwarded. Confirm any cloud/VPN/firewall path allows SIP + RTP. • Agent name mismatch: Dispatch rules match agent names exactly. Confirm spelling and casing. • SIP formatting: Ensure the SIP URI and Twilio SIP domain settings match what LiveKit expects. If you want, I can help next with: • Specific CLI/JSON for a dispatch rule you can apply. • Example Twilio SIP domain/trunk values and SIP URI formatting. • Troubleshooting steps if calls fail to reach your server (tests to run, logs to check). • Instructions to test outbound calls from an agent. Which of these would you like help with now? Also tell me: • Is your LiveKit server behind NAT or on a public IP/domain? • Do you want inbound only, outbound, or both? • What OS/environment is your agent running in (so I can tailor firewall/port advice)? Sources: Agents telephony integration | LiveKit Documentation