For AI agents: a documentation index is available at the root level at /llms.txt and /llms-full.txt. Append /llms.txt to any URL for a page-level index, or .md for the markdown version of any page.
WebsiteStatusSupportDashboard
DocumentationAPI ReferenceMCPSDKsCLI (new)What's New?
DocumentationAPI ReferenceMCPSDKsCLI (new)What's New?
  • Get started
    • Introduction
    • Phone calls
    • Web calls
    • Vapi Guides
    • Composer
    • CLI quickstart
  • Assistants
    • Quickstart
    • Tools
    • Custom keywords
    • Custom voices
    • Custom transcriber
    • Custom TTS
  • Observability
    • Boards
  • Squads
    • Quickstart
    • Overview
    • Handoff tool
    • Passing data between assistants
  • Best practices
    • Prompting guide
    • Debugging voice agents
    • Enterprise environments (DEV/UAT/PROD)
    • IVR navigation
  • Phone numbers
    • Free Vapi number
    • Inbound SMS
      • SIP telephony
      • SIP trunking
      • Networking and firewall
        • Twilio
        • Telnyx
        • Zadarma
        • Plivo
        • Amazon Chime SDK
      • Troubleshoot SIP trunk credential errors
    • Phone Number Hooks
  • Calls
    • Call end reasons
    • Troubleshoot call errors
  • Outbound Campaigns
    • Quickstart
    • Overview
  • Chat
    • Quickstart
    • Streaming
    • Non-streaming
    • OpenAI compatibility
    • Session management
    • Variable substitution
    • SMS chat
    • Web widget
    • Webhooks
  • Workflows
    • Quickstart
    • Overview
LogoLogo
WebsiteStatusSupportDashboard
On this page
  • Outbound Calls (Twilio to Vapi)
  • Twilio Configuration
  • Vapi Configuration
  • Inbound Calls (Vapi to Twilio)
  • Twilio Configuration
  • Vapi Configuration
Phone numbersSIP integrationProviders

Twilio SIP Integration

How to integrate Twilio SIP with Vapi
Was this page helpful?
Edit this page
Previous

Telnyx SIP integration

How to integrate SIP Telnyx to Vapi
Next
Built with

This guide walks you through setting up both outbound and inbound SIP trunking between Twilio and Vapi. The steps are quite similar for other telephony providers.

Outbound Calls (Twilio to Vapi)

Twilio Configuration

  1. Create Elastic SIP Trunk

    Log in to your Twilio account and create a new trunk, assigning it a name, and adjusting the general settings as needed.

    Twilio SIP Trunk

  2. Set Up Termination (Outbound Calls)

    Configure the termination settings. The termination SIP URI is crucial as it will be used in later steps.

    Termination SIP URI

    To allow your Elastic SIP Trunk to accept outbound requests, you need to whitelist IP addresses:

    IP Authentication

    Whitelist Vapi’s SIP server static IPs:

    • 44.229.228.186
    • 44.238.177.138

    Ensure you whitelist the entire IP range as shown below:

    IP Whitelist 1

    IP Whitelist 2

  3. Purchase or Move Numbers to Elastic SIP Trunk

    After creating the Elastic SIP trunk, purchase new numbers or move existing numbers to this trunk.

    Number Attachment

Vapi Configuration

  1. Retrieve Your Vapi API Key

    Log in to your Vapi.ai account and retrieve your API key from the Organization Settings.

  2. Create a SIP Trunk Credential

    Use the following API call to create a SIP trunk credential, replacing the gateway IP with your Twilio Termination SIP URI:

    $curl -X POST https://api.vapi.ai/credential \
    >-H "Content-Type: application/json" \
    >-H "Authorization: Bearer YOUR_VAPI_API_KEY" \
    >-d '{
    > "provider": "byo-sip-trunk",
    > "name": "Twilio Trunk",
    > "gateways": [
    > {
    > "ip": "YOUR_TWILIO_GATEWAY_ID",
    > "inboundEnabled": false
    > }
    > ],
    > "outboundLeadingPlusEnabled": true
    >}'

    Note the id (credentialId) from the response for the next step.

  3. Register Your Phone Number

    Associate your Twilio number with the SIP trunk:

    $curl -X POST https://api.vapi.ai/phone-number \
    >-H "Content-Type: application/json" \
    >-H "Authorization: Bearer YOUR_VAPI_API_KEY" \
    >-d '{
    > "provider": "byo-phone-number",
    > "name": "Twilio SIP Number",
    > "number": "YOUR_SIP_PHONE_NUMBER",
    > "numberE164CheckEnabled": false,
    > "credentialId": "YOUR_CREDENTIAL_ID"
    >}'

    Note the phone number ID from the response for making calls.

  4. Make Outbound Calls

    You can make outbound calls in two ways:

    Using the Vapi Dashboard:

    The phone number will appear in your dashboard. Select your assistant and enter the destination number you want to call.

    Using the API:

    $curl --location 'https://api.vapi.ai/call/phone' \
    >--header 'Authorization: Bearer YOUR_VAPI_API_KEY' \
    >--header 'Content-Type: application/json' \
    >--data '{
    > "assistantId": "YOUR_ASSISTANT_ID",
    > "customer": {
    > "number": "DESTINATION_PHONE_NUMBER",
    > "numberE164CheckEnabled": false
    > },
    > "phoneNumberId": "YOUR_PHONE_NUMBER_ID"
    >}'

Inbound Calls (Vapi to Twilio)

Twilio Configuration

  1. Set Up Origination (Inbound Calls)

    Navigate to the Origination section in your Twilio SIP Trunk settings.

    Origination Settings

    Add your Vapi SIP URI in the following format: sip:YOUR_PHONE_NUMBER@<credential_id>.sip.vapi.ai, where “YOUR_PHONE_NUMBER” is your chosen SIP number that you will attach to this trunk.

    Origination Creation

Vapi Configuration

  1. Create and Configure a Vapi Assistant

    • Create an assistant following the steps in our Phone Quickstart
    • In the assistant settings, link it to the phone number you created

    Now when someone calls your Twilio number, the call will be routed to your Vapi assistant.