Participant attributes and metadata

Use participant attributes and metadata to synchronize application-specific state.

Overview

Each LiveKit participant has two fields for application-specific state:

  • Participant.attributes: A string key-value store
  • Participant.metadata: A single string that can store any data.

These fields are stored and managed by the LiveKit server, and are automatically synchronized to new participants who join the room later.

Initial values can be set in the participant’s access token, ensuring the value is immediately available when the participant connects.

While the metadata field is a single string, the attributes field is a key-value store. This allows fine-grained updates to different parts of the state without affecting or transmitting the values of other keys.

Deleting attributes

To delete an attribute key, set its value to an empty string ('').

Update frequency

Attributes and metadata are not suitable for high-frequency updates (more than once every few seconds) due to synchronization overhead on the server. If you need to send updates more frequently, consider using data messages instead.

Size limits

Metadata and attributes each have a 64 KiB limit. For attributes, this limit includes the combined size of all keys and values.

Usage from LiveKit SDKs

The LiveKit SDKs receive events on attributes and metadata changes for both the local participant and any remote participants in the room. See Handling events for more information.

Participants must have the canUpdateOwnMetadata permission in their access token to update their own attributes or metadata.

// receiving changes
room.on(
RoomEvent.ParticipantAttributesChanged,
(changed: Record<string, string>, participant: Participant) => {
console.log(
'participant attributes changed',
changed,
'all attributes',
participant.attributes,
);
},
);
room.on(
RoomEvent.ParticipantMetadataChanged,
(oldMetadata: string | undefined, participant: Participant) => {
console.log('metadata changed from', oldMetadata, participant.metadata);
},
);
// updating local participant
room.localParticipant.setAttributes({
myKey: 'myValue',
myOtherKey: 'otherValue',
});
room.localParticipant.setMetadata(
JSON.stringify({
some: 'values',
}),
);

Usage from server APIs

From the server side, you can update attributes or metadata of any participant in the room using the RoomService.UpdateParticipant API.

import { RoomServiceClient } from 'livekit-server-sdk';
const roomServiceClient = new RoomServiceClient('myhost', 'api-key', 'my secret');
roomServiceClient.updateParticipant('room', 'identity', {
attributes: {
myKey: 'myValue',
},
metadata: 'updated metadata',
});