Overview
Generate an access token for Analytics requests
Analytics API requests are authorized with a LiveKit token. This is generated by a server-side SDK,much like generating a token for joining Rooms, except that the token needs the roomList
grant.
# using livekit-cli (https://docs.livekit.io/realtime/cli-setup/)livekit-cli create-token \--api-key $LIVEKIT_API_KEY --api-secret $LIVEKIT_SECRET_KEY \--list \--valid-for 24h
const at = new AccessToken(apiKey, apiSecret, { ttl: 60 * 60 * 24 });at.addGrant({ roomList: true });
List sessions
To make a request, you'll need to know your project id, which you can see in the URL for your project dashboard. It's the part after /projects/
that starts with p_
.
curl -H "Authorization: Bearer $TOKEN" https://cloud-api.livekit.io/api/project/$PROJECT_ID/sessions
async function listLiveKitSessions() {const endpoint = `https://cloud-api.livekit.io/api/project/${PROJECT_ID}/sessions/`try {const response = await fetch(endpoint, {method: 'GET',headers: {'Authorization': `Bearer ${token}`,'Content-Type': 'application/json'}});if (!response.ok) throw new Error('Network response was not ok');const data = await response.json();console.log(data); // or do whatever you like here} catch (error) {console.log('There was a problem:', error.message);}}listLiveKitSessions();
This will return a JSON object like this:
{sessions: [{session_id, // stringroom_name, // stringcreated_at, // Timestamplast_active, // Timestampbandwidth_in, // bytes of bandwidth uploadedbandwidth_out, // bytes of bandwidth downloadedegress, // 0 = never started, 1 = active, 2 = endedconnection_counts: {attempts, // intsuccess, // int},num_participants, // intnum_active_participants, // int},// ...]}
List session details
To get more details about a specific session, you can use the session_id returned from the list sessions request.
curl -H "Authorization: Bearer $TOKEN" cloud-api.livekit.io/api/project/$PROJECT_ID/sessions/$SESSION_ID
async function getLiveKitSessionDetails() {const endpoint = `https://cloud-api.livekit.io/api/project/${PROJECT_ID}/sessions/${SESSION_ID}`;try {const response = await fetch(endpoint, {method: 'GET',headers: {'Authorization': `Bearer ${token}`,'Content-Type': 'application/json'}});if (!response.ok) throw new Error('Network response was not ok');const data = await response.json();console.log(data); // or do whatever you like here} catch (error) {console.log('There was a problem:', error.message);}}getLiveKitSessionDetails();
This will return a JSON object like this:
{room_id, // stringroom_name, // stringstatus, // 0=closed, 1=activebandwidth, // billable bytes of bandwidth usedstart_time, // Timestampend_time, // Timestampparticipants: [{participant_identity, // stringparticipant_name, // stringroom_id, // stringis_active, // booleanjoined_at, // Timestampleft_at, // Timestamppublished_sources: {camera_track, // booleanmicrophone_track, // booleanscreen_share_track, // booleanscreen_share_audio, // boolean},sessions: [{session_id, // stringjoined_at, // Timestampleft_at, // Timestamp},// ...],},// ...],num_participants, // int}
Timestamp
objects are Protobuf Timestamps.