How do you set room metadata while issuing a livek...
# ask-ai
e
How do you set room metadata while issuing a livekit auth token ?
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.
Thanks — I’ll answer your question about setting room metadata when issuing a LiveKit auth token. Short answer • You cannot set room metadata directly inside a LiveKit auth token once a room already exists. • You can include a RoomConfiguration in the token to set initial metadata only when the room is created at first join. • To change metadata for an existing room, call the server-side API (
updateRoomMetadata
) after creation. How to set initial room metadata when creating a room via token 1. Create an AccessToken and grant
roomJoin
for the room. 2. Attach a
RoomConfiguration
to the token and set
metadata
to the desired initial value. 3. Issue the JWT. If the room does not yet exist, the room will be created with that metadata. Node.js example:
Copy code
const at = new AccessToken(apiKey, apiSecret);
at.identity = 'user-identity';
at.addGrant({ roomJoin: true, room: 'my-room' });

at.roomConfig = new RoomConfiguration({ metadata: 'room-initial-metadata' });

const token = await at.toJwt();
Python example:
Copy code
token = AccessToken(api_key, api_secret)
token.identity = "user-identity"
token.add_grant(room_join=True, room="my-room")

token.room_config = RoomConfiguration(metadata="room-initial-metadata")

jwt = token.to_jwt()
How to update metadata after the room exists • Use the server SDK’s room update API (for example
updateRoomMetadata
) to set or change metadata for an existing room. • Metadata updates are propagated asynchronously; clients receive
room_metadata_changed
events. When to use which approach • Use token-embedded
RoomConfiguration
only to set initial metadata at room creation time. • Use the server API to update metadata for existing rooms or to change metadata later. If helpful, tell me: • Are you trying to set metadata only at room creation, or update metadata for an existing room? • Which server SDK (Node, Python, Go, etc.) are you using? I can share exact code for that SDK. Sources: server-sdk-kotlin | livekit/livekit_composite | DeepWiki | Handling asynchronous metadata updates in LiveKit | LiveKit | server-sdk-js | livekit/livekit_composite | DeepWiki
e
is metadata needs to be a string or it can be a json too ?
t
Good question — thanks for asking. Room (and other) metadata in LiveKit must be a string. If you need structured data, encode it as a JSON-formatted string (for example,
"{\"userId\":123, \"role\":\"presenter\"}"
) when you set the metadata, and parse the string back to JSON on the client or server that reads it. If you tell me which SDK or language you’re using (Node, Python, Go, etc.), I can show a short example of serializing/deserializing JSON metadata for tokens or for the
updateRoomMetadata
call. Sources: Agent dispatch | LiveKit Documentation