Skip to navigation

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
from paygent_sdk import Client
from paygent_sdk.wrappers import LiveKitPaygentHook
from paygent_sdk.models import STSConfig
# 1. Initialize Paygent
paygent = Client("your-paygent-api-key")
@server.rtc_session()
async def sts_agent(ctx: JobContext):
# LiveKit Realtime Model setup
model = openai.realtime.RealtimeModel()
# ... setup agent and session ...
# 2. Attach Paygent Hook with STSConfig
# This automatically handles initialize_voice_session, tracking, and set_voice_indicator
hook = LiveKitPaygentHook(
paygent_client=paygent,
agent_id="your-external-agent-id",
customer_name="your-customer-name",
customer_id="your-customer-id",
session_id=ctx.job.id,
indicator_name="sts-call-completed",
sts_config=STSConfig(
model="gpt-realtime-2025-08-28",
provider="openai"
)
)
hook.attach(session)
await session.start(agent, room=ctx.room)