melodic-zoo-29246
08/28/2025, 7:08 PMtall-airline-16756
08/28/2025, 7:08 PMtall-airline-16756
08/28/2025, 7:09 PMmelodic-zoo-29246
08/28/2025, 7:09 PMtall-airline-16756
08/28/2025, 7:10 PMwebhook section in your config file with your API key and your server’s URL endpoint.
2. Listen for the "Participant Left" Event: Next, have your server listen for webhook payloads and verify them. When you get a participant_left event, grab the room name from the payload.
3. Delete the Room: Then, use the LiveKit Server API to delete the room. Here’s a quick Python example to help you out:
from livekit import api
async def delete_room_on_participant_left(room_name: str):
api_client = api.LiveKitAPI(
os.getenv("LIVEKIT_URL"),
os.getenv("LIVEKIT_API_KEY"),
os.getenv("LIVEKIT_API_SECRET"),
)
await api_client.room.delete_room(
api.DeleteRoomRequest(room=room_name)
)
One little tip: it’s a good idea to check if the room is actually empty before deleting it. You can use the ListRooms API to see how many participants are still in there.
If you want, I’m happy to help you with a more detailed example of how to handle the webhook or anything else you need. Just let me know!
Sources: Inside a session | LiveKit Docs | Managing rooms | LiveKit Docs | Webhooks | LiveKit Docsmelodic-zoo-29246
08/28/2025, 8:09 PMtall-airline-16756
08/28/2025, 8:09 PMtry-except block to gracefully handle any errors that might pop up:
from livekit import api
async def delete_room_on_participant_left(room_name: str):
try:
api_client = api.LiveKitAPI(
os.getenv("LIVEKIT_URL"),
os.getenv("LIVEKIT_API_KEY"),
os.getenv("LIVEKIT_API_SECRET"),
)
await api_client.room.delete_room(
api.DeleteRoomRequest(room=room_name)
)
print(f"Room '{room_name}' deleted successfully.")
except Exception as e:
print(f"Oops! Failed to delete room '{room_name}': {e}")
This way, if anything goes wrong during the room deletion, you’ll get a clear message about it. Feel free to reach out if you want me to tweak this further or if you have any other questions!