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
feat: add estimated cost to token usage display (#114)
* feat: add estimated cost to token usage display
Adds model-aware cost estimation to both per-request inline stats and
the session summary (/tokens command + exit display).
Pricing table:
- Claude Opus/Sonnet/Haiku (with cache read/write rates)
- OpenAI o1, o3, GPT-4.1, GPT-4o (with cache read rates)
- Gemini 2.5 Pro, 2.5 Flash (with cache read rates)
Per-request display now shows: '~$X.XX' at the end of the stats line
Session summary now shows:
- Est. Cost with model tier label
- Cache savings (how much caching saved vs no-cache pricing)
Also tracks cacheWriteTokens (was available from SDK but not
accumulated) for accurate cost calculation.
Implementation:
- getModelPricing(modelName) — prefix-based pricing lookup
- estimateCost(pricing, in, out, cacheRead, cacheWrite) — USD calc
- Both exported for testing/reuse
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
* fix: address PR #114 review feedback on cost estimation
- Fix JSDoc on estimateCost: removed incorrect 'returns undefined'
claim — function always returns a number
- Fix per-request cost double-counting: subtract cacheReadTokens from
inputTokens before estimating (inputTokens includes cached portion)
- Make currentModel optional in formatTokenSummary — gracefully skips
pricing when model is unknown
- Tighten prefix matching in getModelPricing: require word boundary
(end-of-string or '-') after prefix to prevent misclassification
(e.g. 'o3' won't match 'o3something', only 'o3' or 'o3-mini')
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
---------
Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com>
0 commit comments