how can I track metrics of realtime model
# ask-ai
q
how can I track metrics of realtime model
t
Thanks for reaching out, Harsh. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding to your question about how to track metrics for a realtime model. You can track realtime-model metrics by subscribing to the AgentSession’s
metrics_collected
event. That event emits structured performance data for each agent response (LLM, TTS, STT, VAD, turn latency, token usage, etc.), including TTFT (time to first token) and TTFB (time to first byte). Quick implementation outline (Python): 1. Subscribe to metrics events
Copy code
session = AgentSession(llm=realtime_model_instance)

@session.on("metrics_collected")
def on_metrics_ev(ev: MetricsCollectedEvent):
    print("LLM Metrics:", ev.metrics.llm)
    print("TTS Metrics:", ev.metrics.tts)
    print("STT Metrics:", ev.metrics.stt)
1. Aggregate metrics across the session with UsageCollector
Copy code
usage_collector = metrics.UsageCollector()

@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
    usage_collector.collect(ev.metrics)

# When the session ends
summary = usage_collector.get_summary()
print("Usage Summary:", summary)
What you’ll get • TTFT and TTFB values for each response • Turn latency, token counts, and model identification • STT/TTS timings and VAD events where applicable • Structured objects you can log, emit to a monitoring pipeline, or display live Notes and next steps • Ensure your AgentSession uses a realtime model (e.g.,
openai.realtime.RealtimeModel()
or another supported provider). • You can log these events in real time (console, Rich, or a dashboard) or forward them to external monitoring/metrics systems for aggregation and alerting. Would you like: • A short example that forwards metrics to Prometheus/StatsD? • A Node.js example instead of Python? • Help mapping specific metrics (e.g., TTFT, TTFB) to your existing dashboards? Tell me which follow-up you prefer and any details about your stack (language, monitoring tools). I’ll tailor the next steps. Sources: Agents (Node.js) | livekit/livekit_composite | DeepWiki | Build a multilingual voice agent that automatically switches languages | Li... | Realtime models overview | LiveKit Documentation | LLM Metrics | LiveKit Documentation