a
hello
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! How can I help you today? I'm here to make sure everything goes smoothly for you.
a
so i deploy my agent to livekit cloud using lk agent create.. now i want to use that deployed agent for telephony twilio outbound.. how to do it ?
t
I'm here to help you get started with using your deployed LiveKit agent for Twilio outbound telephony. Just follow these friendly steps: 1. Set Up Prerequisites: First, make sure you have a Twilio phone number, a configured SIP trunk, and a LiveKit Cloud project ready to go. Don’t forget to install the LiveKit CLI (version 2.3.0 or later) to keep things running smoothly. 2. Configure Environment Variables: Next, set up important variables like
LIVEKIT_URL
,
LIVEKIT_API_KEY
,
TWILIO_ACCOUNT_SID
,
TWILIO_PHONE_NUMBER
, and others. This will help everything connect properly. 3. Create an Outbound Trunk: You’ll want to register your Twilio SIP trunk with LiveKit. Just create a JSON file including details like your phone number, trunk domain, and authentication credentials. Then, use the LiveKit CLI to create the trunk—it’s straightforward! 4. Modify and Deploy Your Agent: Update your agent code to handle outbound calls by using the
create_sip_participant
function. To find the
sip_trunk_id
, simply run the
lk sip outbound list
command. 5. Dispatch the Agent: Finally, use the LiveKit CLI to dispatch your agent for outbound calls. Here’s an example you can follow:
Copy code
lk dispatch create \
--new-room \
--agent-name outbound-caller \
--metadata '+15105550100'
Once you initiate the call, the recipient will be connected to your agent as soon as they answer. If you have any questions or need a hand with any step, just let me know—I’m happy to assist! Sources: Making calls using SIP | LiveKit Docs | .env.example | Create and configure a Twilio SIP trunk | LiveKit Docs | Agents telephony integration | LiveKit Docs | Making calls using SIP | LiveKit Docs
a
so i deploy my agent to livekit cloud using lk agent create.. now i want to use that deployed agent for telephony twilio inbound calls.. how to do it ?
t
I'm here to help you use your deployed LiveKit agent for Twilio inbound telephony! Just follow these steps, and if you have any questions along the way, feel free to reach out: 1. Purchase a Twilio Phone Number: First, get a phone number from Twilio that supports voice capabilities. This will be the number your callers dial. 2. Create a TwiML Bin: Next, use Twilio's TwiML Bin to route incoming calls to LiveKit. Here's the TwiML content you'll need—just replace the placeholders with your info:
Copy code
<response>
  <dial>
    <sip username="<your_sip_username>" password="<your_sip_password>">
      sip:<your_twilio_phone_number>@<your_sip_endpoint>
    </sip>
  </dial>
