proud-lawyer-39815
09/24/2025, 5:18 PMtall-airline-16756
09/24/2025, 5:18 PMtall-airline-16756
09/24/2025, 5:19 PMproud-lawyer-39815
09/24/2025, 5:20 PMtall-airline-16756
09/24/2025, 5:21 PMfrom livekit import api
import asyncio
async def main():
# Initialize the LiveKit API client
# Uses LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET from environment variables
lkapi = api.LiveKitAPI()
try:
# Create a new room
room_info = await lkapi.room.create_room(
api.CreateRoomRequest(name="my-room"),
)
print(f"Created room: {room_info.name}")
# List all active rooms
rooms_response = await lkapi.room.list_rooms(api.ListRoomsRequest())
print("Active rooms:")
for room in rooms_response.rooms:
print(f" - {room.name}")
# List participants in a specific room
participants_response = await lkapi.room.list_participants(
api.ListParticipantsRequest(room="my-room")
)
print("Participants in 'my-room':")
for participant in participants_response.participants:
print(f" - Identity: {participant.identity}, State: {participant.state}")
# Delete a room
await lkapi.room.delete_room(api.DeleteRoomRequest(room="my-room"))
print("Deleted room 'my-room'")
finally:
# Close the API client
await lkapi.aclose()
if __name__ == "__main__":
asyncio.run(main())
This example gently walks you through:
• Initializing the LiveKit API client
• Creating a room
• Listing all rooms
• Listing participants in a room
• Deleting a room
Just a quick note: make sure you have the environment variables LIVEKIT_URL, LIVEKIT_API_KEY, and LIVEKIT_API_SECRET set up before running this. If you have any questions or need a hand with anything else, please don’t hesitate to ask — I’m here to help!
Sources: Managing rooms | LiveKit Docs | Managing participants | LiveKit Docs