feat: add route-aware pricing estimates (salvaged from #1563)#1695
Merged
feat: add route-aware pricing estimates (salvaged from #1563)#1695
Conversation
Cherry-picked from PR #1563 by kshitijk4poor. Conflicts resolved in hermes_state.py (with self._lock) and run_agent.py (normalize_usage replaces Anthropic cache fix).
…eway tests Cherry-picked from PR #1563 by kshitijk4poor.
Cherry-picked from PR #1563 by kshitijk4poor.
- Remove speculative forward-looking pricing entries (claude-opus-4.6, claude-sonnet-4.6, gpt-5, gpt-5.4, o4-mini) — show 'unknown' instead of inventing prices - Remove cost $$ display from CLI status bar entirely - Thread the OpenRouter metadata pre-warm (was blocking in __init__) - Remove duplicate fetch_model_metadata import - Fix tests for removed models
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Salvaged from PR #1563 by @kshitijk4poor. Cherry-picked their 3 commits onto current main with conflict resolution and follow-up fixes.
Replaces the static
MODEL_PRICINGdict + keyword heuristic cost calculation with a proper route-aware pricing architecture:normalize_usage()handles Anthropic, OpenAI, and Codex API shapes, splitting tokens into input/output/cache_read/cache_write/reasoning bucketsresolve_billing_route()determines pricing based on provider+model pair, not just model name heuristicsCostStatus(actual/estimated/included/unknown) andCostSourcefor transparencyincluded(cost $0)get_pricing()andestimate_cost_usd()still work for callers that haven't been updatedFollow-up changes (on top of cherry-pick)
fetch_model_metadataimporthermes_state.py(preservedwith self._lock) andrun_agent.py(normalize_usagereplaces inline Anthropic cache handling)Test plan
python -m pytest tests/ -n0 -q— 4992 passed (16 pre-existing failures unrelated to this PR)tests/agent/test_usage_pricing.py,tests/test_cli_status_bar.py,tests/test_insights.py,tests/test_hermes_state.py,tests/gateway/test_session.py,tests/gateway/test_status_command.py— all 229 passAttribution
Original work by @kshitijk4poor in PR #1563 (3 commits cherry-picked with authorship preserved).