how can we set the max duartion for every call?
# ask-ai
w
how can we set the max duartion for every call?
t
Thanks for reaching out, Test. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I can help with setting a maximum call duration. I just need a little clarification so I point you to the right steps. Which product or setup are you using? A few examples: • LiveKit self-managed or LiveKit Cloud (our service) • A third‑party provider (Zoom, Teams, OnceHub, etc.) • A custom application using the LiveKit SDKs Also tell me: 1. Do you want a global limit for every room/session, or different limits per room/meeting type? 2. Are you enforcing the limit server‑side (so clients get disconnected when time is up) or just notifying users? 3. If you’re using the LiveKit SDKs, which language/framework (JavaScript, iOS, Android, or server SDK)? 4. If you already have code or config in place, paste the relevant snippet or describe how rooms are created. Once you tell me which product and your preferred enforcement method (disconnect vs. notify), I’ll give step‑by‑step instructions or a code example to implement the max duration.
w
livekit cloud
t
Thanks — I’m responding to your request about setting a maximum duration for calls on LiveKit Cloud. LiveKit Cloud does not enforce call-duration limits automatically, but you can enforce one programmatically by ending the room/session after a timer expires. To give the best guidance I can, a couple quick clarifying questions: 1. Do you want a single global limit applied to every room, or different limits per room/type/user? 2. Do you want the call to be forcefully disconnected when time’s up, or do you prefer sending a warning/notification before ending the call? 3. Which environment are you controlling this from: server-side agent code (LiveKit Agents), your application backend, or client code? If server-side, which SDK/language are you using (JavaScript/Node, Python, Go, etc.)? If you want a quick example now, here’s a recommended approach for LiveKit Cloud using server-side logic (safe, server-enforced disconnect): 1. When a room/session starts, start a server-side timer for the desired MAX_DURATION. 2. When the timer fires, call the API/SDK to close or disconnect participants in that room (for example, call room.disconnect() or session.shutdown() from your agent/server code). 3. Optionally send a pre-expiration notification (e.g., at T-1 minute) so participants can wrap up. 4. Cancel the timer if the room ends earlier. If you tell me which SDK/language you prefer, I’ll provide a concise code snippet (server-side) to implement the timer, the pre-warning, and the graceful disconnect. Sources: Deploy and scale agents on LiveKit Cloud | How to implement call greeting retries in voice agents | LiveKit | Job lifecycle | LiveKit Documentation
w
Do you want a single global limit applied to every room yes
t
Thanks — I’m responding to your confirmation that you want a single global limit applied to every room on LiveKit Cloud. LiveKit Cloud does not enforce a built‑in global room duration limit, but you can enforce one reliably from your backend by periodically monitoring active rooms and terminating any that exceed your global maximum. Below is a concise, production-ready approach and a runnable example you can adapt. Key idea • Run a resilient background task that: a. Lists active rooms. b. Tracks each room’s start time (when first seen). c. Deletes/ends any room whose elapsed time exceeds MAX_DURATION. • This enforces the same limit for every room (global). What you’ll need • A LiveKit API key/secret with grants to list and delete rooms. • A backend process that stays running (e.g., container with restart policy, VM, or managed service). Recommended implementation (Python, asyncio) 1. Set your global duration in seconds (e.g., 60 minutes = 3600). 2. Poll LiveKit’s room list every 20–60 seconds. 3. Call delete_room for rooms that exceeded the limit. Example (adaptable):
Copy code
import 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 | DeepWiki
w
dont we have a inbuilt setting for this?
t
Thanks — I’m responding to your question about whether LiveKit Cloud has a built‑in setting to enforce a global max call duration. Short answer: No — LiveKit Cloud does not provide a built‑in global call‑duration setting that automatically ends every room after a defined time. What that means for you • You must enforce a global limit from your backend (or agent) code. • The usual, reliable pattern is a server‑side monitor or per‑room timer that calls the LiveKit Server API / SDK to disconnect participants or delete the room when the limit is reached. Quick options you can use • Background monitor: Periodically list active rooms, track first-seen/start times, and delete rooms that exceed the global limit. (Recommended for a single global policy.) • Per-room timer: When a room is created, start a server timer that fires after MAX_DURATION to disconnect the room. • Pre‑warning: Optionally send a notification (e.g., 1 minute before) before you disconnect so users can wrap up. If you want, I can: • Provide a short example in your preferred backend language (Node.js, Python, or Go). • Show how to add a pre-expiration warning to participants. • Outline the API key grants required to list/delete rooms. Which language would you like the example in, and do you want a pre‑warning sent before disconnecting? Sources: How to detect and handle silence during calls | LiveKit | How to implement call greeting retries in voice agents | LiveKit | examples/voice_agents | livekit/livekit_composite | DeepWiki
w
sip has a proprty max_call_duration
t
Thanks — I’m responding to your note about SIP’s
max_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 | DeepWiki
w
do we have similar setting for non sip calls
t
Thanks — I’m responding to your question about whether LiveKit Cloud has a setting like SIP’s
max_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?