> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.withpaygent.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.withpaygent.com/_mcp/server.

# Gemini Realtime (STS)

Track Google Gemini's Multimodal Live API using `track_google_sts`. This integration captures usage metadata directly from Gemini's response turn.

> **Warning**
>
> **Prerequisite:** Complete the [Voice Agent Setup](/documentation/voice-tracking/voice-agent-setup) before implementing STS tracking.

**`gemini_live_sts.py`**

```python title="gemini_live_sts.py"
from paygent_sdk import Client

from paygent_sdk.models import CustomerCreateOrGetRequest

paygent = Client("your-paygent-api-key")
session_id = f"voice_call_{int(time.time() * 1000)}"
customer_id = "customer-123"

# 1. Ensure Customer exists
paygent.create_or_get_customer(CustomerCreateOrGetRequest(
    name="Customer Name",
    external_id=customer_id
))

# 2. Initialize Voice Session
paygent.initialize_voice_session(session_id, "external-agent-id", customer_id)

# 3. Handle Gemini Live turns
async def receive_audio(self):
    while True:
        if self.session is not None:
            turn = self.session.receive()
            async for response in turn:
                if data := response.data:
                    # Handle incoming audio data
                    ...
                
                if usage := response.usage_metadata:
                    # Track usage directly from Gemini usage_metadata
                    paygent.track_google_sts(
                        usage_metadata=usage,
                        session_id=session_id,
                        model="gemini-2.0-flash-exp"
                    )

# 4. Cleanup / Finalize
paygent.set_voice_indicator(session_id, indicator_name, 1.5)
```