When creating a participant token, where do I set ...
# ask-ai
b
When creating a participant token, where do I set the metadata? In the AccessToken? Or in the RoomConfiguration?
Copy code
function createParticipantToken(
  userInfo: AccessTokenOptions,
  roomName: string,
  apiKey: string,
  apiSecret: string,
  agentName?: string
): Promise<string> {
  const at = new AccessToken(apiKey, apiSecret, {
    ...userInfo,
    ttl: "15m",
  });
  const grant: VideoGrant = {
    room: roomName,
    roomJoin: true,
    canPublish: true,
    canPublishData: true,
    canSubscribe: true,
  };
  at.addGrant(grant);

  if (agentName) {
    at.roomConfig = new RoomConfiguration({
      agents: [{ agentName }],
    });
  }

  return at.toJwt();
}
t
Thanks for reaching out, 최윤지. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Replying to your question about where to set participant metadata: Set participant metadata on the AccessToken. The
metadata
field on the
AccessToken
becomes the participant’s initial metadata when they join the room.
RoomConfiguration
is for room-level settings (like agent dispatch) and should not be used for participant-specific metadata. Example: include
metadata
when creating the token:
Copy code
const at = new AccessToken(apiKey, apiSecret, {
  ...userInfo,
  metadata: 'your metadata here',
  ttl: '15m',
});
Sources: Authentication | LiveKit docs | Participant attributes and metadata | LiveKit docs | Managing participants | LiveKit docs