Configure Twilio Elastic SIP Trunking for OpenAI

Configure Twilio Elastic SIP Trunking

  1. Assign the phone number to your Twilio SIP trunk.
  2. Set the trunk’s Origination URI to:
sip:<OPENAI_PROJECT_ID>@sip.api.openai.com;transport=tls
  1. Use TLS on port 5061.
  2. Ensure <OPENAI_PROJECT_ID> matches the OpenAI project where the webhook is configured.
  3. Subscribe the OpenAI webhook endpoint to:
realtime.call.incoming

Troubleshooting Missing Events

If no webhook event appears, first inspect Twilio’s call logs and SIP response. A 4xx or 5xx response commonly indicates that::link: :sparkles:

Unitech Character with ChatGPT

  • The Request-URI sent to OpenAI does not contain the project ID.

  • TLS is not configured correctly.
  • The specified OpenAI project is incorrect.

Capture the outbound SIP INVITE and verify that its first line resembles:

INVITE sip:<OPENAI_PROJECT_ID>@sip.api.openai.com SIP/2.0

Also confirm that:

  • The webhook is a project-level OpenAI webhook, not a Twilio webhook.
  • The webhook endpoint is publicly reachable and returns a 2xx response quickly.
  • Webhook signature verification uses the unmodified raw request body.
  • The API key used to accept the call belongs to the same OpenAI project.

Accept the Incoming Call

After receiving the event, accept the call with:

POST /v1/realtime/calls/{call_id}/accept

If the call is not accepted, OpenAI will eventually reject or terminate it.

Request-URI Rewriting

If Twilio replaces the Request-URI user portion with the called E.164 phone number, route the call through either:

  • A TwiML <Sip> destination, or
  • An SBC that preserves the OpenAI project ID in the destination URI.:microscope: :rocket: :globe_showing_asia_australia: