how to read room metadata from the LiveKit agent?
# ask-ai
a
how to read room metadata from the LiveKit agent?
t
Thanks for reaching out, Sebastián. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking how to read room metadata from a LiveKit agent — here's how to do that and a few useful notes. Python
Copy code
@server.rtc_session()
async def my_agent(ctx: JobContext):
    # read room metadata
    room_metadata = ctx.room.metadata
    print(f"Room metadata: {room_metadata}")

    # optional: connect to participate
    await ctx.connect(auto_subscribe=AutoSubscribe.AUDIO_ONLY)
Node.js / TypeScript
Copy code
export default defineAgent({
  entry: async (ctx: JobContext) => {
    // read room metadata
    const roomMetadata = ctx.room.metadata;
    console.log(`Room metadata: ${roomMetadata}`);

    // optional: connect to participate
    await ctx.connect(undefined, AutoSubscribe.AUDIO_ONLY);
  },
});
Key points • Access the
metadata
property on the
ctx.room
(
rtc.Room
) provided to the agent entrypoint. • Metadata is a string and has a 64 KiB size limit. • If you need to react to changes, listen for the
RoomMetadataChanged
event. • Room metadata is set via server APIs (e.g., CreateRoom / UpdateRoomMetadata); agents/participants can't directly change it without appropriate permissions. Would you like an example that parses JSON metadata or code showing how to handle the RoomMetadataChanged event? Sources: Room metadata | LiveKit docs