What is SIP?

SIP (Session Initiation Protocol) is a signalling protocol used to establish, manage, and terminate communication sessions over IP networks. It is widely used for real-time communication, including voice and video calls.


Key Concepts in SIP

  1. Call Origination:

    Refers to receiving inbound calls. It involves setting up and managing phone numbers, enabling calls from traditional PSTN or IP-based networks to reach your system.

    Example: If your SIP provider has assigned the number +14155552671 to your SIP trunk, inbound calls to this number will be routed to your configured Vapi system.

  2. Call Termination:

    Refers to outbound calls routed from your system to the recipient’s network. This requires configurations for routing and managing call quality.

    Example: A user in your system places a call to +442071838750. The call is routed from Vapi through your SIP provider to the intended recipient.


Setup Requirements

From the Vapi Side

  1. Create a SIP URI: Use the Vapi API to generate a SIP URI. Example:

    curl --location '<https://api.vapi.ai/phone-number>' \\
    --header 'Authorization: Bearer your-vapi-private-api-key' \\
    --header 'Content-Type: application/json' \\
    --data-raw '{
        "provider": "vapi",
        "sipUri": "<sip:[email protected]>",
        "assistantId": "your-assistant-id"
    }'
    
    

    Replace placeholders with your details:

    Upon completion, a SIP URI like sip:[email protected] will be generated. Inbound calls to this URI will trigger actions in Vapi.

  2. Configure Webhooks (Optional): If you want call requests sent to a webhook instead of a specific assistant, update the SIP URI with your webhook:

    curl --location --request PATCH '<https://api.vapi.ai/phone-number/id>' \\
    --header 'Content-Type: application/json' \\
    --header 'Authorization: Bearer your-vapi-private-api-key' \\
    --data '{
        "assistantId": null,
        "serverUrl": "https://your_server_url"
    }'
    
    

    When an inbound call is received, the webhook https://myserver.com/call-handler will be triggered.

  3. Set Up Outbound Call Credentials: Define the connection between Vapi and your SIP provider using a credential:

    curl -X POST <https://api.vapi.ai/credential> \\
    -H "Content-Type: application/json" \\
    -H "Authorization: Bearer your-private-key" \\
    -d '{
        "provider": "byo-sip-trunk",
        "name": "SIP Provider Name",
        "gateways": [{"ip": "provider-gateway"}]
    }'
    
    

    Replace placeholders with:

  4. Link Phone Numbers to SIP Trunk: Associate phone numbers with the SIP trunk for inbound or outbound calls:

    curl -X POST <https://api.vapi.ai/phone-number> \\
    -H "Content-Type: application/json" \\
    -H "Authorization: Bearer your-private-key" \\
    -d '{
        "provider": "byo-phone-number",
        "name": "SIP Number",
        "number": "your-sip-phone-number",
        "credentialId": "your-credential-id-which-you-got-from-previous-step"‬
    ‭    "numberE164CheckEnabled": false‬
    }'
    
    

    Replace placeholders with:


From the SIP Provider Side

  1. Inbound Configuration:

  2. Outbound Configuration:

  3. Number Assignment:

  4. SIP Domain and Invite Setup: