VOICE / connect-twilio-elastic-sip-trunk-to-xai

Voice

Connect a Twilio Elastic SIP trunk to xAI

Point a Twilio Elastic SIP Trunk at SpaceXAI so a Twilio number can deliver inbound calls into a registered Direct SIP line for Speech to Speech. Official SIP Phone Calls documents the Twilio path under Telephony providers: create a trunk, set the origination URI to sip:{number}@sip.voice.x.ai;transport=tls, assign a Twilio phone number, and enable call transfer on the trunk when your app uses mid-call refer. The destination {number} is the Direct SIP phone number you registered with SpaceXAI (BYO trunk), not a random Twilio string.

What you need

You need a Twilio account with Elastic SIP Trunking access, a Twilio phone number (or a purchase ready to attach), and a SpaceXAI phone-number registration whose E.164 matches the {number} in the origination URI — typically from Register a BYO SIP phone number. If you configured allowed_addresses on create, add Twilio’s SIP signaling CIDRs so INVITEs pass. Neighboring jobs include Handle SIP phone calls with Speech to Speech for webhook verification and WebSocket join, Transfer a SIP call with refer when you escalate mid-call, and Hang up a SIP call for app-owned teardown; more voice jobs live on the Voice hub.

Configure the Twilio trunk

Follow the staff Twilio checklist in order. In the Twilio Console, open Voice → Elastic SIP Trunking and create a trunk. Open the trunk’s Origination settings and add this origination URI, substituting your registered Direct SIP number for {number}: sip:{number}@sip.voice.x.ai;transport=tls. Assign a Twilio phone number to the trunk, or purchase a new number and attach it. If your application transfers calls mid-session with refer, enable call transfer on the trunk so the carrier allows REFER.

Keep transport set to TLS as shown in the URI, and keep the SpaceXAI host as sip.voice.x.ai from the guide. After origination is saved, place a test call to the Twilio number and confirm your webhook receives realtime.call.incoming with a call_id you can join on the realtime WebSocket.

Align SpaceXAI registration and transfers

The E.164 on POST /v2/phone-numbers (BYO) should be the number your carrier and Twilio path deliver toward SpaceXAI. When allowed_addresses is set, include Twilio signaling ranges or INVITEs are rejected before your webhook fires. Mid-call refer to a Twilio SIP Domain can include URI parameters on the sip: target_uri; the SIP FAQ states custom SIP headers are not sent on REFER, so enable Twilio trunk call transfer when you rely on that path.

Pitfalls

Pointing origination at a number you never registered on SpaceXAI yields unanswered INVITEs. Using transport=udp or omitting sip.voice.x.ai breaks the documented TLS route. Forgetting trunk call-transfer while your agent posts refer leaves mid-call escalations failing at the carrier. Treating Twilio attachment alone as Speech to Speech setup skips webhook signing verification and the call_id WebSocket join required after realtime.call.incoming.