You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently, ccusage fetches current prices from LiteLLM API and applies them to all historical data. However, Claude API pricing changes over time, which leads to inaccurate cost calculations for past usage.
For example:
Claude 3.5 Sonnet was priced at $3/$15 per 1M tokens
Claude 4 Sonnet is now priced at $3/$15 per 1M tokens (same, but models change)
Older models like Claude 3 Opus had different pricing
If pricing changes in the future, running ccusage monthly will show incorrect costs for historical months
The reported costs won't reflect what was actually charged at the time of usage.
Problem
Currently, ccusage fetches current prices from LiteLLM API and applies them to all historical data. However, Claude API pricing changes over time, which leads to inaccurate cost calculations for past usage.
For example:
ccusage monthlywill show incorrect costs for historical monthsThe reported costs won't reflect what was actually charged at the time of usage.
Background
From #4, I understand that:
costUSDfield in logstokens × current_priceThis works well for current usage, but becomes inaccurate for historical data when prices change.
Suggested Solution
Maintain a historical pricing table that maps date ranges to prices:
When calculating costs, look up the price that was in effect on the date of each log entry.
Alternatives
total_cost_usdfrom statusline (related to [suggestion]: extractingtotal_cost_usd, record it, and use it for other commands (daily, monthly...) #576) - only solves future data--use-current-pricesflag - explicitly opt into current pricing, default to historicalRelated Issues
costUSDfield, ccusage switched to calculationtotal_cost_usd, record it, and use it for other commands (daily, monthly...) #576 - Proposal to recordtotal_cost_usdfrom statusline (future data only)