LiveKit STS Integration

Automatically track unified Speech-to-Speech (STS) usage for LiveKit Agents using the LiveKitPaygentHook. This is the recommended way to track multimodal sessions.

Prerequisite: Complete the Voice Agent Setup before implementing STS tracking.

Simplified Workflow. The LiveKit hook handles the entire session lifecycle, from initializing the voice session to tracking multimodal usage and setting the final indicator.

Implementation Steps

Step 1 — Initialize Client: Initialize the Paygent Client at the global level.

Step 2 — Attach Hook: The hook automatically calls initialize_voice_session when the room is joined.

livekit_sts_agent.py
1from paygent_sdk import Client
2from paygent_sdk.wrappers import LiveKitPaygentHook
3from paygent_sdk.models import STSConfig
4
5# 1. Initialize Paygent
6paygent = Client("your-paygent-api-key")
7
8@server.rtc_session()
9async def sts_agent(ctx: JobContext):
10 # LiveKit Realtime Model setup
11 model = openai.realtime.RealtimeModel()
12
13 # ... setup agent and session ...
14
15 # 2. Attach Paygent Hook with STSConfig
16 # This automatically handles initialize_voice_session, tracking, and set_voice_indicator
17 hook = LiveKitPaygentHook(
18 paygent_client=paygent,
19 agent_id="your-external-agent-id",
20 customer_name="your-customer-name",
21 customer_id="your-customer-id",
22 session_id=ctx.job.id,
23 indicator_name="sts-call-completed",
24 sts_config=STSConfig(
25 model="gpt-realtime-2025-08-28",
26 provider="openai"
27 )
28 )
29 hook.attach(session)
30
31 await session.start(agent, room=ctx.room)