wooden-smartphone-55787
02/19/2026, 8:55 AMtall-airline-16756
02/19/2026, 8:55 AMtall-airline-16756
02/19/2026, 8:56 AMwooden-smartphone-55787
02/19/2026, 8:56 AMtall-airline-16756
02/19/2026, 8:57 AMwooden-smartphone-55787
02/19/2026, 8:57 AMtall-airline-16756
02/19/2026, 8:57 AMimport asyncio
import time
from livekit import api # use your livekit-api client
LIVEKIT_URL = "<https://your-instance.livekit.cloud>"
API_KEY = "your-api-key"
API_SECRET = "your-api-secret"
client = api.LiveKitAPI(url=LIVEKIT_URL, api_key=API_KEY, api_secret=API_SECRET)
MAX_DURATION_SECONDS = 60 * 60 # 60 minutes
POLL_INTERVAL_SECONDS = 30
room_start_times = {} # {room_name: first_seen_unix_time}
async def monitor_rooms():
global room_start_times
while True:
try:
room_list = await client.room.list_rooms()
now = time.time()
# Build map of currently active rooms
active_rooms = {r.name: r for r in room_list.rooms}
# Remove rooms that no longer exist
for name in list(room_start_times.keys()):
if name not in active_rooms:
del room_start_times[name]
# Track new rooms and check durations
for room in room_list.rooms:
if room.name not in room_start_times:
room_start_times[room.name] = now
elapsed = now - room_start_times[room.name]
if elapsed > MAX_DURATION_SECONDS:
try:
await client.room.delete_room(api.DeleteRoomRequest(room=room.name))
# optional: log or notify users
except Exception as e:
print(f"Failed deleting room {room.name}: {e}")
except Exception as e:
print(f"Monitor error: {e}")
await asyncio.sleep(POLL_INTERVAL_SECONDS)
if __name__ == "__main__":
loop = asyncio.get_event_loop()
loop.create_task(monitor_rooms())
loop.run_forever()
Optional refinements
• Send a pre-expiration warning (e.g., at T-1 minute) by calling your app’s notification flow before deleting the room.
• Use room metadata to persist actual room creation timestamps instead of relying on first-seen time, if you create rooms programmatically and can set that metadata at creation.
• Make the monitor highly available (run with leader election or single-instance responsibility) to avoid duplicate deletes or race conditions.
• Instead of deleting the room, you can selectively disconnect participants if you want to preserve room state.
If you’d like, I can:
• Provide a Node.js or Go example for your backend language.
• Show how to add a pre-expiration notification flow.
• Outline IAM/grant scope required for the API key.
Which language would you prefer for the example (Node, Python, or Go), and do you want a pre‑warning sent to participants before disconnecting?
Sources: sip | livekit/livekit_composite | DeepWikiwooden-smartphone-55787
02/19/2026, 8:58 AMtall-airline-16756
02/19/2026, 8:58 AMwooden-smartphone-55787
02/19/2026, 8:59 AMtall-airline-16756
02/19/2026, 8:59 AMmax_call_duration.
You’re correct: for SIP trunks LiveKit supports a max_call_duration property that limits an individual SIP call. However, that SIP property applies only to SIP sessions and does not act as a built‑in global duration limit across all LiveKit rooms or WebRTC calls.
What that means for you
• SIP calls: You can set max_call_duration on the SIP integration to automatically limit those SIP calls.
• Non‑SIP calls (WebRTC, agent rooms, etc.): There is no built‑in global setting in LiveKit Cloud to automatically end every room after a fixed time. You must enforce a global limit from your backend/agent logic.
Recommended approaches
• If most of your traffic is SIP and that covers your use case, set max_call_duration in your SIP configuration.
• If you need a true global limit for every room (including WebRTC), implement server‑side enforcement:
◦ Option A (recommended): Run a background monitor that lists active rooms, records first‑seen/start times, and deletes rooms that exceed your MAX_DURATION.
◦ Option B: When you create a room, start a server timer that disconnects that room after MAX_DURATION.
◦ Option C: For agent sessions, start a per‑session timer and call session.shutdown() or room.disconnect() when time is up.
If you want, I can:
• Show how to set max_call_duration for SIP (where to configure it and an example).
• Provide a concise server example in your preferred language (Node.js, Python, or Go) to enforce a global limit for all rooms, including pre‑expiration warnings.
Which would you like next: SIP config example or a global enforcement snippet in a specific language?
Sources: sip | livekit/livekit_composite | DeepWiki | SIP Lifecycle Management Agent | LiveKit Documentation | examples/frontdesk | livekit/livekit_composite | DeepWikiwooden-smartphone-55787
02/19/2026, 9:00 AMtall-airline-16756
02/19/2026, 9:00 AMmax_call_duration for non‑SIP calls.
Short answer: No — LiveKit Cloud does not provide a built‑in max‑duration property for non‑SIP calls (WebRTC rooms or agent sessions). The max_call_duration setting is specific to SIP trunks only.
What to do instead
• Enforce the limit from your backend or agent logic. Common patterns:
◦ Background monitor: periodically list active rooms, track when each room started, and call the Server API to delete or disconnect rooms that exceed your global MAX_DURATION.
◦ Per‑room timer: when a room is created (or participant joins), start a server timer that disconnects the room after MAX_DURATION.
◦ Agent timer: for agent sessions, start a timer on session start and call session.shutdown() or room.disconnect() when time’s up.
• Optionally send a pre‑warning (e.g., 1–2 minutes before) to participants before disconnecting so they can wrap up.
If helpful, I can provide:
• A short code example in your preferred backend language (Node.js, Python, or Go) that enforces a global max duration and optionally sends a pre‑warning.
• Guidance on required API grants for the key used to list/delete rooms.
Which language would you like the example in, and do you want a pre‑warning notification before disconnecting?