@session.on("metrics_collected") def _on_metri...
# ask-ai
e
@session.on("metrics_collected") def _on_metrics_collected(_ev_: MetricsCollectedEvent): metrics.log_metrics(ev.metrics) usage_collector.collect(ev.metrics) logger.info(f"Metrics collected: {ev.metrics}") how to log stt , tts metrics , llm
t
Thanks for reaching out, Guess. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hi there! To help you log STT, TTS, and LLM metrics in LiveKit, you can make use of the
log_metrics
helper function that comes with the LiveKit Agents SDK. Let me walk you through how to set it up: 1. Listen for the
metrics_collected
Event:
First, subscribe to the
metrics_collected
event on your session. This way, you’ll be able to capture metrics related to STT, TTS, or LLM operations as they happen. 2. Use the
log_metrics
Helper:
Next, simply pass the metrics object you receive to
metrics.log_metrics()
if you’re using Python, or
metrics.logMetrics()
for JavaScript/TypeScript. This handy function takes care of formatting and logging the right fields depending on the type of metric. Here’s a quick example in Python:
Copy code
from livekit.agents import metrics, MetricsCollectedEvent

@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
    metrics.log_metrics(ev.metrics)  # This logs STT, TTS, and LLM metrics automatically
What Gets Logged? • STT Metrics: This includes
audio_duration
(the input audio length) and
duration
(how long processing took). • TTS Metrics: You’ll see
ttfb
(time to first byte),
audio_duration
, and character count logged. • LLM Metrics: This covers
ttft
(time to first token), token usage, and throughput. If you want to dive deeper into your metrics, you can use the
UsageCollector
class to gather data over time, or enable OpenTelemetry for more detailed tracing. I hope this helps you get started smoothly—feel free to reach out if you have any questions! Sources: Logs, metrics, and telemetry | LiveKit docs | livekit-agents/livekit/agents/metrics/base.py | examples/src/basic_agent.ts | metrics/metrics_stt.py
e
livekit-agents[openai,deepgram,cartesia,bey,silero,turn-detector]>=1.2.0 livekit-api>=0.5.0 python-dotenv>=1.0.0 boto3>=1.28.38 requests>=2.31.0 fastapi>=0.115.0 uvicorn>=0.25.0 aiohttp>=3.8.0 asyncio-mqtt>=0.13.0 pydantic>=2.0.0 loguru>=0.7.0 livekit-plugins-noise-cancellation>=0.2.5 aiofiles==24.1.0 aiohappyeyeballs==2.6.1 aiohttp==3.12.15 aiosignal==1.4.0 annotated-types==0.7.0 anyio==4.10.0 asyncio-mqtt==0.16.2 attrs==25.3.0 av==15.1.0 boto3==1.40.22 botocore==1.40.22 certifi==2025.8.3 cffi==1.17.1 charset-normalizer==3.4.3 click==8.2.1 colorama==0.4.6 coloredlogs==15.0.1 distro==1.9.0 docstring_parser==0.17.0 eval_type_backport==0.2.2 fastapi==0.116.1 filelock==3.19.1 flatbuffers==25.2.10 frozenlist==1.7.0 fsspec==2025.9.0 googleapis-common-protos==1.70.0 grpcio==1.74.0 h11==0.16.0 hf-xet==1.1.9 httpcore==1.0.9 httpx==0.28.1 huggingface-hub==0.34.4 humanfriendly==10.0 idna==3.10 importlib_metadata==8.7.0 iniconfig==2.1.0 Jinja2==3.1.6 jiter==0.10.0 jmespath==1.0.1 livekit==1.0.12 livekit-agents==1.2.8 livekit-api==1.0.5 livekit-blingfire==1.0.0 livekit-plugins-bey==1.2.8 livekit-plugins-anam livekit-plugins-cartesia==1.2.8 livekit-plugins-deepgram==1.2.8 livekit-plugins-noise-cancellation==0.2.5 livekit-plugins-openai==1.2.8 livekit-plugins-google==1.2 livekit-plugins-silero==1.2.8 livekit-plugins-turn-detector==1.2.8 livekit-protocol==1.0.5 loguru==0.7.3 MarkupSafe==3.0.2 mpmath==1.3.0 multidict==6.6.4 nest-asyncio==1.6.0 numpy onnxruntime==1.22.1 openai==1.105.0 opentelemetry-api==1.36.0 opentelemetry-exporter-otlp==1.36.0 opentelemetry-exporter-otlp-proto-common==1.36.0 opentelemetry-exporter-otlp-proto-grpc==1.36.0 opentelemetry-exporter-otlp-proto-http==1.36.0 opentelemetry-proto==1.36.0 opentelemetry-sdk==1.36.0 opentelemetry-semantic-conventions==0.57b0 packaging==25.0 paho-mqtt==2.1.0 pillow==11.3.0 pip==25.1.1 pluggy==1.6.0 prometheus_client==0.22.1 propcache==0.3.2 protobuf==6.32.0 psutil==7.0.0 pycparser==2.22 pydantic==2.11.7 pydantic_core==2.33.2 Pygments==2.19.2 PyJWT==2.10.1 pytest==8.4.1 python-dateutil==2.9.0.post0 python-dotenv==1.1.1 PyYAML==6.0.2 regex==2025.9.1 requests==2.32.5 s3transfer==0.13.1 safetensors==0.6.2 six==1.17.0 sniffio==1.3.1 sounddevice==0.5.2 starlette==0.47.3 sympy==1.14.0 tokenizers==0.22.0 tqdm==4.67.1 transformers==4.56.1 types-protobuf==6.30.2.20250822 typing_extensions==4.15.0 typing-inspection==0.4.1 urllib3==2.5.0 uvicorn==0.35.0 watchfiles==1.1.0 websockets==15.0.1 yarl==1.20.1 zipp==3.23.0 pinecone i want for livekit-agents-1.2.5 fix all dependencies
t
I'd love to help you out! Could you please share a bit more about the dependency issues or any error messages you're seeing with
livekit-agents
version 1.2.5? For instance: • Are there any version conflicts or missing dependencies that you've noticed? • Do any specific error messages pop up during installation or when you're running it? Once I have these details, I'll be better equipped to guide you through a solution. Looking forward to helping you get this sorted! Sources: Python Agents Core Architecture | livekit/livekit_composite | DeepWiki | package-lock.json | AI Service Plugin Ecosystem | livekit/livekit_composite | DeepWiki
e
there are lot kindly receheck adn let me lnow
t
I don't have the answer you're looking for. You could also try asking your question: • in one of the other Slack channels or • to https://deepwiki.com/livekit/livekit_composite which is trained on all LiveKit source code If you find the answer, please post it here to help others!