i would like to limit livekit agent to allow only ...
# ask-ai
e
i would like to limit livekit agent to allow only max 3 users
t
Thanks for reaching out, Aman. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your request to limit the LiveKit agent to a maximum of 3 users. Quick answer you can use now: • Create the room the agent uses with
maxParticipants: 3
. This will prevent more than 3 participants from joining that room (the agent counts as a participant if it joins the room). • If you need stricter control or different behavior (e.g., deny joins after 3, kick excess participants), enforce the limit in your server logic by checking current participant count (or handling
participant_joined
webhooks) and refusing or disconnecting extra users. A couple of quick clarifying questions so I can give exact steps: 1. Do you mean 3 total participants in the room (including the agent) or 3 external users plus the agent? 2. Is your agent running self-hosted or on LiveKit Cloud? 3. Do you want joins to be rejected immediately once the limit is reached, or allow joins and then disconnect the oldest/newest participant programmatically? Tell me those and I’ll give the exact code snippets or webhook logic to implement it. Sources: server-sdk-js | livekit/livekit_composite | DeepWiki | Managing rooms | LiveKit docs | Agent server options | LiveKit docs
e
agent is self hosted, l want to support only 3 session at a time if 4th try to join, it should not allow
t
Thanks — I’ll help you enforce a hard limit of 3 concurrent sessions for your self-hosted agent so a 4th join is rejected. Recommended approach (simple, reliable) 1. Create the room your agent uses with
maxParticipants: 3
. LiveKit will refuse join attempts beyond that limit. 2. When issuing join tokens or answering join requests from your app server, check the room's current participant count first and deny token issuance if count >= 3 (this prevents an attempted join before it reaches LiveKit). Implementation options (pick one) • Use Room creation / update (preferred) ◦ When creating the room via the RoomService API, set
maxParticipants: 3
. The server will enforce the limit automatically and reject a 4th join. ◦ If room already exists, update its
maxParticipants
to 3. • Enforce on your agent/app server (extra safety) ◦ Before generating a join token, call the LiveKit room endpoint to get current participants. If count >= 3, return an error to the client and do not issue a token. ◦ This prevents a race where multiple clients request tokens simultaneously. • Optional webhook fallback ◦ Subscribe to
participant_joined
events. If a join somehow succeeds beyond 3, immediately disconnect the extra participant. (Useful as a safety net only.) If you want, I can provide: • The exact API call or code snippet for creating/updating a room with
maxParticipants: 3
for your preferred language (Node, Go, or Python). • A sample pre-join check snippet for token issuance to prevent race conditions. Which language do you use for your server (Node, Go, Python, or other)?