</response>
3. Link the TwiML Bin: Then, make sure to configure your Twilio phone number to use this TwiML Bin for incoming calls under the "Voice Configuration" section. This connects everything smoothly. 4. Create a LiveKit Inbound Trunk: You'll want to create a JSON file with your SIP trunk details and deploy it using the LiveKit CLI:
lk sip inbound create inbound-trunk.json
5. Set Up a Dispatch Rule: To route calls to your agent, create a dispatch rule and deploy it like this:
lk sip dispatch create dispatch-rule.json
6. Ensure Your Agent is Running: Don’t forget to start your agent with a defined
agent_name
so it’s ready to handle those incoming calls. 7. Answer Calls in Your Agent Code: Finally, use
generate_reply()
in your agent code to interact with callers once the agent joins the room. If any of these steps feel tricky or if you want me to walk you through any part in more detail, just let me know—I’m here to support you! Sources: Inbound calls with Twilio Voice | LiveKit Docs | Accepting incoming calls | LiveKit Docs | package.json | packages/sip--um-actually/README.md | Agents telephony integration | LiveKit Docs
a
1. Ensure Your Agent is Running: Don’t forget to start your agent with a defined
agent_name
so it’s ready to handle those incoming calls. in this step, even if i deployed agent to livekit cloud using the latest method lk agent create and its in runnig state in cloud,still i need to start my agent from local using python agent.py start before making call.. ?
t
Hi there! You actually don’t need to start your agent locally if it’s already deployed and running in LiveKit Cloud using
lk agent create
. Once it’s deployed, your agent runs smoothly on LiveKit Cloud’s infrastructure and can handle incoming calls all on its own—no local execution needed. Local execution is mainly helpful when you’re developing or testing. So, rest assured, your cloud-hosted agent will work independently and manage sessions just as you’ve set it up. Sources: Deploy and scale agents on LiveKit Cloud | Voice AI quickstart | LiveKit Docs | README.md | Deploying to production | LiveKit Docs
a
1. Ensure Your Agent is Running: Don’t forget to start your agent with a defined
agent_name
so it’s ready to handle those incoming calls. what this step means then ?
t
Just a quick note to make sure your agent is running with a defined
agent_name
. This means your agent should have a unique name set during its initialization. This step is really important for telephony integrations because the
agent_name
helps match dispatch rules and route calls correctly. For instance, in your agent code, you’d set the name like this:
Copy code
agents.cli.run_app(agents.WorkerOptions(
    entrypoint_fnc=entrypoint,
    agent_name="my-telephony-agent"  # Unique name for the agent
))
When you create dispatch rules or use the LiveKit CLI, just be sure to use this exact
agent_name
so everything routes smoothly. If you have any questions or want me to walk you through it, I’m here to help! Sources: Agents telephony integration | LiveKit Docs | Agents telephony integration | LiveKit Docs | SIP troubleshooting guide | LiveKit Docs | README.md
a
i tried all the steps, and now when i am calling then its not picking up the call
t
I’m here to help you get your LiveKit agent picking up Twilio inbound calls smoothly. Let’s walk through some key troubleshooting steps together: 1. Verify Agent Name and Dispatch Rule: Please double-check that the
agent_name
in your agent code exactly matches the name in your dispatch rule. Remember, names are case-sensitive, so even a small difference can cause issues. 2. Check SIP Trunk Authentication: Make sure the username and password in your TwiML or SIP trunk configuration perfectly match those in your LiveKit inbound trunk. This step is crucial for a secure connection. 3. Inspect Inbound Trunk Setup: Using the LiveKit CLI, confirm that the trunk is properly set up with your Twilio phone number in the correct E.164 format (for example,
+15105550100
). 4. Run the Agent: Ensure your agent process is up and running, and connected to LiveKit. It’s also a good idea to check the logs for any error messages that might give us clues. 5. Test Call Flow: Let’s verify the entire workflow: Twilio should send the call to LiveKit, LiveKit authenticates the trunk, matches the dispatch rule, and then routes the call to your agent. 6. Switch to Elastic SIP Trunking: If you’re currently using TwiML Bins, you might want to consider switching to Elastic SIP Trunking. This offers full telephony features like outbound calls and call transfers, which can enhance your setup. To help you inspect your setup, you can run these commands:
Copy code
lk sip inbound list
lk sip dispatch list
If you get stuck or want me to walk you through any particular step, just let me know—I’m here to support you every step of the way! Sources: SIP troubleshooting guide | LiveKit Docs | Agents telephony integration | LiveKit Docs | Inbound calls with Twilio Voice | LiveKit Docs | README.md | Accepting incoming calls | LiveKit Docs
a
I am using twiml bin so when using livekit cli for adding dispatch rule, i need to add agent name field in the json right ?
t
Absolutely! When you're using the LiveKit CLI to add a dispatch rule, it's important to include the
agentName
field within the JSON under the
roomConfig.agents
section. This little detail helps make sure the dispatch rule sends calls to the right agent. Here's a quick example for you:
Copy code
{
  "dispatch_rule": {
    "rule": {
      "dispatchRuleIndividual": {
        "roomPrefix": "call-"
      }
    },
    "roomConfig": {
      "agents": [
        {
          "agentName": "my-telephony-agent"
        }
      ]
    }
  }
}
Just double-check that the
agentName
exactly matches the name you’ve set in your agent code. If anything feels unclear or you want to dive deeper, I’m here to help—just let me know!
a
Also need to add phone number field with phone number in invound trunk json ?
t
Absolutely! You'll want to include the
numbers
field in your inbound trunk JSON. This is where you list the Twilio phone numbers linked to your trunk. Just make sure the phone numbers are in E.164 format (for example,
+15105550100
). Here's a quick example for you:
Copy code
{
  "trunk": {
    "name": "My inbound trunk",
    "auth_username": "your_username",
    "auth_password": "your_password",
    "numbers": [
      "+15105550100"
    ]
  }
}
This step helps LiveKit properly connect incoming calls from the specified phone number to your trunk. If you have any questions or need a hand with anything else, just let me know—I'm here to help!
a
Can i do all this steps from UI or need to do using cli ? Also, can do i need to deploy agent again after adding json files for trunk and dispatch ?
t
Absolutely! You can easily set up inbound trunks and dispatch rules right from the LiveKit UI, no need to use the CLI. Just head over to the Telephony → Configuration page in your LiveKit Cloud dashboard, and click on the "Create new" option to add a trunk or dispatch rule. It’s designed to be really user-friendly, so you should find it straightforward to configure these settings. Also, there’s no need to redeploy your agent after adding trunk and dispatch configurations. These settings are managed separately from the agent deployment, so your agent will automatically start handling calls based on the new dispatch rules and trunk settings. If you have any questions along the way, I’m here to help! Sources: Using Wavix to accept and make calls | LiveKit Docs | Accepting incoming calls | LiveKit Docs | Accepting incoming calls | LiveKit Docs | src/setup-livekit.ts | packages/sip--um-actually/src/setup-livekit.ts
a
So if i am using twiml bin for inbound then no need to setup trunk and dispatch from cli right.. i can do from frontend ?
t
That's right! If you're using TwiML Bin for your inbound calls, you can easily set up the trunk and dispatch rule right from the LiveKit Cloud dashboard (frontend). Just head over to the Telephony → Configuration page, and use the "Create new" options to configure the inbound trunk and dispatch rule—no need to worry about the CLI. If you'd like, I’m here to guide you through any specific step. Just let me know!
a
What to add in .env ?
t
Here are the environment variables you'll want to add to your
.env
file for setting up LiveKit telephony with Twilio: • LiveKit Configuration: ◦ `LIVEKIT_API_KEY`: Your LiveKit API key ◦ `LIVEKIT_API_SECRET`: Your LiveKit API secret ◦ `LIVEKIT_URL`: The URL of your LiveKit server instance (for example,
<wss://your-project.livekit.cloud>
) ◦ `LIVEKIT_SIP_URI`: Your LiveKit SIP URI (like
<sip:your-sip-uri@livekit.cloud>
) • Twilio Configuration: ◦ `TWILIO_ACCOUNT_SID`: Your Twilio Account SID ◦ `TWILIO_AUTH_TOKEN`: Your Twilio Auth Token ◦ `TWILIO_PHONE_NUMBER`: The Twilio phone number you’ve purchased (e.g.,
+1234567890
) ◦ `TWILIO_SIP_USERNAME`: Username for your Twilio SIP trunk credentials ◦ `TWILIO_SIP_PASSWORD`: Password for your Twilio SIP trunk credentials • Optional (if you’re using AI features): ◦ `OPENAI_API_KEY`: Needed if your agent uses OpenAI for voice processing If you’d like, I’m here to help walk you through setting up any of these variables—just let me know! Sources: src/setup-livekit.ts | packages/sip--make-a-call/.env.example | server/index.js | Inbound calls with Twilio Voice | LiveKit Docs
a
For inbound using twiml bin ?
t
When you're setting up inbound calls with TwiML Bin, it's important to have a few environment variables configured in your
.env
file. Don’t worry, I’m here to guide you through it! • LiveKit Configuration: ◦ `LIVEKIT_API_KEY`: This is your LiveKit API key ◦ `LIVEKIT_API_SECRET`: Your LiveKit API secret ◦ `LIVEKIT_URL`: The URL of your LiveKit server instance (for example,
<wss://your-project.livekit.cloud>
) ◦ `LIVEKIT_SIP_URI`: Your LiveKit SIP URI (something like
<sip:your-sip-uri@livekit.cloud>
) • Twilio Configuration: ◦ `TWILIO_ACCOUNT_SID`: Your Twilio Account SID ◦ `TWILIO_AUTH_TOKEN`: Your Twilio Auth Token ◦ `TWILIO_PHONE_NUMBER`: The Twilio phone number you’ve purchased (e.g.,
+1234567890
) ◦ `TWILIO_SIP_USERNAME`: Username for your Twilio SIP trunk credentials ◦ `TWILIO_SIP_PASSWORD`: Password for your Twilio SIP trunk credentials Even though TwiML Bin makes call routing simpler, these environment variables are still necessary to properly authenticate and route your calls through LiveKit. If anything feels unclear or you want to dive deeper into any step, just let me know—I’m happy to help!
a
Once this setup i can re deploy my agent to cloud right then it should work
t
Absolutely! Once you finish setting this up, you'll be able to redeploy your agent to LiveKit Cloud smoothly. Just make sure your agent has the right
agent_name
and all the environment variables are correctly configured. After that, your agent should be all set to handle inbound calls without a hitch. If you run into any bumps along the way, please don’t hesitate to reach out—I’m here to help!
a
So can i assign a sepcific agent to specific room in inbound ? If yes then how using cloud ui
t
Absolutely, you can assign a specific agent to a specific room for inbound calls using the LiveKit Cloud UI. Let me guide you through the steps: 1. Create a Dispatch Rule: Head over to the Telephony → Configuration page in the LiveKit Cloud dashboard and click on "Create new → Dispatch rule." 2. Use the JSON Editor: To assign a specific agent, switch to the JSON editor and add the
roomConfig.agents
field. Here’s an example to help you visualize:
Copy code
{
  "rule": {
    "dispatchRuleIndividual": {
      "roomPrefix": "call-"
    }
  },
  "name": "My dispatch rule",
  "roomConfig": {
    "agents": [
      {
        "agentName": "inbound-agent",
        "metadata": "dispatch metadata"
      }
    ]
  }
}
3. Verify Agent Name: It’s important to double-check that the
agentName
in your agent code exactly matches the name you use in the dispatch rule JSON. If you’d like, I’m here to help you with the JSON configuration or any other questions you might have. Just let me know! Sources: SIP troubleshooting guide | LiveKit Docs | packages/livekit-server-sdk/src/AgentDispatchClient.ts | SIP dispatch rule | LiveKit Docs | Dispatching agents | LiveKit Docs | Using Wavix to accept and make calls | LiveKit Docs
a
i ahve done verything correctly... check this {callId: "SCL_XSNSuni5itvP" trunkId: "ST_TbMM7Ysu3juJ" region: "oashburn1b" fromUri: {user: "+918975012399" host: "10.34.13.251" port: 17791 transport: "SIP_TRANSPORT_UDP" } toUri: {user: "+18384488081" host: "3obet2isa0b.sip.livekit.cloud" port: 5060 transport: "SIP_TRANSPORT_UDP" } callDirection: "SCD_INBOUND" callStatus: "SCS_ERROR" createdAtNs: "1758556007687716872" endedAtNs: "1758556007688887589" error: "invalid credentials were provided" }
t
It looks like the error message "invalid credentials were provided" is pointing to a little hiccup with the authentication details for your SIP trunk. No worries—let’s walk through some steps together to get this sorted out: 1. Verify SIP Trunk Credentials: Please double-check that the
auth_username
and
auth_password
in your LiveKit inbound trunk configuration exactly match the credentials you’ve set in your TwiML Bin or Twilio SIP trunk. 2. Check TwiML Bin Configuration: Take a moment to ensure the SIP URI in your TwiML Bin includes the right username and password, something like:
Copy code
<sip username="your_username" password="your_password">
  <sip:your_number@your-sip-domain.liveki>t.cloud
