Automatic Tracking

Automatic tracking simplifies your integration by intercepting calls to LLM providers. You don’t have to manually extract token counts or call sendUsage() for each API request.

Scenario: You’re building a chatbot and making dozens of OpenAI API calls. Manually extracting usage data and calling the Paygent tracking API for each one is tedious and error-prone. You just want the tracking to happen automatically.

Solution: Use Paygent’s automatic wrappers or interceptors.

Automatic tracking uses monkeypatching to intercept calls to LLM providers. This means you don’t have to change how you call the LLM, other than adding three optional tracking parameters.

Call paygent_sdk.init() once. Then, simply pass tracking IDs directly into your standard model calls.

automatic_tracking.py
1import paygent_sdk
2from openai import OpenAI
3
4# Initialize once at application start
5paygent_sdk.init(api_key="your-paygent-api-key")
6
7client = OpenAI()
8
9# Standard call - usage is tracked automatically!
10response = client.chat.completions.create(
11 model="gpt-4o",
12 messages=[{"role": "user", "content": "Explain automatic tracking"}],
13
14 # These parameters are intercepted by Paygent
15 paygent_agent_id="research-agent",
16 paygent_customer_id="user-789",
17 paygent_indicator="explanation-requested"
18)

Manual vs Automatic

FeatureManual TrackingAutomatic Tracking
SetupClient instance setup per callInitialize once / Wrap client
Token ExtractionManual code neededFully automatic
Error RiskCan forget to trackImpossible to miss
MaintenanceHighLow
RecommendedFor custom use cases✓ Best for most users