Gemini Realtime (STS)
Prerequisite
If you haven't set up a voice agent in the Paygent dashboard yet, please follow our setup guide first. You'll need an Agent ID to start tracking.
Track Google Gemini's Multimodal Live API using track_google_sts. This integration captures usage metadata directly from Gemini's response turn.
gemini_live_sts.py
1from paygent_sdk import Client
2
3from paygent_sdk.models import CustomerCreateOrGetRequest
4
5paygent = Client("your-paygent-api-key")
6session_id = f"voice_call_{int(time.time() * 1000)}"
7customer_id = "customer-123"
8
9# 1. Ensure Customer exists
10paygent.create_or_get_customer(CustomerCreateOrGetRequest(
11 name="Customer Name",
12 external_id=customer_id
13))
14
15# 2. Initialize Voice Session
16paygent.initialize_voice_session(session_id, "external-agent-id", customer_id)
17
18# 2. Handle Gemini Live turns
19async def receive_audio(self):
20 while True:
21 if self.session is not None:
22 turn = self.session.receive()
23 async for response in turn:
24 if data := response.data:
25 # Handle incoming audio data
26 ...
27
28 if usage := response.usage_metadata:
29 # Track usage directly from Gemini usage_metadata
30 paygent.track_google_sts(
31 usage_metadata=usage,
32 session_id=session_id,
33 model="gemini-2.0-flash-exp"
34 )
35
36# 3. Cleanup / Finalize
37paygent.set_voice_indicator(session_id, indicator_name, 1.5)Was this page helpful?
Need help? Contact us at support@withpaygent.com