Basic Usage

Here is how you track AI usage across different languages. For Python, Paygent provides automatic instrumentation. For Node.js and Go, use manual tracking methods.

The simplest way to track AI usage in Python is by initializing Paygent at the start of your application. This automatically instruments supported LLM clients.

main.py
1import paygent_sdk
2from openai import OpenAI
3
4# 1. Initialize Paygent (Automatic Tracking)
5paygent_sdk.init(api_key="your-paygent-api-key")
6
7# 2. Use your LLM client normally
8client = OpenAI(api_key="your-openai-api-key")
9
10# 3. Add paygent_* kwargs to track usage
11response = client.chat.completions.create(
12 model="gpt-4o",
13 messages=[{"role": "user", "content": "Hello!"}],
14
15 # Paygent tracking parameters
16 paygent_agent_id="chatbot-agent",
17 paygent_customer_id="customer-123",
18 paygent_indicator="message-sent"
19)
20
21print(response.choices[0].message.content)

Understanding the Parameters:

  • Agent ID: Identifies which AI component performed the work (e.g., “chatbot-agent”)
  • Customer ID: Identifies which customer used the service
  • Indicator: Describes what action was performed (e.g., “message-sent”)
  • Usage Data: Contains the model info and token counts