Dial SIP Phone URI with custom headers/params.
# support
d
Hey, we want to use Vapi with SIP telephony, but we have an issue as we try to correlate our Call with Vapi Call. We create a SIP phone for agent with some specific URI for example: sip:5aafd131-74fc-4bf8-8b67-08ec9e54c3fd@sip.vapi.ai. To connect the call we just dial this endpoint from our telephony infrastructure. The problem is that we do not have Vapi Call ID at this point and we can not propagate our own call ID in SIP URI. As a result it is hard to correlate our Call to VAPI call. We found workaround, but it is not very nice. We were thinking if it is possible to pass some values though SIP URI as we dial it? Something like this: sip:5aafd131-74fc-4bf8-8b67-08ec9e54c3fd@sip.vapi.ai;our_call_id=call_id_1 We tried this, but unfortunately we don't see this value anywhere in the webhooks Call ID of our test call: 974d4e99-9dee-4466-ae69-2e0ca4f23903 Thanks in advance
s
@User Looking at your specific issue, I understand that you want to correlate your telephony system's Call ID with Vapi's Call ID when making SIP calls. You tried adding a parameter to the SIP URI like sip:5aafd131-74fc-4bf8-8b67-08ec9e54c3fd@sip.vapi.ai;our_call_id=call_id_1 but don't see this value in webhooks. The root of your problem is how SIP URIs are processed by Vapi. 1. SIP URIs are parsed in a very specific way, primarily extracting the username and domain portions 2. The URI parameters (like ;our_call_id=call_id_1) are not specifically handled or extracted in the current implementation ## Understanding the Current Implementation From the code analysis, Vapi's SIP URI handling works like this: 1. When a SIP call comes in, Vapi extracts basic information from the URI using. 2. The current implementation primarily focuses on the username portion before the @ and the domain after it 3. The extractVariableValues function is used to extract custom values, but only from SIP headers (not URI parameters). It extracts values only from headers that start with "X-" or "x-", not from URI parameters. ## Solution The best solution is to use custom SIP headers instead of URI parameters. Based on the code, Vapi is set up to extract and pass custom values from SIP headers that start with "X-". Instead of:
Copy code
sip:5aafd131-74fc-4bf8-8b67-08ec9e54c3fd@sip.vapi.ai;our_call_id=call_id_1
Use a custom header in your SIP INVITE request:
Copy code
X-Our-Call-ID: call_id_1
This custom header will be extracted and passed to the assistant as a variable value, which you can then access in your webhooks or assistant logic. For your specific test call ID (974d4e99-9dee-4466-ae69-2e0ca4f23903), you could set:
Copy code
X-Our-Call-ID: 974d4e99-9dee-4466-ae69-2e0ca4f23903
We will extract it and make it available as our_call_id in the variableValues object passed to the assistant. ## Accessing SIP Headers as Dynamic Variables Once you've sent custom SIP headers, they become available as dynamic variables throughout the Vapi ecosystem: 1. In Assistant Prompts: You can access them directly using template syntax like:
Copy code
Your call ID from your system is: {{our_call_id}}
2. In Webhook Payloads: All your custom SIP headers are included in webhook payloads as part of the variableValues object, making them accessible in: - Call start events - End of call reports - Transcription events - Server events of all types - Status updates 3. In Call Metadata: The headers are stored with the call and maintained throughout the call lifecycle This approach gives you a reliable way to correlate your internal call IDs with Vapi calls across your entire integration.
d
Hey @Shubham Bajaj, thanks for a very detailed answer! We tried this approach and it works, thanks!
k
Marking this ticket as Solved ✅