Overview
Anyway automatically tracks the cost of every LLM API call, helping you:- Monitor spending in real-time
- Attribute costs to users, features, or teams
- Identify expensive operations
- Optimize token usage
Automatic Cost Calculation
Both the Python and JavaScript SDKs automatically calculate costs based on bundled pricing data. Costs are added as span attributes:gen_ai.usage.input_cost— Input token cost (USD)gen_ai.usage.output_cost— Output token cost (USD)gen_ai.usage.cost— Total cost (USD)
Supported Models
Pricing is included for 150+ models from these providers:The SDK ships with a default pricing file that is updated with each release. You can also provide custom pricing — see below.
Custom Pricing
Provide your own pricing data to add models or override prices:- Python
- JavaScript
- Python
- JavaScript
Pricing JSON Format
promptPrice: Cost per 1K input tokens (USD)completionPrice: Cost per 1K output tokens (USD)
Model Matching
The SDK matches model names using a three-tier strategy:- Exact match —
gpt-4o-minimatchesgpt-4o-mini - Date suffix stripped —
gpt-4o-2024-08-06matchesgpt-4o - Longest prefix —
gpt-4o-mini-custommatchesgpt-4o-mini
Cost Attribution
Use association properties to track costs by user, feature, or team:- Python
- JavaScript
Cost Dashboard
The Cost Dashboard shows:- Total spend — Current period and trend
- Cost by model — Which models cost the most
- Cost by association — Filter by user, team, or feature
- Daily trends — Spending over time
Cost Optimization Tips
Use cheaper models for simple tasks
Use cheaper models for simple tasks
Not every task needs a large model. Use
gpt-4o-mini or claude-3-haiku for:- Classification tasks
- Simple extractions
- Formatting/transformation
Optimize prompts
Optimize prompts
Shorter prompts = lower costs:
- Remove redundant instructions
- Use examples efficiently
- Consider prompt caching
Set token limits
Set token limits
Prevent runaway costs with
max_tokens:Next Steps
Usage Limits
Set usage quotas
Payments
Create payment links and accept payments