> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.withpaygent.com/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.withpaygent.com/_mcp/server.

# 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.

#### Python

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`**

```python title="main.py"
import paygent_sdk
from openai import OpenAI

# 1. Initialize Paygent (Automatic Tracking)
paygent_sdk.init(api_key="your-paygent-api-key")

# 2. Use your LLM client normally
client = OpenAI(api_key="your-openai-api-key")

# 3. Add paygent_* kwargs to track usage
response = client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "Hello!"}],
    
    # Paygent tracking parameters
    paygent_agent_id="chatbot-agent",
    paygent_customer_id="customer-123",
    paygent_indicator="message-sent"
)

print(response.choices[0].message.content)
```

#### Node.js

**`index.ts`**

```typescript title="index.ts"
import { PaygentClient } from '@paygent_org/paygent-sdk-node';

// Create a new client
const client = PaygentClient.newClient('your-paygent-api-key');

// Define usage data
const usageData = {
  serviceProvider: 'OpenAI',
  model: 'gpt-4o',
  promptTokens: 756,
  completionTokens: 244,
  totalTokens: 1000
};

// Send usage data
await client.sendUsage(
  'chatbot-agent',      // Agent ID
  'customer-123',       // Customer ID
  'message-sent',       // Indicator
  usageData
);

console.log('Usage tracked successfully!');
```

#### Go

**`main.go`**

```go title="main.go"
package main

import (
    "context"
    "fmt"
    paygent "github.com/paygent-org/paygent-sdk-go"
)

func main() {
    // Create client
    client := paygent.NewClient("your-paygent-api-key")
    
    // Define usage data
    usageData := paygent.UsageData{
        ServiceProvider:  "OpenAI",
        Model:            "gpt-4o",
        PromptTokens:     756,
        CompletionTokens: 244,
        TotalTokens:      1000,
    }
    
    // Send usage data
    err := client.SendUsage(
        "chatbot-agent",      // Agent ID
        "customer-123",       // Customer ID
        "message-sent",       // Indicator
        usageData,
    )
    
    if err != nil {
        fmt.Printf("Failed to send usage: %v\n", err)
        return
    }
    
    fmt.Println("Usage tracked successfully!")
}
```

> **Info**
>
> **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