How can i add metadata to the rooms?
# ask-ai
a
How can i add metadata to the rooms?
t
Thanks for reaching out, Angel. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm glad you're interested in adding metadata to rooms in LiveKit! To do this, you'll want to use the server-side APIs. The
metadata
field is a flexible string, and many folks use structured formats like JSON to keep track of room-wide state or settings. Let me walk you through the two main ways to handle this: 1. When Creating a Room: You can include the
metadata
field right in the
CreateRoom
API request. Here's a quick example in TypeScript:
Copy code
await roomService.createRoom({
  name: 'my-room',
  metadata: JSON.stringify({ game_state: { started: false } }),
});
1. Updating Metadata for an Existing Room: If you need to change the metadata later, the
UpdateRoomMetadata
API is your friend. Here's how you might do it in Python:
Copy code
await room_service.update_room_metadata(
  UpdateRoomMetadataRequest(room='my-room', metadata='new_metadata')
)
Just a heads-up: room metadata has a size limit of 64 KiB, and it's accessible to all participants through the LiveKit client SDKs. If you'd like to respond to any changes, you can listen for the
RoomMetadataChanged
event. I hope this helps you get started smoothly! If you have any questions along the way, feel free to ask. Sources: livekit/livekit_room.pb.go | src/lib/controller.ts | examples/agent_dispatch.py | Room metadata | LiveKit Docs | Job lifecycle | LiveKit Docs