How to get connection latency using livekit api
# ask-ai
b
How to get connection latency using livekit api
✅ 1
t
Thanks for reaching out, G. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — you’re asking how to get connection latency using the LiveKit API. I’ll be direct about what’s available and then offer practical alternatives you can use depending on your goal. Short answer • LiveKit does not provide a direct API call that returns raw connection latency (e.g., RTT/ping) for participants. • LiveKit exposes a connection quality metric (Excellent / Good / Poor) and other media stats (bitrate, packet loss, frame rate, simulcast layer changes) you can use to assess network performance. • For voice-agent flows, LiveKit agents emit specific latency metrics (TTFT, TTFB, EOU delays) via a
metrics_collected
event. What you can do now • Listen for connection quality changes: ◦ Subscribe to the
ConnectionQualityChanged
event for a participant to receive
ConnectionQuality
values (Excellent / Good / Poor). Use this to adapt your UI or features when quality degrades. • Read real-time media stats: ◦ Collect bitrate, packet loss, and frame rate from the client SDK’s stats APIs or from analytics dashboards (LiveKit Cloud or self-hosted exports). Packet loss and bitrate are primary inputs used in the connection quality score. • For voice-agent latency metrics: ◦ If you’re using LiveKit Agents, use the
metrics_collected
event to get TTFT, TTFB, and other timing metrics relevant to LLM/TTS flows. If you need an actual numeric RTT/ping • Option A — Application-level ping: a. Implement a simple ping over your LiveKit data channel or signaling channel: send a timestamped message and measure the round-trip time when you get the reply. b. Average or percentile the RTT samples to smooth noise and monitor trends. • Option B — WebRTC stats (client-side): a. On the client, pull WebRTC getStats (or SDK-equivalent) which may expose
roundTripTime
or related RTT/jitter stats from the RTCPeerConnection. b. Note: LiveKit’s connection quality score explicitly excludes RTT and jitter from its quality calculation, but you can still collect these values locally for your own monitoring. Questions to narrow this down • Which SDK are you using (JS, iOS, Android, or server)? I can provide example code for the appropriate SDK. • Do you want a binary signal (good/poor) or a numeric RTT value for monitoring or UI display? • Are you running on LiveKit Cloud or a self-hosted LiveKit server? If you tell me the SDK and whether you want connection-quality events or raw RTT samples, I’ll provide precise example code and the recommended approach for your use case. Sources: client-sdk-js | livekit/livekit_composite | DeepWiki | How is Connection Quality determined? | examples/survey | livekit/livekit_composite | DeepWiki | Build Your First AI Voice Agent in Python: Complete Tutorial | LiveKit | LLM Metrics | LiveKit Documentation, with interactive elements