How It Works
Quick Start
1
Basic Usage
Enable usage tracking with the global collector:
2
Query Usage Data
Access tracked usage data for analytics:
Usage Sink Protocols
TokenUsageSinkProtocol
Interface for persisting token usage data to any backend:Built-in Sinks
Usage Query Protocols
UsageQueryProtocol
Interface for reading usage data from your backend:Built-in Query Adapters
InMemoryUsageQuery
InMemoryUsageQuery
Query adapter for
InMemoryTokenUsageSink:TokenCollectorUsageQuery
TokenCollectorUsageQuery
Query adapter for global
TokenCollector:Integration with Host
Wire usage tracking into PraisonAIUI backends:Custom Sink Example
Complete example with PostgreSQL backend:Best Practices
Use NoOp sink in production by default
Use NoOp sink in production by default
The default
NoOpTokenUsageSink has zero overhead. Only enable tracking when needed:Batch writes for high throughput
Batch writes for high throughput
Buffer writes to reduce database load:
Include custom metadata
Include custom metadata
Add business context to usage records:
Usage Metrics Format
Token metrics objects contain these fields:
Query summary format:
Related
Host Integration
Auto-wire usage tracking
Backend Injection
Custom backend services

