|
| 1 | +--- |
| 2 | +title: VAPI Inbound Calling |
| 3 | +sidebar_label: Inbound Calls |
| 4 | +slug: /ai/guides/integrations/vapi/inbound-calls |
| 5 | +description: Route incoming calls from SignalWire phone numbers to VAPI AI assistants using SIP trunking |
| 6 | +--- |
| 7 | + |
| 8 | +import Admonition from '@theme/Admonition'; |
| 9 | +import { Card, CardGroup } from "@site/src/components/Extras/Card"; |
| 10 | +import { LiaPhoneSolid, LiaCodeSolid, LiaBookSolid, LiaToolsSolid } from "react-icons/lia"; |
| 11 | + |
| 12 | +[signup]: https://signalwire.com/signup |
| 13 | +[vapi]: https://dashboard.vapi.ai/ |
| 14 | +[vapi-sip-guide]: https://docs.vapi.ai/advanced/sip/sip-trunk |
| 15 | +[sw-firewall-guide]: /voice/getting-started/sip/allowing-signalwire-ips-through-your-firewall/ |
| 16 | +[resources]: https://my.signalwire.com?page=resources |
| 17 | +[swml-guide]: /swml/ |
| 18 | +[outbound-calls]: /ai/guides/integrations/vapi/outbound-calls |
| 19 | +[swml-guides]: /swml/guides |
| 20 | +[ai-best-practices]: /ai/guides/best-practices |
| 21 | + |
| 22 | + |
| 23 | +<Subtitle>Route incoming calls to your VAPI AI assistants using SignalWire's phone network</Subtitle> |
| 24 | + |
| 25 | +VAPI provides powerful AI voice assistants, but these assistants need phone numbers to receive calls. SignalWire's phone network can route incoming calls directly to your VAPI assistants using SIP trunking. This guide shows you how to connect them. |
| 26 | + |
| 27 | +When you're finished, callers will dial your SignalWire phone number and immediately connect to your VAPI AI assistant - no additional routing or servers needed. |
| 28 | + |
| 29 | +## Setup overview |
| 30 | + |
| 31 | +<Steps> |
| 32 | + |
| 33 | +### Configure VAPI for SignalWire |
| 34 | + |
| 35 | +Set up a SIP trunk with SignalWire's IP addresses and register your phone number. |
| 36 | + |
| 37 | +### Create call routing in SignalWire |
| 38 | + |
| 39 | +Build a SWML script that forwards incoming calls to your VAPI assistant. |
| 40 | + |
| 41 | +### Connect and test |
| 42 | + |
| 43 | +Assign the routing script to your phone number and verify calls reach your AI assistant. |
| 44 | + |
| 45 | +</Steps> |
| 46 | + |
| 47 | +## What you'll need |
| 48 | + |
| 49 | +- A SignalWire account with at least one phone number ([sign up here][signup]) |
| 50 | +- A [VAPI][vapi] account with API access |
| 51 | +- Your VAPI private API key (found in your VAPI dashboard) |
| 52 | + |
| 53 | +## Setting up VAPI to receive SignalWire calls |
| 54 | + |
| 55 | +VAPI needs to know that calls will be coming from SignalWire's network. We'll create a SIP trunk that includes all of SignalWire's IP addresses, then register your phone number with that trunk. |
| 56 | + |
| 57 | +This follows VAPI's official [SIP trunk setup guide][vapi-sip-guide], but with SignalWire-specific configuration. |
| 58 | + |
| 59 | +### Create the SIP trunk |
| 60 | + |
| 61 | +Run the API call below to create the trunk, making sure to replace `YOUR_VAPI_PRIVATE_KEY` with your actual API key. |
| 62 | + |
| 63 | +Save the `id` from the response - you'll need this credential ID for the next step. |
| 64 | + |
| 65 | +:::warning Important: Keep IPs updated |
| 66 | +These IP addresses are current as of this guide's publication, but SignalWire IPs can change and should be programmatically monitored to avoid any impact on calls. You can gather SignalWire's latest IPs by performing a DIG or nslookup of `sip.signalwire.com`. |
| 67 | + |
| 68 | +See our guide on [allowing SignalWire IPs through firewalls][sw-firewall-guide] for more details. |
| 69 | +::: |
| 70 | + |
| 71 | +```bash |
| 72 | +curl -X POST "https://api.vapi.ai/credential" \ |
| 73 | + -H "Content-Type: application/json" \ |
| 74 | + -H "Authorization: Bearer YOUR_VAPI_PRIVATE_KEY" \ |
| 75 | + -d '{ |
| 76 | + "provider": "byo-sip-trunk", |
| 77 | + "name": "SignalWire Inbound Trunk", |
| 78 | + "gateways": [ |
| 79 | + { "ip": "170.64.128.96" }, |
| 80 | + { "ip": "198.13.56.186" }, |
| 81 | + { "ip": "104.248.176.184" }, |
| 82 | + { "ip": "152.42.144.114" }, |
| 83 | + { "ip": "104.248.150.114" }, |
| 84 | + { "ip": "138.68.125.160" }, |
| 85 | + { "ip": "159.65.244.171" }, |
| 86 | + { "ip": "167.99.198.84" }, |
| 87 | + { "ip": "13.245.35.235" }, |
| 88 | + { "ip": "108.61.169.31" }, |
| 89 | + { "ip": "137.184.4.155" }, |
| 90 | + { "ip": "188.166.126.7" }, |
| 91 | + { "ip": "139.59.34.94" }, |
| 92 | + { "ip": "165.232.186.228" }, |
| 93 | + { "ip": "157.175.131.128" } |
| 94 | + ] |
| 95 | + }' |
| 96 | +``` |
| 97 | + |
| 98 | + |
| 99 | +### Register your SignalWire phone number |
| 100 | + |
| 101 | +Now register your SignalWire phone number with VAPI using the credential ID from above: |
| 102 | + |
| 103 | +```bash |
| 104 | +curl -X POST "https://api.vapi.ai/phone-number" \ |
| 105 | + -H "Content-Type: application/json" \ |
| 106 | + -H "Authorization: Bearer YOUR_VAPI_PRIVATE_KEY" \ |
| 107 | + -d '{ |
| 108 | + "provider": "byo-phone-number", |
| 109 | + "name": "SignalWire Inbound Number", |
| 110 | + "number": "+15551234567", |
| 111 | + "numberE164CheckEnabled": true, |
| 112 | + "credentialId": "YOUR_CREDENTIAL_ID" |
| 113 | + }' |
| 114 | +``` |
| 115 | + |
| 116 | +Make sure to replace: |
| 117 | +- `YOUR_VAPI_PRIVATE_KEY` with your actual API key |
| 118 | +- `+15551234567` with your SignalWire phone number in E.164 format (including the + and country code) |
| 119 | +- `YOUR_CREDENTIAL_ID` with the credential ID from the previous step |
| 120 | + |
| 121 | +### Assign your AI assistant |
| 122 | + |
| 123 | +In your VAPI dashboard, find the phone number you just registered and assign it to one of your AI assistants. You'll only need to configure the inbound settings - we're not using this number for outbound calls. |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## Configuring SignalWire to route calls |
| 128 | + |
| 129 | +Now we need to tell SignalWire where to send incoming calls. We'll create a simple SWML script that forwards calls to your VAPI assistant. |
| 130 | + |
| 131 | +### Create the routing script |
| 132 | + |
| 133 | +In your SignalWire dashboard, go to [**Resources**][resources] → **Add** → **Script** → **SWML Script**. This script will handle all incoming calls by immediately connecting them to VAPI: |
| 134 | + |
| 135 | +```yaml andJSON |
| 136 | +version: 1.0.0 |
| 137 | +sections: |
| 138 | + main: |
| 139 | + - connect: |
| 140 | + to: 'sip:%{call.to}@YOUR_CREDENTIAL_ID.sip.vapi.ai' |
| 141 | +``` |
| 142 | +
|
| 143 | +Replace `YOUR_CREDENTIAL_ID` with the credential ID from the VAPI trunk setup above. The `%{call.to}` variable ensures VAPI receives the original dialed number, which helps with call routing and analytics. |
| 144 | + |
| 145 | +:::info Understanding SWML |
| 146 | +This SWML script uses the `connect` method to bridge the incoming call directly to VAPI's SIP endpoint. |
| 147 | +The call happens in real time with no delays. Learn more about SWML in our [complete guide][swml-guide]. |
| 148 | +::: |
| 149 | + |
| 150 | +### Connect the script to your phone number |
| 151 | + |
| 152 | +Go to **Phone Numbers** in your SignalWire dashboard, find your number, and click **Edit Settings**. Under the voice settings, assign your new SWML script to handle incoming calls. |
| 153 | + |
| 154 | +That's it - your phone number is now connected to your VAPI assistant. |
| 155 | + |
| 156 | +--- |
| 157 | + |
| 158 | +## Testing and troubleshooting |
| 159 | + |
| 160 | +Call your SignalWire phone number and you should hear your VAPI assistant answer within a few seconds. |
| 161 | + |
| 162 | +If something isn't working, here are the most common issues: |
| 163 | + |
| 164 | +**Calls aren't reaching VAPI**: Check that your SWML script has the correct credential ID and is assigned to your phone number. Also, verify that your phone number is set to accept voice calls. |
| 165 | + |
| 166 | +**VAPI can't connect**: Make sure all SignalWire IP addresses are in your VAPI trunk. If SignalWire has added new IP addresses since you created the trunk, you'll need to update it. |
| 167 | + |
| 168 | +**Wrong number format errors**: Phone numbers must be in E.164 format (`+1234567890`) with no spaces or special characters. |
| 169 | + |
| 170 | +You can monitor call logs in both platforms - SignalWire shows the initial call routing, while VAPI shows the assistant interaction details. |
| 171 | + |
| 172 | +--- |
| 173 | + |
| 174 | +## What's next |
| 175 | + |
| 176 | +Now that you have basic inbound routing working, you might want to explore: |
| 177 | + |
| 178 | +<CardGroup cols={3}> |
| 179 | + <Card |
| 180 | + title="Outbound Calling" |
| 181 | + href="/ai/guides/integrations/vapi/outbound-calls" |
| 182 | + icon={<LiaPhoneSolid />} |
| 183 | + > |
| 184 | + Let your VAPI assistant make outbound calls through SignalWire |
| 185 | + </Card> |
| 186 | + |
| 187 | + <Card |
| 188 | + title="Advanced Call Flows" |
| 189 | + href="/swml/guides" |
| 190 | + icon={<LiaCodeSolid />} |
| 191 | + > |
| 192 | + Add IVR menus, call screening, or business hours logic before connecting to VAPI |
| 193 | + </Card> |
| 194 | + |
| 195 | + <Card |
| 196 | + title="Assistant Optimization" |
| 197 | + href="/ai/guides/best-practices" |
| 198 | + icon={<LiaBookSolid />} |
| 199 | + > |
| 200 | + Best practices for creating effective VAPI assistants |
| 201 | + </Card> |
| 202 | +</CardGroup> |
0 commit comments