Is job id and session id same ?
# ask-ai
e
Is job id and session id same ?
t
Thanks for reaching out, Aditya. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether a job ID and a session ID are the same — they're not. • Job ID: Identifies a single agent execution (a job) in the LiveKit Agents framework. It tracks that agent's lifecycle and metadata while it runs in a room. • Session ID: Identifies a LiveKit room communication session (used by analytics and realtime session tracking). It represents the overall room/session, independent of agent jobs. They can be related (an agent job may run inside a session) but they refer to different entities and are used for different purposes. Would you like help finding the job ID or session ID in your logs or API responses? Sources: Job lifecycle | LiveKit docs | Agents (Node.js) | livekit/livekit_composite | DeepWiki | Analytics API | LiveKit docs
e
how can i get the session id ?
t
You're asking how to get the LiveKit session ID — here are the ways you can retrieve it, depending on your needs. • Use the Analytics API: call the List Sessions endpoint to get sessions for a project; each session object includes a
sessionId
. a. Example:
Copy code
curl -H "Authorization: Bearer $TOKEN" \
     "<https://cloud-api.livekit.io/api/project/$PROJECT_ID/sessions>"
• From server-side room/job context: in Agents
JobContext
you can access room identifiers (e.g.,
ctx.job.room.name
or
ctx.room.name
) to correlate with sessions. • From session/detail endpoints or participant lists: session details and participant connection timestamps returned by the analytics/session endpoints let you correlate participants or tracks to a specific
sessionId
. Would you like the exact Analytics API response format or help locating the
sessionId
for a specific project or job? Sources: Analytics API | LiveKit docs | Job lifecycle | LiveKit docs
e
is there 1:1 relation between job and session id ?
t
Short answer: No — job IDs and session IDs are not guaranteed to be 1:1. • A job ID identifies a single agent execution (one agent invocation). • A session ID (room session) identifies the overall LiveKit communication session for a room. Relationships: • One agent job → one job ID and one agent session context (1:1 for that agent execution). • One room session → can contain many agent jobs (many job IDs map to the same session ID). • If your setup dispatches a single agent per room, you'll see a 1:1 correspondence by design, but that is not enforced by the system. Would you like help mapping job IDs to session IDs from your Analytics API response or agent logs? Sources: Agents (Node.js) | livekit/livekit_composite | DeepWiki | Job lifecycle | LiveKit docs | Analytics API | LiveKit docs | Agent dispatch | LiveKit docs | Observability data hooks | LiveKit docs
e
is there a no way to get the session id when the session starts or ends ?
t
You're asking whether you can obtain a LiveKit session ID when a session starts or ends — yes. Here are the practical ways to get it. • Analytics API (recommended): Call the List Sessions endpoint to see active sessions; each session object includes
sessionId
. Use the session list at session start and the session detail endpoint after end to get
sessionId
, start/end times, and final metadata. ◦ Example:
Copy code
curl -H "Authorization: Bearer $TOKEN" \
      "<https://cloud-api.livekit.io/api/project/$PROJECT_ID/sessions>"
• Correlate from agent/job context: In Agents, use
JobContext
(e.g.,
ctx.room.name
or
ctx.job.room.name
) to identify the room; then query the Analytics API to find the matching
sessionId
. Agents also expose lifecycle hooks (e.g.,
AgentSession
close event) you can use to trigger the lookup at session end. • Room lifecycle events: Listen for room disconnection reasons such as
ROOM_CLOSED
(emitted when all participants leave). When that event fires, query the Analytics session detail for the room to obtain the sessionId and end timestamp. Do you want a short script to call the Analytics API and map
roomName
to
sessionId
, or help wiring this into your agent/session event handler? Sources: Analytics API | LiveKit docs
e
what is the difference between shutdown callback and on session end hook ?
t
You're asking for the difference between the shutdown callback and the on-session-end hook — here’s a concise comparison and when to use each. • on_session_end (Python only) ◦ Trigger: Runs when a session ends (part of the session termination flow). ◦ Purpose: Produce a final session report or export structured session data (transcripts, events, metadata). ◦ Access: Full session data via
ctx.make_session_report()
. ◦ Defined via:
@server.rtc_session(on_session_end=...)
. ◦ Use it to: Save analytics, export transcripts, or persist session-level records. • Shutdown callback (Python & Node.js) ◦ Trigger: Runs after
session.shutdown()
/
ctx.shutdown()
when the session is closing, before the process exits. The framework waits (default up to 60s) for these callbacks to finish. ◦ Purpose: Cleanup resources — close DB connections, flush logs, save transient state. ◦ Access: Session is already closing; less direct access to live session internals. ◦ Defined via:
ctx.add_shutdown_callback(...)
. ◦ Use it to: Ensure graceful cleanup and resource release. How they fit together: • In Python you can use both:
on_session_end
to generate/export the final session report, then shutdown callbacks to perform cleanup. • In Node.js use shutdown callbacks for cleanup since
on_session_end
is not available. Would you like a short Python example showing both wired together? Sources: Job lifecycle | LiveKit docs | Observability data hooks | LiveKit docs