</sip>
3. Inspect LiveKit Trunk: You can use the LiveKit CLI or UI to review your inbound trunk settings. Make sure your phone number is in E.164 format and that all credentials are entered correctly. 4. Test Authentication: If you have a SIP client handy (like Zoiper), give the credentials a quick test to see if they connect properly with the LiveKit SIP URI. If you’d like, I’m here to help you verify or update any of these configurations—just let me know!
a
please verify or update
{ "sipTrunkId": "ST_TbMM7Ysu3juJ", "name": "My inbound trunk", "numbers": [ "+18384488081" ], "authUsername": "aditya", "authPassword": "password", "krispEnabled": true } { "sipDispatchRuleId": "SDR_uLfKFQhokDQS", "rule": { "dispatchRuleIndividual": { "roomPrefix": "call-" } }, "name": "My Rule", "roomConfig": { "agents": [ { "agentName": "simple-agent" } ] } } i have provided you code , inbound trunk, dispatch rule
{ "sipTrunkId": "ST_TbMM7Ysu3juJ", "name": "My inbound trunk", "numbers": [ "+18384488081" ], "authUsername": "aditya", "authPassword": "password", "krispEnabled": true } { "sipDispatchRuleId": "SDR_uLfKFQhokDQS", "rule": { "dispatchRuleIndividual": { "roomPrefix": "call-" } }, "name": "My Rule", "roomConfig": { "agents": [ { "agentName": "simple-agent" } ] } }