400 SDP Error with Empty Reason Message During WebRTC Transcription

I obtain an ephemeral key from my server, which is set up as follows:

// server context above ...
const realtimeBaseUrl = 'https://api.openai.com/v1/realtime'
const response = await fetch(`${realtimeBaseUrl}/transcription_sessions`, {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.OPENAI_API_KEY}`,
    "Content-Type": "application/json",
  },
}

return response.client_secret.value
// server context below ...

I’m using WebRTC for real-time transcription and received a 400 error when sending the SDP offer, see below.

// client context above ...

const ephemeralToken = await getEphemeralToken();

// Establish peer connection
const pc = new RTCPeerConnection();

// Add local audio track for mic input
const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
pc.addTrack(stream.getTracks()[0]);

// Data channel for sending and receiving messages
const dataChannel = pc.createDataChannel("oai-events");
dataChannel.onmessage = handleDataChannelMessage;

// Create offer & set local description
const offer = await pc.createOffer();
await pc.setLocalDescription(offer);

// Send SDP offer to OpenAI Realtime
const baseUrl = "https://api.openai.com/v1/realtime";
const model = "gpt-4o-mini-transcribe";
const url = `${baseUrl}?model=${model}`;

const sdpResponse = await fetch(url, {
  method: "POST",
  body: offer.sdp,
  headers: {
    Authorization: `Bearer ${ephemeralToken}`,
    "Content-Type": "application/sdp",
  },
});

// Set remote description
const answerSdp = await sdpResponse.text();
console.log("SDP Response:", answerSdp);
await pc.setRemoteDescription({ type: "answer", sdp: answerSdp });

// client context below ...

error 400 (Bad Request) via POST to https://api.openai.com/v1/realtime?model=gpt-4o-mini-transcribe

SDP Response: {
    "error": {
        "message": "",
        "type": "",
        "code": "",
        "param": ""
    }
}

Interestingly, I tested switch the server’s ephemeral token endpoint from /transcription_sessions to /sessions, the WebRTC connection could be established.

I resolved this, the problem is when sending SPD to realtime endpoint, the url is https://api.openai.com/v1/realtime, no ?model=gpt-4o-mini-transcribe needed

1 Like

Hi @keepitreal i’m experiencing a similar issue. I have tried with body: raw SDP and application/sdp without session, which is optional. that, gives a 400 error, i also structured the SDP as following type:”realtime”, model:”gpt-realtime” “type:sdp” “sdp”: “a=0\r\n” and that, also lead me to a 400

Do you happen to have an idea, how to get it going?

Thanks in advance!