Telnyx SIP Integration

How to integrate SIP Telnyx to Vapi

Inbound

On Vapi

1

Personalized origination SIP URI creation

First we will create a personalized origination SIP URI via the Vapi API

1curl --location 'https://api.vapi.ai/phone-number' \
2 --header 'Authorization: Bearer your-vapi-private-api-key' \
3 --header 'Content-Type: application/json' \
4 --data-raw '{
5 "provider": "vapi",
6 "sipUri": "sip:[email protected]",
7 "assistantId": "your-assistant-id"
8 }'
  • provider: This is set to “vapi”.
  • sipUri: Replace username with your desired SIP username.
  • assistantId: Provide your specific assistant ID associated with your Vapi AI account.
2

[Optional] Send call request to a webhook instead of assistant

Send a PATCH to /phone-number/your_phone_id

1 curl --location --request PATCH 'https://api.vapi.ai/phone-number/your_phone_id' \
2 --header 'Content-Type: application/json' \
3 --header 'Authorization: Bearer your-vapi-private-api-key' \
4 --data '{
5 "assistantId": null,
6 "serverUrl": "https://your_server_url"
7 }'
  • your_server_url is the webhook link that will receive the assistant request.
  • your_phone_id is the id of your just created origination sip URI

Now every time you make a call to this number (i.e. assigned numbers on SIP trunking to this origination URI), you’ll get a webhook event requesting an assistant.

On Telnyx

1

Setup inbound authentication

  1. Go to Voice / SIP Trunking / Create
  2. Select FQDN
  3. Select add FQDN
  4. Select A
  5. Add created SIP URI
  6. FQDN: sip.vapi.ai
  7. Port should be 5060 by default
2

Go to Inbound tab

Set as follows:

3

Assign your acquired phone number to SIP trunking

Go to numbers tab, assign number

4

Modify SIP invite

Modify SIP invite so your VAPI and Telnyx accounts will be matched correctly

  1. Go to numbers, edit the one your will be using
  2. Navigate do voice
  3. Scroll down till the end to find Translated Number

This setting will modify the SIP Invite to the vapi platform so invites are sent to your vapi sip URI. It will be whatever value you set when you created it.

  1. If your chosen sipURI from previous step is [email protected] , this should be username
  2. Done! You should now be receiving calls!

Outbound

On Telnyx

1

Set outbound authentication method

  1. Go to Voice / Sip Trunking / Authentication and routing
  2. Scroll down to outbound calls authentication and:
  • Add the two fixed IPs from VAPI, select Tech Prefix and create a unique 4-digits Tech Prefix (example 1234 - don’t use 1234, must be unique to your account)
2

Create outbound voice profiles

  1. Go to voice / outbound voice profiles
  2. Create profile
  3. Name it as you will (1. details)
  4. Allow as desired destination (2. destinations)
  5. Leave the next screen as is (3. configuration)
  6. Assign the desired sip trunk (4. …)
  7. Complete

Or you an just go to sip trunk / you sip trunk / outbound / and select your just created outbound voice profile.

3

Go to Outbound tab to select the country you'll be calling the most

Set as follows, choosing the country that you will be making most calls to (example Brazil)

We recommend creating a separate SIP Trunk for each country you aim to be making most calls to.

On Vapi

1

Create a SIP Trunk Credential through Vapi API

1curl -X POST https://api.vapi.ai/credential \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer your-vapi-private-api-key" \
4 -d '{
5 "provider": "byo-sip-trunk",
6 "name": "Telnyx Trunk",
7 "gateways": [
8 {
9 "ip": "sip.telnyx.com"
10 }
11 ]
12 }'
2

Create a Phone Number Associated with the SIP Trunk

1curl -X POST https://api.vapi.ai/phone-number \
2 -H "Content-Type: application/json" \
3 -H "Authorization: Bearer your-vapi-private-api-key" \
4 -d '{
5 "provider": "byo-phone-number",
6 "name": "Telnyx SIP Number",
7 "number": "your-sip-phone-number",
8 "numberE164CheckEnabled": false,
9 "credentialId": "your-new-trunk-credential-id-which-you-got-from-previous-step"
10 }'
3

Start making outbound calls

Use this cURL to trigger calls with tech prefix

1curl --location 'https://api.vapi.ai/call/phone' \
2 --header 'Authorization: Bearer your-vapi-private-api-key' \
3 --header 'Content-Type: application/json' \
4 --data '{
5 "assistantId": "your-assistant-id",
6 "customer": {
7 "number": "tech-prefix-with-phone-number-without-plus-signal",
8 "numberE164CheckEnabled": false
9 },
10 "phoneNumberId": "your-phone-id"
11}'

Example of tech-prefix-with-phone-number-without-plus-signal

  • Phone number: +6699999999
  • Tech Prefix: 1234
  • Should look like this: 12346699999999
  • No + as you can see

Done! Outbound should now be working!