Realtime api websocket disconnects randomly in nodejs

Using nodejs connecting from server side.

I’m running into this issue that some time around 5-10 minutes in - response.text.delta server event starts to respond slowly and my websocket connection disconnects.

I then get error RealtimeAPI is not connected from here: openai-realtime-api-beta/lib/api.js at main · openai/openai-realtime-api-beta · GitHub with eventName="input_audio_buffer.append".

Modifying the close listener here: openai-realtime-api-beta/lib/api.js at main · openai/openai-realtime-api-beta · GitHub to ws.on('close', (code, reason) I get code=1011 with reason="keepalive ping timeout"

Looking at the rate_limits.updated event. I’m hitting neither the token limit cap, or the 15-minute session timer cap.

Is there another mechanism from OpenAI side that throttles requests and would cause this disconnect?

2 Likes

I figured it out—you need to monkey patch the api.js in the library with a keep-alive ping-pong mechanism. The base library currently doesn’t support long-running monologues well.

3 Likes

Thanks for sharing - I am running into the same issue! I notice the connection closes after just 1-2 minutes.

Mind sharing your patch? I added the ‘ping’ but got an error as the event type is unsupported, so figure it’s missing the ‘pong’

Also, what are you noticing in practice is a duration for a “long running monologue” that’s unsupported?

@hemlocket tagging in case it doesn’t notify

The maximum session length has been increased from 15 minutes to 30 minutes on the Realtime API beta.

Here’s the latest announcement:

1 Like

@hemlocket - I’d love to know more about your patch, I’m running into the same issue on my end.