Asterisk to OpenAI Realtime invite problem

Hi team,

we are connecting asterisk with openai realtime api.
where asterisk to whatsapp and whatsapp to asterisk we already did and it working live in production.

while we are connecting asterisk with openai realtime api we are faceing one Invite TO issue as openai realtime want like sip:$PROJECT_ID@sip.api.openai.com;transport=tls

but when are sending from asteirsk it send only sip:$PROJECT_ID@sip.api.openai.com
and after the “;“ everyting will be ignored by asteirsk

[Sep 4 13:40:23] <— Transmitting SIP request (992 bytes) to TLS:172.65.182.150:5061 —>
[Sep 4 13:40:23] INVITE sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com:5061 SIP/2.0
[Sep 4 13:40:23] Via: SIP/2.0/TLS 139.84.175.186:5061;rport;branch=z9hG4bKPj0ba14edc-d91c-48fe-a96e-a100105bcfe2;alias
[Sep 4 13:40:23] From: “+911214287400” sip:+911214287400@139.84.175.186;tag=70be2d1e-e3d0-428e-b3b1-33bc999c4413
[Sep 4 13:40:23] To: sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com
[Sep 4 13:40:23] Contact: sip:asterisk@139.84.175.186:5061;transport=TLS
[Sep 4 13:40:23] Call-ID: d45e8b25-eb2a-47a1-aed4-c3a3332ea941
[Sep 4 13:40:23] CSeq: 7635 INVITE
[Sep 4 13:40:23] Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, INFO, REFER
[Sep 4 13:40:23] Supported: 100rel, replaces, norefersub, histinfo
[Sep 4 13:40:23] Max-Forwards: 70
[Sep 4 13:40:23] User-Agent: openairealtimeapi.callanywhere.co.in
[Sep 4 13:40:23] Content-Type: application/sdp
[Sep 4 13:40:23] Content-Length: 239

as per requirement it should be
sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com;transport=tls

suggest us how to use asterisk to send this type of SIP URI in TO

Are you sure, what actually happens?

And what is the actual configuration?

its my pjsip.conf
[global]

type=global

default_realm=CALLANYWHERE

user_agent=openairealtimeapi.callanywhere.co.in

use_callerid_contact=no

debug=no

keep_alive_interval=90

endpoint_identifier_order=username,ip,anonymous,header,auth_username

taskprocessor_overload_trigger=pjsip_only

[system]

type=system

timer_t1=5000

timer_b=32000

compact_headers=no

disable_multi_domain=no

follow_early_media_fork=yes

accept_multiple_sdp_answers=yes

threadpool_initial_size=0

threadpool_auto_increment=5

threadpool_idle_timeout=60

threadpool_max_size=50

[general]

icesupport = yes

[transport-tls]

type=transport

protocol=tls

bind=0.0.0.0:5061

external_media_address=139.84.175.186

external_signaling_address=139.84.175.186

cert_file=/etc/asterisk/keys/asterisk.cert

priv_key_file=/etc/asterisk/keys/asterisk.key

method=tlsv1_2

verify_client=no

require_client_cert=no

allow_reload=yes

async_operations=1

[openai-realtime]

type=endpoint

transport=transport-tls

context=openai-context

aors=openai-realtime

disallow=all

allow=alaw

webrtc=no

media_encryption=no

use_avpf=no

rtcp_mux=no

ice_support=no

bundle=no

direct_media=no

rtp_symmetric=yes

force_rport=yes

rewrite_contact=yes

dtmf_mode=rfc4733

rtp_timeout=600

rtp_timeout_hold=1200

media_address=139.84.175.186

timers=no

trust_id_inbound=yes

trust_id_outbound=yes

send_connected_line=no

aggregate_mwi=no

t38_udptl=no

asymmetric_rtp_codec=yes

[openai-realtime]

type=aor

contact=sip:sip.api.openai.com:5061

remove_existing=yes

maximum_expiration=7200

minimum_expiration=60

qualify_frequency=0

max_contacts=1

; Identify configuration for OpenAI

[openai-realtime]

type=identify

endpoint=openai-realtime

match=sip.api.openai.com



and its my extension.conf

[inbound-test]

exten => _.,1,NoOp(Inbound Call from telephony ${CDR(src)} to ${CDR(dst)})

exten => _.,n,Set(TIMEOUT(absolute)=0) ; Remove absolute timeout

exten => _.,n,Set(TIMEOUT(response)=60) ; Allow time for connection

