<@U07FRRZH2GN> how to get the gemini live api's to...
# ask-ai
a
@icy-policeman-64898 how to get the gemini live api's tocken usage for audio input and audio output with the logs
✅ 1
t
Thanks for reaching out, Abhishek. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Thanks — I’m responding about how to get Gemini Live API token usage for audio input/output and the related logs. Short answer: • Token counts for audio input and audio output are emitted in the
metrics_collected
event from an
AgentSession
as a
RealtimeModelMetrics
payload (it includes per-modality token statistics). • To retain and view those metrics after a session ends, enable Agent observability on your project and use the Agent Console Usage pane, which shows cumulative token and audio usage. • Example guidance: some models (e.g., “Gemini Live 2.5 Flash Native Audio”) count ~960 audio input and 960 audio output tokens per minute for pricing/usage. To help you further, please tell me: 1. Are you using the AgentSession events in a running session or trying to fetch past session logs? 2. Which environment/project and model (e.g., Gemini Live 2.5) are you using? 3. Do you already have Agent observability enabled in the project console? With those details I’ll give exact steps or the event payload/example you can parse to extract audio input/output token counts. Sources: https://livekit.com/pricing.md| | Agent Console | LiveKit Documentation, with interactive elements
a
for gemini-3.1-flash-live-preview
t
Great — thanks for specifying
gemini-3.1-flash-live-preview
. Here’s how to get audio input/output token usage and related logs for that model. What you’ll use • The
metrics_collected
event emitted by an
AgentSession
. It contains a
RealtimeModelMetrics
payload with per-modality token stats (audio input and audio output). • The Agent Console’s Usage pane and Agent observability to retain and view session metrics after the session ends. Steps to retrieve token usage and logs 1. Ensure Agent observability is enabled for your project in the Agent Console so session metrics and logs are retained. 2. While a session is running, listen for
metrics_collected
events from the
AgentSession
. Parse the
RealtimeModelMetrics
payload to read token usage fields for: ◦ audio input tokens ◦ audio output tokens 1. For historical or aggregated views, open the Agent Console → Usage pane to see cumulative token/audio usage for the project and model (
gemini-3.1-flash-live-preview
). 2. If you need per-session transcripts or detailed logs, ensure observability is on; those artifacts are not retained by default after session end unless observability is enabled. If you want, I can: • Show an example
metrics_collected
payload and the exact fields to parse. • Walk through enabling Agent observability in your console if you tell me whether it’s already enabled. Which would you like?, with interactive elements
a
Show an example
t
Below is an example
metrics_collected
event payload (JSON) you would receive from an
AgentSession
that includes
RealtimeModelMetrics
with per-modality token stats for
gemini-3.1-flash-live-preview
. Parse the
audio_input_tokens
and
audio_output_tokens
fields (names shown below) to get token usage for audio.
Copy code
{
  "event": "metrics_collected",
  "timestamp": "2026-05-10T14:23:45.123Z",
  "session_id": "agent-session-abc123",
  "agent_id": "agent-xyz789",
  "model": "gemini-3.1-flash-live-preview",
  "realtime_model_metrics": {
    "request_id": "req-0001",
    "duration_ms": 1250,
    "latency_ms": 240,
    "total_tokens": 1840,
    "per_modality": {
      "text": {
        "input_tokens": 120,
        "output_tokens": 80
      },
      "audio": {
        "audio_input_tokens": 960,
        "audio_output_tokens": 680
      },
      "vision": {
        "input_tokens": 0,
        "output_tokens": 0
      }
    },
    "billing_breakdown": {
      "text_tokens": 200,
      "audio_tokens": 1640
    }
  },
  "session_state": {
    "is_active": true,
    "participants": 2
  }
}
What to extract • audio input tokens:
realtime_model_metrics.per_modality.audio.audio_input_tokens
• audio output tokens:
realtime_model_metrics.per_modality.audio.audio_output_tokens
• total tokens (if needed):
realtime_model_metrics.total_tokens
• timestamp/session id for correlating logs:
timestamp
,
session_id
If you want, I can: • Show a short parsing snippet in your preferred language (Node, Python, or Go) to extract those fields. • Show how to aggregate these metrics across multiple
metrics_collected
events for a session or project. Which would you prefer?, with interactive elements