Nomadiction
05/08/2026, 9:20 PMRefer-To built from wrong gateway
Following up on this thread (the hybrid gateway workaround suggested here is what led us to this bug).
[Setup (as recommended by Vapi support in this thread):](https://discord.com/channels/1211482211119796234/1494130355660259408)
{
"provider": "byo-sip-trunk",
"name": "Twilio SIP Trunk",
"gateways": [
{
"ip": "<our-fqdn>.pstn.twilio.com",
"inboundEnabled": false,
"outboundEnabled": true
},
{
"ip": "54.172.60.0",
"inboundEnabled": true,
"outboundEnabled": false
}
],
"outboundAuthenticationPlan": {
"authUsername": "vapi"
},
"outboundLeadingPlusEnabled": true
}
Bug:
When a transfer is triggered, Vapi sends a SIP REFER to Twilio. The Refer-To URI is constructed using the inbound gateway's IP and the ephemeral TLS rport of the active session — not the configured outbound FQDN. Twilio receives the REFER, tries to route to a nonexistent ephemeral port, and returns 403 Forbidden.
Reproduced from our own SIP traces:
# Twilio's inbound Via header (note rport=):
Via: SIP/2.0/TLS 54.172.60.1:5061;branch=...;rport=
# Vapi's REFER — Refer-To picks up that IP and rport:
Refer-To: <sip:+@54.172.60.1:> ← WRONG
# Expected:
Refer-To: <sip:+@.pstn.twilio.com> ← should use outbound gateway FQDN
The ephemeral port is the TLS source port Twilio used for the inbound connection — it's gone by the time the REFER is processed. This makes every single transfer fail.Nomadiction
05/08/2026, 9:20 PMVapi Support Bot
05/08/2026, 9:21 PM