same => n,Dial(PJSIP/proj_ynVte2cOPDHsxBZ6IUbVRcQ7@openai-realtime,60,rg)

same => n,hangup

exten => h,1,hangup

when i dial i see on asterisk side
[Sep 4 15:15:56] == Using SIP RTP CoS mark 5
[Sep 4 15:15:56] > 0x7f43e8013230 – Strict RTP learning after remote address set to: 122.176.155.244:16152
[Sep 4 15:15:56] – Executing [+911213509215@inbound-test:1] NoOp(“SIP/openairealtime-00000005”, “Inbound Call from telephony +911214287400 to +911213509215”) in new stack
[Sep 4 15:15:56] – Executing [+911213509215@inbound-test:2] Set(“SIP/openairealtime-00000005”, “TIMEOUT(absolute)=0”) in new stack
[Sep 4 15:15:56] – Channel hangup cancelled.
[Sep 4 15:15:56] – Executing [+911213509215@inbound-test:3] Set(“SIP/openairealtime-00000005”, “TIMEOUT(response)=60”) in new stack
[Sep 4 15:15:56] – Response timeout set to 60.000
[Sep 4 15:15:56] – Executing [+911213509215@inbound-test:4] Dial(“SIP/openairealtime-00000005”, “PJSIP/proj_ynVte2cOPDHsxBZ6IUbVRcQ7@openai-realtime,60,rg”) in new stack
[Sep 4 15:15:56] – Called PJSIP/proj_ynVte2cOPDHsxBZ6IUbVRcQ7@openai-realtime
[Sep 4 15:15:56] <— Transmitting SIP request (992 bytes) to TLS:172.65.182.150:5061 —>
[Sep 4 15:15:56] INVITE sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com:5061 SIP/2.0
[Sep 4 15:15:56] Via: SIP/2.0/TLS 139.84.175.186:5061;rport;branch=z9hG4bKPj159a4ada-7846-420e-a692-11995f728116;alias
[Sep 4 15:15:56] From: “+911214287400” sip:+911214287400@139.84.175.186;tag=ac2b076a-48d3-4d46-ac92-ceeeb226add9
[Sep 4 15:15:56] To: sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com
[Sep 4 15:15:56] Contact: sip:asterisk@139.84.175.186:5061;transport=TLS
[Sep 4 15:15:56] Call-ID: 17e11e57-0915-487d-9599-ed7472ae6942
[Sep 4 15:15:56] CSeq: 2075 INVITE
[Sep 4 15:15:56] Allow: OPTIONS, REGISTER, SUBSCRIBE, NOTIFY, PUBLISH, INVITE, ACK, BYE, CANCEL, UPDATE, PRACK, MESSAGE, INFO, REFER
[Sep 4 15:15:56] Supported: 100rel, replaces, norefersub, histinfo
[Sep 4 15:15:56] Max-Forwards: 70
[Sep 4 15:15:56] User-Agent: openairealtimeapi.callanywhere.co.in
[Sep 4 15:15:56] Content-Type: application/sdp
[Sep 4 15:15:56] Content-Length: 239
[Sep 4 15:15:56]
[Sep 4 15:15:56] v=0
[Sep 4 15:15:56] o=- 166540146 166540146 IN IP4 139.84.175.186
[Sep 4 15:15:56] s=Asterisk
[Sep 4 15:15:56] c=IN IP4 139.84.175.186
[Sep 4 15:15:56] t=0 0
[Sep 4 15:15:56] m=audio 17128 RTP/AVP 8 101
[Sep 4 15:15:56] a=rtpmap:8 PCMA/8000
[Sep 4 15:15:56] a=rtpmap:101 telephone-event/8000
[Sep 4 15:15:56] a=fmtp:101 0-16
[Sep 4 15:15:56] a=ptime:20
[Sep 4 15:15:56] a=maxptime:140
[Sep 4 15:15:56] a=sendrecv
[Sep 4 15:15:56]
[Sep 4 15:15:57] <— Received SIP response (484 bytes) from TLS:172.65.182.150:5061 —>
[Sep 4 15:15:57] SIP/2.0 100 Trying
[Sep 4 15:15:57] Via: SIP/2.0/TLS 139.84.175.186:5061;received=172.69.203.193;rport=53174;branch=z9hG4bKPj159a4ada-7846-420e-a692-11995f728116;alias
[Sep 4 15:15:57] From: “+911214287400” sip:+911214287400@139.84.175.186;tag=ac2b076a-48d3-4d46-ac92-ceeeb226add9
[Sep 4 15:15:57] To: sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com;tag=be2462d1-c4b0-4de9-825f-1dcb2559562f
[Sep 4 15:15:57] Call-ID: 17e11e57-0915-487d-9599-ed7472ae6942
[Sep 4 15:15:57] CSeq: 2075 INVITE
[Sep 4 15:15:57] Content-Length: 0
[Sep 4 15:15:57] Contact: sip:OAI@sip.api.openai.com:5061
[Sep 4 15:15:57]
[Sep 4 15:15:57]
[Sep 4 15:16:00] <— Received SIP response (688 bytes) from TLS:172.65.182.150:5061 —>
[Sep 4 15:16:00] SIP/2.0 200 OK
[Sep 4 15:16:00] Via: SIP/2.0/TLS 139.84.175.186:5061;branch=z9hG4bKPj159a4ada-7846-420e-a692-11995f728116;received=172.69.203.193;alias;rport=53174
[Sep 4 15:16:00] From: “+911214287400” sip:+911214287400@139.84.175.186;tag=ac2b076a-48d3-4d46-ac92-ceeeb226add9
[Sep 4 15:16:00] To: sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com;tag=be2462d1-c4b0-4de9-825f-1dcb2559562f
[Sep 4 15:16:00] Call-ID: 17e11e57-0915-487d-9599-ed7472ae6942
[Sep 4 15:16:00] CSeq: 2075 INVITE
[Sep 4 15:16:00] Content-Length: 206
[Sep 4 15:16:00] Contact: sip:OAI@sip.api.openai.com:5061
[Sep 4 15:16:00]
[Sep 4 15:16:00] v=0
[Sep 4 15:16:00] o=- 166540146 166540148 IN IP4 52.247.123.134
[Sep 4 15:16:00] s=OAI
[Sep 4 15:16:00] c=IN IP4 52.247.123.134
[Sep 4 15:16:00] t=0 0
[Sep 4 15:16:00] m=audio 42920 RTP/AVP 8 101
[Sep 4 15:16:00] a=rtpmap:101 telephone-event/8000
[Sep 4 15:16:00] a=fmtp:101 0-16
[Sep 4 15:16:00] a=ptime:20
[Sep 4 15:16:00] a=rtpmap:8 PCMA/8000
[Sep 4 15:16:00]
[Sep 4 15:16:00] <— Transmitting SIP request (511 bytes) to TLS:172.65.182.150:5061 —>
[Sep 4 15:16:00] ACK sip:OAI@172.65.182.150:5061;transport=TLS SIP/2.0
[Sep 4 15:16:00] Via: SIP/2.0/TLS 139.84.175.186:5061;rport;branch=z9hG4bKPj4063bce8-3598-412e-932b-d9450e52aaa0;alias
[Sep 4 15:16:00] From: “+911214287400” sip:+911214287400@139.84.175.186;tag=ac2b076a-48d3-4d46-ac92-ceeeb226add9
[Sep 4 15:16:00] To: sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com;tag=be2462d1-c4b0-4de9-825f-1dcb2559562f
[Sep 4 15:16:00] Call-ID: 17e11e57-0915-487d-9599-ed7472ae6942
[Sep 4 15:16:00] CSeq: 2075 ACK
[Sep 4 15:16:00] Max-Forwards: 70
[Sep 4 15:16:00] User-Agent: openairealtimeapi.callanywhere.co.in
[Sep 4 15:16:00] Content-Length: 0
[Sep 4 15:16:00]
[Sep 4 15:16:00]
[Sep 4 15:16:00] <— Transmitting SIP request (571 bytes) to TLS:172.65.182.150:5061 —>
[Sep 4 15:16:00] BYE sip:OAI@172.65.182.150:5061;transport=TLS SIP/2.0
[Sep 4 15:16:00] Via: SIP/2.0/TLS 139.84.175.186:5061;rport;branch=z9hG4bKPj2ebbf164-1f69-41ac-93c4-128d3440278f;alias
[Sep 4 15:16:00] From: “+911214287400” sip:+911214287400@139.84.175.186;tag=ac2b076a-48d3-4d46-ac92-ceeeb226add9
[Sep 4 15:16:00] To: sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com;tag=be2462d1-c4b0-4de9-825f-1dcb2559562f
[Sep 4 15:16:00] Call-ID: 17e11e57-0915-487d-9599-ed7472ae6942
[Sep 4 15:16:00] CSeq: 2076 BYE
[Sep 4 15:16:00] Reason: SIP ;cause=406 ;text=“SDP offer/answer incomplete”
[Sep 4 15:16:00] Max-Forwards: 70
[Sep 4 15:16:00] User-Agent: openairealtimeapi.callanywhere.co.in
[Sep 4 15:16:00] Content-Length: 0
[Sep 4 15:16:00]
[Sep 4 15:16:00]
[Sep 4 15:16:00] – PJSIP/openai-realtime-00000005 answered SIP/openairealtime-00000005
[Sep 4 15:16:00] – Channel PJSIP/openai-realtime-00000005 joined ‘simple_bridge’ basic-bridge <607ee427-3cc6-49d6-a0e8-0b7a7c3537b6>
[Sep 4 15:16:00] – Channel SIP/openairealtime-00000005 joined ‘simple_bridge’ basic-bridge <607ee427-3cc6-49d6-a0e8-0b7a7c3537b6>
[Sep 4 15:16:00] > 0x7f43e8013230 – Strict RTP switching to RTP target address 122.176.155.244:16152 as source
[Sep 4 15:16:00] <— Received SIP response (433 bytes) from TLS:172.65.182.150:5061 —>
[Sep 4 15:16:00] SIP/2.0 200 OK
[Sep 4 15:16:00] Via: SIP/2.0/TLS 139.84.175.186:5061;alias;rport=53174;branch=z9hG4bKPj2ebbf164-1f69-41ac-93c4-128d3440278f;received=172.69.203.193
[Sep 4 15:16:00] From: “+911214287400” sip:+911214287400@139.84.175.186;tag=ac2b076a-48d3-4d46-ac92-ceeeb226add9
[Sep 4 15:16:00] To: sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com;tag=be2462d1-c4b0-4de9-825f-1dcb2559562f
[Sep 4 15:16:00] Call-ID: 17e11e57-0915-487d-9599-ed7472ae6942
[Sep 4 15:16:00] CSeq: 2076 BYE
[Sep 4 15:16:00] Content-Length: 0
[Sep 4 15:16:00]
[Sep 4 15:16:00]
[Sep 4 15:16:00] – Channel PJSIP/openai-realtime-00000005 left ‘simple_bridge’ basic-bridge <607ee427-3cc6-49d6-a0e8-0b7a7c3537b6>
[Sep 4 15:16:00] – Channel SIP/openairealtime-00000005 left ‘simple_bridge’ basic-bridge <607ee427-3cc6-49d6-a0e8-0b7a7c3537b6>
[Sep 4 15:16:00] – Executing [+911213509215@inbound-test:5] Hangup(“SIP/openairealtime-00000005”, “”) in new stack
[Sep 4 15:16:00] == Spawn extension (inbound-test, +911213509215, 5) exited non-zero on ‘SIP/openairealtime-00000005’
[Sep 4 15:16:00] – Executing [h@inbound-test:1] Hangup(“SIP/openairealtime-00000005”, “”) in new stack
[Sep 4 15:16:00] == Spawn extension (inbound-test, h, 1) exited non-zero on ‘SIP/openairealtime-00000005’
openairealtimeapi*CLI>

but same openai reatime api is working with twilio just be point to twilio but in twilio
SIP URI is sip:proj_ynVte2cOPDHsxBZ6IUbVRcQ7@sip.api.openai.com;transport=tls

so now here i am stuck, here its not working due to TO URI or anything else

This is your problem, it has nothing to do with the To URI. The lack of Content-Type is likely causing PJSIP to not process the SDP response, resulting in call termination.

A thread was just created on the OpenAI side for this:

And an older one (which includes a patch it seems for PJSIP to hack it in):

And to quote the RFC[1]:

The Content-Type header field MUST be present if
   the body is not empty.

[1] RFC 3261 - SIP: Session Initiation Protocol

1 Like

its seems direclty via asteirsk its hard to connect, but i am trying some tricks from asterisk.
if i got success i will update here also.


now with same pjsip conf we are getting content type and our whole system is working.
only one thing we made some changes into webhook and connect websocket.
but now its working directly with asterisk

1 Like

Hello @amarniit great you make it working , can you please share changes in teh webhook .Thanks

with webhook now we are using websocket connection also, thn its start working.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.