adorable-bear-14321
05/12/2026, 2:22 PMtall-airline-16756
05/12/2026, 2:22 PMtall-airline-16756
05/12/2026, 2:22 PMmetrics_collected events during the session and sending a final summary when the session ends (or using the Data Collection mode payload and adding metrics yourself).
How to implement (high level):
1. Subscribe to metrics events during the session:
◦ Listen for AgentSessionEventTypes.MetricsCollected (or your runtime’s equivalent) and accumulate relevant fields (e.g., input/output tokens, inference times, audio durations).
◦ Example pattern:
session.on(voice.AgentSessionEventTypes.MetricsCollected,
lambda ev: usage_collector.collect(ev.metrics))
1. Detect session end:
◦ Use the session/room end event or the Agent Builder Data Collection end webhook (the job/room ended_at payload).
1. Emit/send the summary at end:
◦ On session end, compute aggregates (totals, averages) from your collector and either:
▪︎ POST the summary to your endpoint, or
▪︎ Emit a custom event into your system or room for downstream consumers.
1. Optional: include summary in Data Collection mode
◦ If you use Data Collection mode, add your computed usage metrics into the final structured payload (summary or results) before sending it to your configured endpoint.
If you’d like, tell me:
• Which SDK/language you’re using, and
• Whether you prefer the summary sent via webhook or emitted in-room,
and I’ll provide a short code example tailored to that environment.
Sources: Agent Console | LiveKit Documentation | Collect structured data with LiveKit Agents | LiveKit | Agent Builder | LiveKit Documentation | Creating and Publishing Custom Metrics, with interactive elementsadorable-bear-14321
05/12/2026, 2:47 PMLLMModelUsage, TTSModelUsage, STTModelUsage, / session.usage.model_model_usagetall-airline-16756
05/12/2026, 2:48 PMModelUsageCollector, LLMModelUsage, TTSModelUsage, STTModelUsage, and session.usage.model_model_usage. Short, practical guidance:
• ModelUsageCollector
◦ Use this to aggregate metrics throughout a session. Subscribe to metrics_collected events and let the collector sum token counts, audio durations, and timings so you can produce a final summary at call end.
• LLMModelUsage
◦ Use per-inference when you need granular LLM data (input/output token counts, per-call cost/latency). Good for debugging or per-turn accounting.
• TTSModelUsage
◦ Use per-inference to capture generated audio metrics (duration, characters). Useful when you need per-synthesis cost, quality analysis, or to attribute audio output to a step.
• STTModelUsage
◦ Use per-inference to capture speech-to-text metrics (audio duration transcribed, confidence metadata). Good for per-segment transcription accounting and troubleshooting.
• session.usage.model_model_usage
◦ Read this for session-level totals once aggregated. Use it for billing reports, dashboards, or adding a usage summary to your end-of-call payload.
If you want, tell me which SDK/language you’re using and whether you prefer the final summary pushed as a webhook or emitted in-room — I’ll give a short code example.
Sources: Adaptive interruption handling | LiveKit Documentation | Agent Console | LiveKit Documentation, with interactive elementsadorable-bear-14321
05/12/2026, 2:49 PMtall-airline-16756
05/12/2026, 2:49 PMLLMModelUsage, TTSModelUsage, and STTModelUsage are the per-inference usage types.
◦ ModelUsageCollector (or UsageCollector) is the helper to aggregate metrics during a session.
◦ The supported session-level property to read at end-of-call is session.usage.model_usage.
• Best practice to log usage at call end:
a. Aggregate metrics during the session (subscribe to metrics_collected and use `ModelUsageCollector`/`UsageCollector`).
b. On session shutdown/room end, read session.usage.model_usage and log or POST those records.
If you tell me your SDK/language, I’ll provide a short code snippet for subscribing, collecting, and logging at session end.
Sources: Build a multilingual voice agent that automatically switches languages | Li..., with interactive elementsadorable-bear-14321
05/12/2026, 3:12 PMtall-airline-16756
05/12/2026, 3:12 PMmetrics_collected is deprecated. Short answer and recommended approach:
• InterruptionMetrics are emitted when Adaptive Interruption Handling is enabled (default on LiveKit Cloud) and are available via per-plugin / per-session metrics listeners or from session.usage at session end.
• The pattern is to capture interruption metrics from the session’s metrics stream using the newer per-plugin listeners or a UsageCollector, then read session-level data at shutdown.
Steps to implement:
1. Ensure adaptive interruption handling is enabled (or default on LiveKit Cloud) and VAD/aligned STT are active.
2. Add a per-plugin or session metrics listener to collect interruption metric objects as they arrive (they’ll contain fields like numInterruptions, detectionDelay, predictionDuration, etc.). If your runtime provides a named event for plugin metrics, use that; otherwise use the updated metrics listener pattern your SDK exposes.
3. Aggregate during the session (use ModelUsageCollector / UsageCollector or your own collector).
4. At session end, read session.usage (specifically session.usage.model_usage) or emit/post your aggregated InterruptionMetrics summary.
If you tell me which SDK/language you’re using (agents-js, Python, etc.), I’ll provide a concise code example showing the exact listener and shutdown logging for InterruptionMetrics.
Sources: Adaptive interruption handling | LiveKit Documentation, with interactive elementsadorable-bear-14321
05/12/2026, 3:17 PMtall-airline-16756
05/12/2026, 3:18 PMModelUsageCollector / UsageCollector or your own collector) to sum numInterruptions, numBackchannels, detectionDelay, etc.
3. On session shutdown / room end, read session.usage.model_usage and your aggregated interruption metrics and log or POST a final summary.
Where the metrics appear
• Live, via the per-plugin/per-session metrics listener events.
• At end of call via session.usage (session.usage.model_usage) and your own aggregated InterruptionMetrics summary.
Needed from you to give code
• Which SDK/language are you using (agents-js, Python, etc.) and do you want the final summary sent as a webhook or emitted in-room?
Tell me that and I’ll provide a concise code example.
, with interactive elementsadorable-bear-14321
05/12/2026, 4:02 PM@session.llm.on("metics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
metrics.log_metrics(ev.metrics, logger=logger)
this is not workingtall-airline-16756
05/12/2026, 4:02 PMsession.llm for "metics_collected" isn't working. Quick fixes and the correct approach:
• The metrics_collected event on session.llm is deprecated. Attach listeners at the session or per-plugin level instead (or use the runtime’s per-plugin metrics hook).
• Also note your example has a typo: "metics_collected" → should be "metrics_collected" (but still don’t attach it to session.llm).
Recommended Python pattern:
1. Attach to session-level metrics:
def _on_metrics_collected(ev: MetricsCollectedEvent):
# filter for the metric type you need, e.g., InterruptionMetrics
metrics.log_metrics(ev.metrics, logger=logger)
# attach to session, not session.llm
session.on("metrics_collected", _on_metrics_collected)
1. If using realtime models or plugin-specific metrics, use the per-plugin listener pattern:
def _sync_wrapper(ev: MetricsCollectedEvent):
if isinstance(ev.metrics, RealtimeModelMetrics) or ev.metrics.type == "interruption_metrics":
asyncio.create_task(_on_metrics_collected(ev))
session.on("metrics_collected", _sync_wrapper)
1. Aggregate during the session (UsageCollector or custom collector) and read session.usage.model_usage on shutdown for a final summary.
If you want, tell me:
• which SDK and version (agents-js, Python SDK + version), and
• paste the exact error or logs you see —
and I’ll give a tailored, runnable snippet to fix your handler and capture InterruptionMetrics.
Sources: Adaptive interruption handling | LiveKit Documentation, with interactive elementsadorable-bear-14321
05/12/2026, 4:05 PMsession.on("metrics_collected", _on_metrics_collected)
but this is deprecatedtall-airline-16756
05/12/2026, 4:05 PM