Node.js SDK - Basic Usage
Here's a simple example of tracking AI usage with the Node.js SDK:
index.ts
1import { PaygentClient } from '@paygent_org/paygent-sdk-node';
2
3// Create a new client
4const client = PaygentClient.newClient('your-paygent-api-key');
5
6// Define usage data
7const usageData = {
8 serviceProvider: 'OpenAI',
9 model: 'gpt-4o',
10 promptTokens: 756,
11 completionTokens: 244,
12 totalTokens: 1000
13};
14
15// Send usage data
16await client.sendUsage(
17 'chatbot-agent', // Agent ID
18 'customer-123', // Customer ID
19 'message-sent', // Indicator/Indicator
20 usageData
21);
22
23console.log('Usage tracked successfully!');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
Was this page helpful?
Need help? Contact us at support@withpaygent.com