Analytics API

Get information about your LiveKit sessions and participants

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
tip:

To streamline your workflow with livekit-cli, add your projects using the command livekit-cli project add. This approach spares you from repeatedly entering your --api-key and --api-secret for each command you execute.

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"

This will return a JSON object like this:

{
sessions: [
{
sessionId, // string
roomName, // string
createdAt, // Timestamp
lastActive, // Timestamp
bandwidthIn, // bytes of bandwidth uploaded
bandwidthOut, // bytes of bandwidth downloaded
egress, // 0 = never started, 1 = active, 2 = ended
numParticipants, // int
numActiveParticipants, // int
},
// ...
]
}

Query parameters

limitint

You can limit the number of returned sessions by adding the limit query parameter like ?limit=100.

caution:

Higher limit values may result in a time out from the Analytics API.

pageint

You can page through the results by adding ?page=n&limit=100 to the endpoint URL to get the nth page of results with 100 sessions per page. Pagination starts from 0.

startstring

Specify the start date for the request time range in the format YYYY-MM-DD. Sessions starting on the specified start date will be included in the response.

note:

The start date must be within 7 days of the current date.

endstring

Specify the end date for the request time range using the format YYYY-MM-DD. Sessions up to and including this end date will be included in the response.

Examples

# Get the first page and limit the number of sessions to 100.
curl -H "Authorization: Bearer $TOKEN" \
"https://cloud-api.livekit.io/api/project/$PROJECT_ID/sessions\
?page=0&limit=100"
# Fetch sessions from a specified time range.
curl -H "Authorization: Bearer $TOKEN" \
"https://cloud-api.livekit.io/api/project/$PROJECT_ID/sessions\
?start=2024-01-12&end=2024-01-13"

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"

This will return a JSON object like this:

{
roomId, // string
roomName, // string
bandwidth, // billable bytes of bandwidth used
startTime, // Timestamp
endTime, // Timestamp
numParticipants, // int
participants: [
{
participantIdentity, // string
participantName, // string
roomId, // string
joinedAt, // Timestamp
leftAt, // Timestamp
publishedSources: {
cameraTrack, // boolean
microphoneTrack, // boolean
screenShareTrack, // boolean
screenShareAudio, // boolean
},
sessions: [
{
sessionId, // string
joinedAt, // Timestamp
leftAt, // Timestamp
},
// ...
],
},
// ...
],
}

Timestamp objects are Protobuf Timestamps.