my metadata in ctx.job is empty why? import { Acce...
# ask-ai
c
my metadata in ctx.job is empty why? import { AccessToken, AccessTokenOptions, VideoGrant } from "livekit-server-sdk"; import { NextResponse } from "next/server"; // NOTE: you are expected to define the following environment variables in `.env.local`: const API_KEY = process.env.LIVEKIT_API_KEY; const API_SECRET = process.env.LIVEKIT_API_SECRET; const LIVEKIT_URL = process.env.LIVEKIT_URL; // don't cache the results export const revalidate = 0; export type ConnectionDetails = { serverUrl: string; roomName: string; participantName: string; participantToken: string; }; export async function GET() { try { if (LIVEKIT_URL === undefined) { throw new Error("LIVEKIT_URL is not defined"); } if (API_KEY === undefined) { throw new Error("LIVEKIT_API_KEY is not defined"); } if (API_SECRET === undefined) { throw new Error("LIVEKIT_API_SECRET is not defined"); } // Generate participant token const participantIdentity = `voice_assistant_user_${Math.floor(Math.random() * 10_000)}`; const roomName = `voice_assistant_room_${Math.floor(Math.random() * 10_000)}`; const participantToken = await createParticipantToken( { identity: participantIdentity }, roomName ); // Return connection details const data: ConnectionDetails = { serverUrl: LIVEKIT_URL, roomName, participantToken: participantToken, participantName: participantIdentity, }; const headers = new Headers({ "Cache-Control": "no-store", }); return NextResponse.json(data, { headers }); } catch (error) { if (error instanceof Error) { console.error(error); return new NextResponse(error.message, { status: 500 }); } } } function createParticipantToken(userInfo: AccessTokenOptions, roomName: string) { const at = new AccessToken(API_KEY, API_SECRET, { ...userInfo, ttl: "15m", }); const grant: VideoGrant = { room: roomName, roomJoin: true, canPublish: true, canPublishData: true, canSubscribe: true, }; at.metadata = JSON.stringify({ client_id: "web-client", source: "web", campaign: "spring2025", }); at.attributes = { client_id: "web-client", source: "web", campaign: "spring2025", }; at.addGrant(grant); return at.toJwt(); }
t
Thanks for reaching out, ZaidKaraymeh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The
metadata
field in the
AccessToken
is used to set participant metadata (
Participant.metadata
) and doesn’t affect
ctx.job.metadata
. To fill
ctx.job.metadata
, you’ll want to explicitly dispatch an agent using tools like the
AgentDispatchService
API, participant token configuration with
RoomAgentDispatch
, or SIP dispatch rules. Just make sure that the
metadata
field is part of the agent dispatch configuration, rather than the participant’s
AccessToken
. If you’d like, I’m here to help guide you through these steps—just let me know! Sources: src/test/kotlin/io/livekit/server/AccessTokenTest.kt | livekit-api/livekit/api/access_token.py | cmd/lk/token.go | Agent dispatch | LiveKit Docs | Dispatching agents | LiveKit Docs