This guide shows you how to add and modify Diversion headers before the call hits your Voice AI stack and during an active session, so you can feed richer context into prompts and actions without breaking SIP etiquette.
SIP headers:
Diversion headers:
Inbound Call → SIP receives INVITE.
Diversion Header Injected (Pre‑Call) by SIP, CRM webhook, or lambda function.
Assistant Selection based on Diversion metadata.
Re‑INVITE / UPDATE (Mid‑Call) optionally tweaks Diversion to reflect new context (e.g. agent transfer, escalation).
Voice AI consumes the latest Diversion value at each turn; variables automatically update inside prompts.
<diversion> is the special variable you can call into a before the call or during the call action.Use an API‑based action that your SBC or middleware hits before its forwards the INVITE to the assistant.
Method: POST
Trigger flag: run_action_before_call_start = true
Request body must include:
Return: a JSON object whose keys match your prompt variables.
<sip:+14155550199@caller.net>;tag=9fxced76sl
To: <sip:+12065551234@voice.example.com>
X-Diversion: <sip:+15559876543@acmebank>;reason=unconditional;privacy=off;brand=AcmeBank;journey_stage=loan‑apps
Contact: <sip:+12065551234@203.0.113.5>
Content‑Length: 0Every key (brand, journey_stage, etc.) mirrors the variable names in your prompt/template.
Best Practices & Gotchas Don’t rename keys casually. If you change customer_tier to loyalty, update the header and every prompt variable.
Stick to alphanumerics in sub‑parameter names; some SBCs choke on funky characters.
Size matters. Keep the header under ~1 KB or risk fragmentation on UDP.
Chain of custody. When another platform adds its own Diversion, keep yours last so you always know which index to read.
Security. Encrypt sensitive tags (e.g. account IDs) or push them via secure SIP‑TLS trunks.
Benefits Recap