busy-breakfast-32623
09/23/2025, 7:06 AMtall-airline-16756
09/23/2025, 7:06 AMtall-airline-16756
09/23/2025, 7:07 AMtotal_text_input_tokens, total_text_output_tokens, total_audio_input_tokens) by their corresponding rates. 3. Finally, add up the costs from all categories to get your total cost. If you’d like, I’m here to help you access the metrics programmatically or guide you through the calculation process. Just let me know! Sources: livekit-plugins/livekit-plugins-google/livekit/plugins/google/beta/realtime...busy-breakfast-32623
09/23/2025, 7:09 AMtall-airline-16756
09/23/2025, 7:10 AMusage_metadata from the API response and see if there’s an entry in response_tokens_details where the modality is marked as AUDIO. 2. If you don’t find such an entry, it probably means the API isn’t categorizing or reporting audio output tokens. If you find that the API response is missing this data, it might be worth reaching out for further investigation or clarification from the API provider. Please feel free to ask if you'd like a hand inspecting the usage_metadata or if you have any other questions—I’m here to help! Sources: livekit-agents/livekit/agents/metrics/utils.py | plugins/openai/src/realtime/api_proto.tsbusy-breakfast-32623
09/23/2025, 7:12 AMtall-airline-16756
09/23/2025, 7:13 AM@session.on("metrics_collected") event doesn’t give direct access to the raw usage_metadata. Instead, it provides structured metrics like RealtimeModelMetrics or LLMMetrics, which are thoughtfully derived from the usage_metadata. Here’s a friendly example of how you can work with the available metrics: python @session.on("metrics_collected") def _on_metrics_collected(ev: MetricsCollectedEvent): m = ev.metrics if isinstance(m, RealtimeModelMetrics): print(f"Input Tokens: {m.input_tokens}, Output Tokens: {m.output_tokens}") print(f"Audio Input Tokens: {m.input_token_details.audio_tokens}") print(f"Text Input Tokens: {m.input_token_details.text_tokens}") print(f"Audio Output Tokens: {m.output_token_details.audio_tokens}") print(f"Text Output Tokens: {m.output_token_details.text_tokens}") If you’re looking for the raw usage_metadata, it’s not directly available through the public API. But no worries! You can enable OpenTelemetry tracing to capture detailed trace data, including token usage and other helpful attributes. I’m here to help if you want assistance setting up tracing or if you have any other questions — just let me know! Sources: examples/voice_agents/langfuse_trace.py | plugins/google/src/beta/realtime/realtime_api.ts | Logs, metrics, and telemetry | LiveKit Docs