Skip to content

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

Description

@sbenodiz

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:
➡️ 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions