I have a voice agent setup with twilio, is there a...
# ask-ai
a
I have a voice agent setup with twilio, is there a way to get the entire call duration from livekit itself, we are currently calculating it on our end using the time diff when user joins and leaves the room. Thanks!.
t
Thanks for reaching out, Ayush. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I'm happy to help you understand how LiveKit provides call duration metrics at both the room and participant levels: • Room-Level Duration: LiveKit keeps track of the total duration of rooms in seconds using the
promRoomDuration
metric. This is calculated once a room ends. • Participant-Level Duration: The
promSessionDuration
metric records how long each participant's session lasts, measured in milliseconds. • Analytics: With LiveKit Cloud analytics, you’ll find "total connection minutes" on session pages, which shows the combined call duration for all participants. Plus, you can easily filter and analyze this data over different time ranges. If you’d like, I’m here to guide you through setting up or accessing these metrics—just let me know how I can assist! Sources: pkg/telemetry/prometheus/rooms.go | Say hello to improved Cloud analytics | livekit/livekit_analytics.pb.go
a
how can i access this ? will it be available in agentSession ? also can you attach the doc link for this promRoomDuration ?
t
Thanks for reaching out! The
promRoomDuration
metric is part of LiveKit's Prometheus-based telemetry system and helps track room durations in seconds. It’s not directly available within the
AgentSession
context, but don’t worry—I’m here to guide you through how to access it: 1. First, make sure Prometheus monitoring is enabled on your LiveKit server. 2. Then, you can scrape the
/metrics
endpoint, where the
livekit_room_duration_seconds
metric is available. If you want to correlate this with
AgentSession
, using timestamps or shared identifiers like
room_sid
(when available) can help you match room-level telemetry with agent session activity smoothly. I wasn’t able to find a direct documentation link for
promRoomDuration
, but please don’t hesitate to reach out if you’d like any help setting up Prometheus or accessing these metrics—I’m happy to assist! Sources: CHANGELOG.md | Capturing metrics | LiveKit Docs | Logs, metrics, and telemetry | LiveKit Docs | metrics/metrics_llm.py
a
so without setting up prometheus is there any other way to get the call/room duration ?
t
I'm happy to help you find call or room duration without needing to set up Prometheus! Here are a few friendly options you can try: 1. Webhooks: You can enable webhooks for events like
room_started
and
room_ended
. These events come with timestamps (
creation_time
and
ended_at
) that make it easy to calculate the duration. 2. Analytics Event Streams: Another great way is to subscribe to real-time event streams which provide useful metrics such as
started_at
and
duration_ns
. 3. Custom Observers: If you prefer a programmatic approach, LiveKit’s
roomobs
package is super handy for tracking session durations. For instance, the
RoomSessionReporter
interface lets you report start and end times seamlessly. I hope these options give you some flexibility without the need for Prometheus. If you'd like, I’m here to guide you through setting up webhooks or implementing custom observers—just let me know! Sources: protobufs/livekit_sip.proto | pkg/telemetry/telemetryfakes/fake_telemetry_service.go | pkg/stats/monitor.go | Creating and Publishing Custom Metrics
a
getting this error what may be the issue ? 2025-09-28 125215,461 - WARNING livekit.agents - The room connection was not established within 10 seconds after calling job_entry. This may indicate that job_ctx.connect() was not called. {"pid": 41350, "job_id": "AJ_owGfSt4uAy9j"}
t
It looks like the error is happening because the room connection didn’t get established within the expected time. I’d love to help you sort this out! Could you share a bit more about your setup? • Are you using a specific SDK or API to connect to the room? • Is this issue happening all the time, or just occasionally? • Have there been any recent changes to your configuration or network environment? Getting these details will really help us understand what’s going on and find the best solution for you.
a
i am using the sdk
t
It looks like this error usually happens when the room connection isn’t established within 10 seconds after calling
job_entry
. This might be because
job_ctx.connect()
isn’t called quickly enough. Don’t worry, here are some helpful steps you can try to resolve this: 1. Verify Connection Call: Double-check that
job_ctx.connect()
is being called within those crucial 10 seconds after
job_entry
. 2. Check Network Conditions: Keep an eye on your network, especially if you’re switching between WiFi and cellular—sometimes that can affect the connection. 3. Room Name Uniqueness: Try to avoid reusing the same room name too quickly, as this might cause some unexpected issues. 4. Timeout Configuration: If necessary, you can also adjust the default connection timeout in the SDK’s settings to give it a bit more time. If you’d like, I’m here to help you walk through these steps or troubleshoot further. Just let me know! Sources: livekit-agents/livekit/agents/ipc/job_proc_lazy_main.py | agents/src/ipc/job_proc_lazy_main.ts | lib/src/constants.dart | Getting Help | livekit/livekit_composite | DeepWiki | Avoiding Room ID Reuse When Re-Creating Rooms With the Same Name
a
Can you go throughly through the docs and tell me if there is a way i can get the entire call duration from when the session starts and ends ? for voice agents ? maybe in metadata ? when the call is ended ?
t
I'd love to help you retrieve the entire call duration for voice agents, including session start and end times. Here are a few options you can explore: 1. Analytics API: This is a great way to list sessions and get detailed information, like start and end timestamps. It’s probably the most straightforward method for accessing historical session data. 2. Real-Time Metrics: You can subscribe to
MetricsCollectedEvent
during active sessions to keep track of timing metrics as they happen. 3. Session Lifecycle Tracking: Another approach is to monitor session start and termination events right within your agent implementation. The protocol conveniently includes explicit
startTime
and
endTime
fields. If you’d like, I’m here to guide you through implementing any of these methods or to discuss your specific needs. Just let me know how I can assist! Sources: LiveKit Pricing | Agent Session & Client Integration | livekit/livekit_composite | DeepWiki | Sources/LiveKit/Protos/livekit_models.pb.swift | livekit-agents/livekit/agents/voice/agent_activity.py | Analytics API | LiveKit docs
a
Can you show an example object that gets stored in my s3 when i use recording can i use that? for start and end time ?
t
When you use LiveKit recording with S3, the metadata stored there can include custom key-value pairs that you define in the
Metadata
field of the
S3Upload
configuration. However, I want to let you know that start and end times aren’t included automatically in the metadata by default. If having start and end times in your S3 metadata is important for you, you can definitely add them yourself during the egress setup by filling the
Metadata
field with those values. Please feel free to reach out if you'd like some help on how to include custom timestamps in your recording metadata or if you’re interested in other ways to access timing data. I’m here to assist you! Sources: livekit/livekit_egress.pb.go | Sources/LiveKit/Protos/livekit_metrics.pb.swift | Understanding Transcript Timing in Voice Conversations | cmd/lk/examples/web-egress.json | app/api/record/start/route.ts
a
{"egress_id":"EG_FUeEjgwe47MWc","room_id":"RM_7gp6KNgeGXbE","room_name":"55-generic-voice-agent-17518912wgvwe52","started_at":1751891226235050387,"ended_at":1751891300163694346,"files":[{"filename":"55/livekit/12-55-avqeric-voice-agent-1751891220952-28697.mp4","location":"https:..."}]} when do i get data like this ? when i enable recording, is data like this also recieved ? if yes when and where ? as this has start and end time ?
t
Thank you for sharing the data, including the
started_at
and
ended_at
timestamps. These are part of the
EgressInfo
message, and you can access this information in a few different ways: 1. When Starting Egress: You'll receive the
EgressInfo
object as part of the response when you begin a recording using the Egress API. 2. When Stopping Egress: The
EgressInfo
is updated and returned once you stop the recording. 3. Via Webhooks: You can get real-time notifications for "Egress Started" and "Egress Ended" events, which include this data. 4. When Listing Egress: By using the
ListEgress
API, you can retrieve details about active or completed recordings, including their timing information. If you'd like, I'm here to help you set up any of these methods so you can easily access the egress data. Just let me know! Sources: livekit-api/livekit/api/egress_service.py | template-sdk/src/index.ts | Webhooks | LiveKit Docs | livekit/livekit_egress.pb.go
a
In my code i dont use stop egress although, so when does the egress actually stop / the recording actually stop ?
t
If
StopEgress
isn’t called, the egress (recording) will stop in these situations: 1. Room Deletion: When the room is deleted, the egress participant leaves, and the recording stops right away. This is actually the best way to automatically stop egress. 2. Duration Limits: Egress will stop once it hits the maximum duration you’ve set for the output type (like a file or stream). 3. Stream Outputs Removed: For streaming egress, if all the stream URLs are taken away, the egress will stop on its own. If none of these happen, the egress will keep running. Please feel free to reach out if you’d like some guidance on setting up automatic stop conditions or managing the egress lifecycle in your code—I’m here to help! Sources: pkg/pipeline/controller.go | protobufs/livekit_egress.proto
a
okay, when i start the room composite egress do i also revieve a json file ? automatically containing the info of the egress ? eg {"egress_id":"EG_FUeEjgwe47MWc","room_id":"RM_7gp6KNgeGXbE","room_name":"55-generic-voice-agent-17518912wgvwe52","started_at":1751891226235050387,"ended_at":1751891300163694346,"files":[{"filename":"55/livekit/12-55-avqeric-voice-agent-1751891220952-28697.mp4","location":"https:..."}]} ? this is my req : req = api.RoomCompositeEgressRequest( room_name=self.ctx.room.name, audio_only=True, file_outputs=[ api.EncodedFileOutput( file_type=api.EncodedFileType.MP4, filepath=file_path, s3=api.S3Upload( bucket=os.getenv("CLOUD_STORAGE_BUCKET"), region=os.getenv("CLOUD_STORAGE_REGION"), access_key=os.getenv("AWS_ACCESS_KEY_ID"), secret=os.getenv("AWS_SECRET_ACCESS_KEY"), force_path_style=True, ), ) ], )
t
Thanks for reaching out! I wanted to share that LiveKit doesn’t automatically create a JSON file with egress information when you start a room composite egress. But no worries—the API call to start egress does return an
EgressInfo
object, which includes all the important details like the egress ID, room ID, start and end times, and file outputs. If you'd like, you can capture this response in your code and save it as a JSON file. Just let me know, and I’d be happy to walk you through how to do that! Sources: livekit/livekit_egress.twirp.go | packages/livekit-server-sdk/src/EgressClient.ts | README.md | Universal Egress
a
also as i dont have any stop_egress, does lkapi.aclose handle it ? to stop the egress ?
t
Thanks for reaching out! From what we have, it’s not entirely clear if
lkapi.aclose
will stop egress when
StopEgress
isn’t explicitly called. To be on the safe side,
StopEgress
is the best way to properly end an active egress session. If you’d like, I’m here to help you implement
StopEgress
or explore other options to manage your egress sessions smoothly. Just let me know! Sources: packages/livekit-server-sdk/src/EgressClient.ts | Egress API | LiveKit Docs | egress/recording_agent.py | examples/api.py | lib/livekit/egress_service_client.rb
a
when i am calling stop_egress, i am recieving started_at in the return object but not ended_at, why is this ?
t
I’m glad you asked about the
StopEgress
call! When you use it, the
EgressInfo
object you get back will have the
started_at
timestamp right away. However, the
ended_at
timestamp will only show up once the egress has fully stopped. This way, you can be sure that
ended_at
truly reflects when the egress session ended. If you’re looking for the
ended_at
timestamp, you have a couple of friendly options: you can either wait for the egress to finish or keep an eye on the "Egress Ended" webhook event, which will also provide this information. I hope this helps clarify things for you! Sources: livekit-protocol/src/livekit.rs | protobufs/livekit_egress.proto | pkg/service/egress.go | Webhooks | LiveKit Docs | livekit-protocol/livekit/protocol/egress.pyi
a
how do i know if egress is ended and ended_at is availabe ?
t
I'd be happy to help you determine if egress has ended and when the
ended_at
timestamp becomes available. Here are a few ways you can check: 1. Check Egress Status: Take a look at the
status
field in
EgressInfo
. When the egress has finished, it will show
EGRESS_COMPLETE
,
EGRESS_FAILED
, or
EGRESS_ABORTED
, and you'll see the
ended_at
timestamp filled in. 2. Monitor Webhooks: You can use the "Egress Ended" webhook event, which conveniently includes the
ended_at
timestamp right when the egress completes. 3. Poll with ListEgress API: By calling
list_egress()
, you can check the status of your egress sessions. Once they're done, the
ended_at
field will be set. If you'd like, I’m here to assist you with setting up webhooks or using the API to keep an eye on your egress status. Just let me know! Sources: livekit-api/livekit/api/egress_service.py | protobufs/livekit_egress.proto | Webhooks | LiveKit Docs | packages/livekit-server-sdk/src/WebhookReceiver.ts
a
Okay thanks, i now want to explore webhooks too, how can i configure it ? can i subscribe to specific events or i will recieve all events and need to filter on my own, basically i want webhook triggered when participant joins/leaves the room, to be albe to calculate duration. can you also give example of what type of data i will get ?
t
I'd be happy to help you configure webhooks in LiveKit! Here’s a simple step-by-step guide to get you started: 1. Configuration: ◦ If you’re using LiveKit Cloud, you can easily set up webhooks in the Settings section of your project dashboard. ◦ For those who are self-hosting, just add the
webhook
section to your configuration file and specify the URLs where you'd like to receive events. 1. Event Filtering: To make sure you only get the events that matter to you, you can configure
FilterParams
with
include_events
and
exclude_events
arrays. For example, you might want to track when participants join or leave by subscribing to
participant_joined
and
participant_left
events. 2. Webhook Payload: When an event occurs, the webhook sends a payload containing useful information like
event
(the type of event),
room
(details about the room),
participant
(info about the participant for join/leave events), and timestamps such as
created_at
. Here’s an example of what the payload looks like for a
participant_joined
event:
Copy code
{
  "event": "participant_joined",
  "room": {
    "sid": "RM_123",
    "name": "example-room"
  },
  "participant": {
    "sid": "PA_456",
    "identity": "user123"
  },
  "id": "event-uuid",
  "created_at": 1696523456
}
If you have any questions or need a hand setting up your webhooks or filtering specific events, please don’t hesitate to ask. I’m here to help! Sources: packages/livekit-server-sdk/README.md | Webhooks | LiveKit Docs | config-sample.yaml | egress/notify_options.go | Webhook & Event System | livekit/livekit_composite | DeepWiki