Before you start: Decide whether to ingest or infer usage data. See the Cost Tracking Reference to understand the differences.
Python SDK Implementation
Installation
Install the required packages:Method 1: Using the Decorator (Recommended)
The decorator approach is clean and integrates seamlessly with your existing functions.- Anthropic
- OpenAI
Method 2: Manual Context Manager
For more control, use the context manager approach:JavaScript/TypeScript SDK Implementation
Installation
Install the required packages:Setup
1. Add credentials to.env:
instrumentation.ts:
Method 1: Context Manager (Recommended)
Method 2: Observe Wrapper
Wrap existing functions to trace them automatically:Method 3: Manual Span Creation
For maximum control, create spans manually:Automatic Usage Capture via Integrations
Many ABV integrations automatically capture usage and cost from LLM responses. If you’re using an integration and usage data isn’t appearing as expected, contact support.Ingesting Only Usage (Let ABV Calculate Cost)
You don’t need to calculate costs yourself. Simply ingest usage details, and ABV will calculate costs based on model definitions:Next Steps
Custom Model Definitions
Learn how to define custom models and pricing
Daily Metrics API
Export usage and cost data for analytics
Common Issues
Usage and cost aren't showing up
Usage and cost aren't showing up
Check these:
- Verify you’re passing usage_details in the update call
- Ensure the model name matches a model definition in ABV
- For inference: Check if your model is supported in the model definitions list
- Look for errors in your application logs
Costs seem inaccurate
Costs seem inaccurate
Possible causes:
- Using inference instead of ingestion (switch to ingesting actual usage)
- Model pricing may have changed (update model definitions)
- Custom models need pricing configured
- For historical data: Model definitions aren’t applied retroactively
Missing usage for reasoning models
Missing usage for reasoning models
Solution:
Reasoning models (like OpenAI o1) require ingested usage. ABV cannot infer usage because reasoning tokens are generated internally.Always ingest
reasoning_tokens from the API response for these models.Learn more about reasoning models