Track token usage across agents with pluggable persistence backends for databases, APIs, or custom analytics systems.Documentation Index
Fetch the complete documentation index at: https://docs.praison.ai/llms.txt
Use this file to discover all available pages before exploring further.
Quick Start
Usage Sink Protocols
TokenUsageSinkProtocol
Interface for persisting token usage data to any backend:Built-in Sinks
| Sink | Purpose | Use Case |
|---|---|---|
NoOpTokenUsageSink | Default - no overhead | Production (when tracking disabled) |
InMemoryTokenUsageSink | In-memory storage | Development, testing |
| Custom | Your implementation | Database, API, analytics service |
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:| Field | Type | Description |
|---|---|---|
input_tokens | int | Input tokens consumed |
output_tokens | int | Output tokens generated |
cached_tokens | int | Cached tokens (if supported) |
total_tokens | int | Total tokens (input + output) |
cost | float | Estimated USD cost |
Related
Host Integration
Auto-wire usage tracking
Backend Injection
Custom backend services

