LiveKit Integration
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.
Automatically track usage for LiveKit Agents using the LiveKitPaygentHook.
How it works
The LiveKitPaygentHook intercepts metrics from LiveKit's AgentSession or VoicePipelineAgent and maps them to Paygent's voice tracking API. It handles LLM tokens, STT duration, and TTS character counts automatically.
Manual Configuration
If your LiveKit metrics don't include provider/model information, or if you want to override the detected values, you can pass llm_config, stt_config, and tts_config directly to the hook.
Example Usage
Integrating Paygent into your LiveKit Agent is as simple as creating a hook and attaching it to your session:
1from paygent_sdk import Client
2from paygent_sdk.wrappers import LiveKitPaygentHook
3from paygent_sdk.models import LLMConfig, STTConfig, TTSConfig
4
5# 1. Initialize Paygent
6paygent = Client("your-paygent-api-key")
7
8@server.rtc_session()
9async def my_agent(ctx: JobContext):
10 # 2. Setup your LiveKit AgentSession
11 session = AgentSession(...)
12
13 # 3. Attach Paygent Hook
14 hook = LiveKitPaygentHook(
15 paygent_client=paygent,
16 agent_id="your-agent-id",
17 customer_name="Customer 123",
18 customer_id="customer-123",
19 session_id=ctx.job.id, # Use LiveKit job ID as session ID
20 indicator_name="voice-call-completed",
21 additional_indicators=["total-payout"], # optional
22 llm_config=LLMConfig(model="gpt-4o-mini", provider="openai"),
23 stt_config=STTConfig(model="nova-3", provider="deepgram"),
24 tts_config=TTSConfig(model="sonic-3", provider="cartesia")
25 )
26 hook.attach(session)
27
28 # 4. Start your session normally
29 await session.start(agent=Assistant(), room=ctx.room)
30 await ctx.connect()Why use the LiveKit Hook?
Automatically converts LiveKit metric formats (seconds, tokens) into Paygent-ready billing data.
Automatically starts and finalizes voice sessions in Paygent based on LiveKit session events.
Simultaneously tracks LLM tokens, STT minutes, and TTS characters without additional manual tracking code.
Was this page helpful?
Need help? Contact us at support@withpaygent.com