Realtime API call Transfer not working

Here are my logs, but I’m not getting any details about the 500 error. Any help would be greatly appreciated. I see others on here with what seems to be the same issue. Thank you!

[transfer] Attempting to transfer call=rtc_cd703c2821804fdf93617da3cfde36a8 to key=cohen
[transfer] Transferring call=rtc_cd703c2821804fdf93617da3cfde36a8 to Cohen XXXXX at tel:+13XX53277XX
[transfer] Error transferring call=rtc_cd703c2821804fdf93617da3cfde36a8: Refer failed (500): Internal Server Error
[function] WebSocket disconnected for call=rtc_cd703c2821804fdf93617da3cfde36a8

const response = await fetch(
      `https://api.openai.com/v1/realtime/calls/${encodeURIComponent(callId)}/refer`,
      {
        method: 'POST',
        headers: {
          'Authorization': `Bearer ${process.env.OPENAI_API_KEY}`,
          'Content-Type': 'application/json'
        },
        body: JSON.stringify({ target_uri: targetUri })
      }
    );

    if (!response.ok) {
      const errorText = await response.text();
      const requestId = response.headers.get('x-request-id');
      const message = `Refer failed (${response.status})${requestId ? ` [request-id=${requestId}]` : ''}: ${errorText}`;
      throw new Error(message);
    }

I was able to get this working. I had to point my REFER to my twillio SIP domain. Then I had to enable transfers on my SIP trunk. You have to create an ACL in twillio to allow traffic inbound and you have to click enable transfers to pstn if you want to send it over PSTN.

2 Likes