How to limit OpenAI Realtime API sessions to x minutes max?

Hey everyone

I’m using the OpenAI Realtime API to handle live voice and streaming conversations, and I’m generating ephemeral client secrets server-side via
POST https://api.openai.com/v1/realtime/sessions.

I know that I can control the token expiration using the expires_in field, but that only limits how long the token can be used to start a connection — it doesn’t actually end an active session once it’s already connected.

What I’m trying to do is:
:right_arrow: Automatically limit each realtime session to 60 minutes max, regardless of whether the client stays connected.

So far, it looks like OpenAI doesn’t expose a server-side parameter for session lifetime after connection.

Has anyone found:

A documented (or undocumented) maximum session duration enforced by OpenAI?

A clean way to force-close a WebRTC / WebSocket session after a set time?

This is both a security and billing concern — since once a client connects, they can theoretically stay connected indefinitely, consuming resources and costs on my side without any enforced timeout.

1 Like

While there is no configuration, your goal is met:

Session lifecycle events

After initiating a session via either WebRTC or WebSockets, the server will send a session.created event indicating the session is ready. On the client, you can update the current session configuration with the session.update event. Most session properties can be updated at any time, except for the voice the model uses for audio output, after the model has responded with audio once during the session.

The maximum duration of a Realtime session is 30 minutes.

hey, sorry to get back so late but I thought your answer solved my case. but I know realised that what I want is to dynamically limit the length that the client can use the token base on client credit limits. so some clients it can be 5 minutes and some it can be 60 minutes.
Is there anyway to achieve it?