Skip to content

Feat/cost#2

Open
akshatshaw wants to merge 2 commits intoharshkedia177:mainfrom
akshatshaw:feat/cost
Open

Feat/cost#2
akshatshaw wants to merge 2 commits intoharshkedia177:mainfrom
akshatshaw:feat/cost

Conversation

@akshatshaw
Copy link
Copy Markdown

@akshatshaw akshatshaw commented Apr 17, 2026

--cost — Estimated cost breakdown by model
What :
Adds a new --cost flag that calculates and displays estimated API costs per model, broken down by input, output, cache read, and cache write tokens.

Pricing is local — no API calls. Prices are hardcoded from official public pricing pages with prefix/substring matching for versioned model names. Unknown models fall back to Sonnet-tier pricing.

enrichFromStatsCache()
— JSONL parsing gives proportional estimates, but

stats-cache.json
has authoritative per-model token breakdowns including cacheCreationInputTokens. We use that when available for accuracy.
Non-breaking — --cost is opt-in. Without it, output is identical to before.

tokenviz --claude --cost
💰 ESTIMATED COST
MODEL INPUT OUTPUT CACHE READ CACHE WRITE TOTAL
claude-opus-4-6 $0.37 $5.65 $33.9 $59.7 $99.5
claude-sonnet-4-6 $0.03 $1.58 $4.06 $5.48 $11.2
claude-haiku-4-5-20251001 $0.006 $0.18 $0.63 $0.83 $1.66
TOTAL $116
Works in both terminal and exported PNG/SVG.

tokenviz_20260418_013118

@akshatshaw
Copy link
Copy Markdown
Author

@harshkedia177 i have added support to get estimated cost for claude code usage, have a look and merge

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant