In this guide, we will show how to integrate Retell AI with your telephony providers and use your numbers. You can use your own telephony setup with both Retell LLM or Custom LLM.

We will provide two ways to integrate with your telephony provider:

  1. Elastic SIP trunking: This is the recommended way to integrate with your telephony provider that supports elastic SIP trunking. You will need to set up a SIP trunking and configure your number to point to it, and then import that number to Retell.
  2. Dial to SIP Endpoint: If your telephony provider does not support elastic SIP trunking, or you have more complicated telephony setup that cannot use elastic SIP trunking, you can dial the call to a specific SIP endpoint.
  • Retell SIP server uri: sip:5t4n6j0wnrl.sip.livekit.cloud
  • If inbound does not work (might be due to initial SDP being dropped), specify to use TCP as the transport protocol: sip:5t4n6j0wnrl.sip.livekit.cloud;transport=tcp

Elastic SIP Trunking is a service offered by cloud communications platforms that enables organizations to connect their existing PBX (Private Branch Exchange) or VoIP (Voice over IP) infrastructure to the Public Switched Telephone Network (PSTN) over the internet using the SIP (Session Initiation Protocol).

In this context, the elastic SIP trunking is used to connect Retell’s VoIP with PSTN so that your agents can make and receive calls.

Here’re detailed guides for some telephony providers. SIP trunking is a popular service offered by many telephony providers, so most likely your telephony provider would be able to support this.

1

Create Elastic SIP Trunking

  1. Create the trunk, give it a name, and toggle some general settings
  1. Setup termination (this is for outbound)
  • the termination SIP URI here is important, we would use it in later steps
  • For your elastic SIP trunk to accept our outbound request, you need to whitelist IP address or create a auth with username and password.
    • If you opt for the auth route, you need to specify the username and password in the next step when importing the number to Retell.
    • Currently Retell SIP server does not have a static IP, so if you opt for the IP route, you need to whitelist all the IP addresses in the range like following:
  1. Setup origination (this is for inbound)
  • Here you will specify Retell’s SIP server address as the origination SIP URI: sip:5t4n6j0wnrl.sip.livekit.cloud. If you wish to use toll free numbers, you need to specify sip:5t4n6j0wnrl.sip.livekit.cloud;transport=tcp to use TCP as the transport protocol.
2

Move numbers to Elastic SIP Trunking

You’ve created the elastic SIP trunk, now you would need to purchase numbers / move existing numbers to this trunk.

3

Import numbers to Retell

Now the number is set up with your elastic SIP trunking, you need to import the number to Retell so that we will know how to route the call.

Here you will supply the termination SIP URI you set up in Step 1. If you have set up auth via credentials, you will need to supply the username and password as well.

You can also import number programmatically via Import Number API.

Now the number is imported, you can make and receive calls with this number just like a number you purchased from Retell — it will show up in your dashboard, and you can make phone calls from Dashboard directly. You can also use the Create Phone Call API to create calls programmatically. If you wish to Retell to stop using this number, you can delete it from the dashboard or via the Delete Number API.

Method 2: Dial to SIP Endpoint

If your telephony provider does not support elastic SIP trunking, or you have more complicated telephony setup that cannot use elastic SIP trunking, you can use this method.

When using this method, Retell does not directly make or receive calls, but instead relies on your system to dial the call to the respective SIP endpoint. This would require you to have some codes to handle integration with your telephony provider. All traffic looks like inbound to Retell in this case, so it’s up to you to specify the call direction.

Here we assume you already have your call handling setup.

For Retell to know what agent to use to handle the call, and for you to obtain SIP endpoint to use for this call, you would call the Register Phone Call API. You will get a call_id back from this API, and you would use it to piece together the SIP endpoint.

SIP endpoint: sip:{call_id}@5t4n6j0wnrl.sip.livekit.cloud

Example Code

Here’s an overly simplified example code to handle the inbound call webhook from Twilio and dialing the call to the SIP endpoint.

Node
const client = new Retell({
  apiKey: 'YOUR_RETELL_API_KEY',
});

server.app.post(
  "/voice-webhook",
  async (req: Request, res: Response) => {
    // Register the phone call to get call id
    const phoneCallResponse = await client.call.registerPhoneCall({
      agent_id: 'oBeDLoLOeuAbiuaMFXRtDOLriTJ5tSxD',
      from_number: "+12137771234", // optional
      to_number: "+12137771235", // optional
      direction: "inbound", // optional
    });

    // Start phone call websocket
    const voiceResponse = new VoiceResponse();
    const dial = voiceResponse.dial();
    dial.sip(
      `sip:${phoneCallResponse.call_id}@5t4n6j0wnrl.sip.livekit.cloud`,
    );
    res.set("Content-Type", "text/xml");
    res.send(voiceResponse.toString());
  },
);