How to add room metadata in python ?
# ask-ai
e
How to add room metadata in python ?
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You can set or update room metadata from the server using the LiveKit Python API. Metadata is a freeform string (up to 64 KiB) and is visible to all participants. 1) Update existing room metadata
Copy code
from livekit.api import LiveKitAPI, UpdateRoomMetadataRequest
import asyncio

async def update_metadata():
    async with LiveKitAPI() as lkapi:
        await lkapi.room.update_room_metadata(
            UpdateRoomMetadataRequest(
                room="my-room-name",
                metadata="Updated room metadata"
            )
        )

asyncio.run(update_metadata())
2) Create a room with initial metadata
Copy code
from livekit.api import LiveKitAPI, CreateRoomRequest
import asyncio

async def create_room():
    async with LiveKitAPI() as lkapi:
        room = await lkapi.room.create_room(
            CreateRoomRequest(
                name="my-room",
                metadata="Initial room metadata"
            )
        )
        print(room)

asyncio.run(create_room())
Notes: • The
LiveKitAPI
client reads
LIVEKIT_URL
,
LIVEKIT_API_KEY
, and
LIVEKIT_API_SECRET
from environment variables. • Metadata must be set via the server API (not from clients) and is limited to 64 KiB. Would you like an example showing how participants can read the room metadata client-side? Sources: Room metadata | LiveKit docs | Managing rooms | LiveKit docs | Managing participants | LiveKit docs