Real OpenRouter cost in ReviewResult#83
Open
dangng2004 wants to merge 1 commit into
Open
Conversation
OpenRouter returns the real (post-discount, post-routing) cost in the usage block when asked. Plumb that through so reviews report ground-truth spend instead of a token-count × hardcoded-price estimate. - client.py: send extra_body.usage.include=true on OpenRouter calls; read resp.usage.cost (with model_extra fallback) and add it to the returned usage dict as cost_usd + cost_source. - models.py: ReviewResult gains total_cost_usd and cost_source fields, plus an add_usage() helper that consolidates the per-call token and cost accumulation that was previously duplicated at every call site. - method_local / method_progressive / method_zero_shot: 9 call sites switched from inline token-accumulation pairs to result.add_usage(). - evaluate.compute_cost: prefer the reported value when cost_source is set; estimator stays as the fallback for other providers. - cli.py: viz JSON now records "cost_method" so downstream tooling can tell real numbers apart from estimates. Non-OpenRouter providers (OpenAI, Anthropic, Gemini, Mistral) are unaffected — they keep using the token-price-table estimate.
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
Non-OpenRouter providers
OpenAI, Anthropic, Gemini, Mistral are untouched — they keep the estimator path.
Status
Draft. Verified `add_usage()` accumulates tokens and cost correctly in isolation; no end-to-end run yet against OpenRouter.
Test plan