fix: correct pricing calculation for providers using $/token format#344
Merged
dwash96 merged 1 commit intocecli-dev:v0.92.0from Jan 1, 2026
Merged
fix: correct pricing calculation for providers using $/token format#344dwash96 merged 1 commit intocecli-dev:v0.92.0from
dwash96 merged 1 commit intocecli-dev:v0.92.0from
Conversation
Problem: -------- Commit c6a90d5 added division by DEFAULT_TOKEN_PRICE_RATIO (1000000) to convert pricing from $/M to $/token format. However, this was applied to ALL providers, but different providers use different pricing formats: - Synthetic and OpenRouter: Already return pricing in $/token format (e.g., "$0.00000055" per token) - LiteLLM's model_prices_and_context_window.json: Uses $/M format (e.g., "2.5e-06" = $2.5/M tokens) This caused synthetic provider pricing to be divided by 1,000,000 twice, making costs appear 1,000,000x too small. For example: - synthetic/hf:zai-org/GLM-4.7: $0.00000055/token became $0.00000000000055/token - User reported: 17k sent, 10 received tokens showed cost of $0.0000000096 Solution: --------- Added a heuristic in ModelProviderManager._record_to_info() to detect pricing format before applying conversion: - If cost >= 0.001: Treat as $/M format, divide by 1,000,000 - If cost < 0.001: Treat as $/token format, no division This threshold (0.001) was chosen because: - $/M pricing is typically >= $0.001/M (e.g., $1.0/M, $2.5/M) - $/token pricing is typically < $0.001/token (e.g., $0.00000055/token) Changes: -------- 1. aider/helpers/model_providers.py: - Added _normalize_cost() helper function to intelligently handle both formats - Replaced unconditional division with format-aware normalization 2. tests/basic/test_model_provider_manager.py: - Added test_pricing_normalization_detects_token_format: Verifies $/token pricing is not divided - Added test_pricing_normalization_detects_million_format: Verifies $/M pricing is converted correctly Impact: ------- - Synthetic provider models now display correct pricing - Existing $/M format providers continue to work correctly - No breaking changes to API or behavior Co-authored-by: aider-ce (synthetic/hf:zai-org/GLM-4.7)
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.
Problem:
Commit c6a90d5 added division by DEFAULT_TOKEN_PRICE_RATIO (1000000) to convert pricing from$/M to $ /token format. However, this was applied to ALL providers, but different providers use different pricing formats:
This caused synthetic provider pricing to be divided by 1,000,000 twice, making costs appear 1,000,000x too small. For example:
Solution:
Added a heuristic in ModelProviderManager._record_to_info() to detect pricing format before applying conversion:
This threshold (0.001) was chosen because:
Changes:
aider/helpers/model_providers.py:
tests/basic/test_model_provider_manager.py:
Impact:
Co-authored-by: aider-ce (synthetic/hf:zai-org/GLM-4.7)