Skip to content

fix: Cost calculation uses hardcoded Sonnet pricing - doesn't support Opus/Haiku models #86

Description

@sagarsrc

Scope

backend

What's broken?

The cost calculation in token_metrics.py uses hardcoded Claude Sonnet 4 pricing constants, but Claude Code can use different models (Opus 4.5, Opus 4, Haiku, etc.). This causes significant cost estimation errors.

File: packages/server/src/quickcall_supertrace/metrics/token_metrics.py:16-20

# Cost per 1M tokens (Claude Sonnet 4 pricing)
INPUT_COST_PER_M = 3.00
OUTPUT_COST_PER_M = 15.00
CACHE_READ_COST_PER_M = 0.30
CACHE_WRITE_COST_PER_M = 3.75

The model field is already being parsed in parser.py:211 but is not used in cost calculation.

Impact:

Model Used Actual Cost QuickCall Shows Error
Opus 4.5 ~$0.05 ~$0.03 -40% underestimated
Opus 4/4.1 ~$0.15 ~$0.03 -80% underestimated
Haiku 4.5 ~$0.01 ~$0.03 +200% overestimated
Sonnet 4/4.5 ~$0.03 ~$0.03 ✓ Correct

Expected behavior

Cost calculation should use model-specific pricing based on the model field from the API response.

Official Claude Pricing (per MTok):

Model Input Output Cache Read Cache Write (5m)
Opus 4.5 $5.00 $25.00 $0.50 $6.25
Opus 4/4.1 $15.00 $75.00 $1.50 $18.75
Sonnet 4/4.5 $3.00 $15.00 $0.30 $3.75
Haiku 4.5 $1.00 $5.00 $0.10 $1.25

Source: https://platform.claude.com/docs/en/about-claude/pricing

Version

0.2.8

Activity

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

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions