[Test Fix] fix gov pricing tests - #25022
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
|
Greptile SummaryThis PR fixes failing govcloud pricing tests by: (1) adding Key changes:
Confidence Score: 4/5Safe to merge pending clarification of the totalCost change in the Langfuse fixture, which may indicate cost tracking underreports for us.* inference-profile Bedrock models. The core govcloud fixes are well-reasoned and the None-guard changes are correct. One P1 finding remains: the Langfuse fixture update changes the expected total cost to a value consistent with cheaper base model pricing rather than the us.* inference-profile pricing declared in the JSON, which contradicts an assertion in the govcloud test suite itself. tests/logging_callback_tests/langfuse_expected_request_body/completion_with_bedrock_call.json — the totalCost value should be verified against the actual bedrock cost-lookup path for us.* inference profiles.
|
| Filename | Overview |
|---|---|
| litellm/cost_calculator.py | Adds or 0.0 guard for None pricing values to prevent TypeError on None > 0 comparisons. |
| litellm/litellm_core_utils/llm_request_utils.py | Same None-safe guard in the cheapest-model picker; minor formatting inconsistency introduced. |
| litellm/llms/azure_ai/cost_calculator.py | Adds truthiness check before comparing router_flat_cost_per_token > 0, preventing TypeError when value is None. |
| litellm/llms/vertex_ai/cost_calculator.py | Adds or 0.0 fallback when multiplying by model_info["input/output_cost_per_token"] to handle None values. |
| litellm/router.py | Wraps cost comparisons in (... or 0.0) to guard against None; outer is not None check makes the guard on model_info side redundant but harmless. |
| model_prices_and_context_window.json | Adds two new govcloud Haiku 4.5 entries; corrects Sonnet 4.5 govcloud pricing from 3.3e-06/1.65e-05 to 3.6e-06/1.8e-05. |
| tests/llm_translation/test_bedrock_govcloud.py | Fixes test model IDs to use anthropic.* for GovCloud (not us.*); all tests remain properly mocked with no real network calls. |
| tests/logging_callback_tests/langfuse_expected_request_body/completion_with_bedrock_call.json | Expected totalCost changed from 6.6e-05 (consistent with us.* profile pricing) to 6e-05 (consistent with base anthropic.* pricing) — potential pricing lookup regression. |
Reviews (3): Last reviewed commit: "fix test get model info" | Re-trigger Greptile
| @@ -215,7 +215,7 @@ def _handle_128k_pricing( | |||
| ): | |||
| completion_cost = completion_tokens * output_cost_per_token_above_128k_tokens | |||
There was a problem hiding this comment.
Silent $0 cost when pricing is None
Both input_cost_per_token and output_cost_per_token are accessed via model_info["..."] (dict key access that raises KeyError on missing keys) but the or 0.0 fallback silently produces a $0 cost when those keys exist with a None value. If a Vertex AI model somehow has input_cost_per_token: null in the pricing JSON, the cost calculation will silently undercharge users instead of surfacing the missing data.
The govcloud models added in this PR all have explicit non-None pricing, so this won't trigger here. Consider raising a more explicit error or logging a warning when the value is None so it's not silently ignored:
_input_cost = model_info["input_cost_per_token"]
if _input_cost is None:
verbose_logger.warning("input_cost_per_token is None for model_info, defaulting to 0.0")
_input_cost = 0.0
prompt_cost = prompt_tokens * _input_costThere was a problem hiding this comment.
makes sens but I'm not sure what our mental model is
04e811d to
797c747
Compare
| "output": 10, | ||
| "unit": "TOKENS", | ||
| "totalCost": 6.599999999999999e-05 | ||
| "totalCost": 6e-05 |
There was a problem hiding this comment.
Expected cost inconsistent with
us.* inference-profile pricing
The totalCost changed from 6.599999999999999e-05 to 6e-05. The model logged is bedrock/us.anthropic.claude-haiku-4-5-20251001-v1:0 with 10 input + 10 output tokens.
Pricing cross-check from model_prices_and_context_window.json:
us.anthropic.claude-haiku-4-5-20251001-v1:0→input: 1.1e-06,output: 5.5e-06→10 × 1.1e-06 + 10 × 5.5e-06 = 6.6e-05(old value — correct for theus.*profile)anthropic.claude-haiku-4-5-20251001-v1:0(base Bedrock) →input: 1e-06,output: 5e-06→10 × 1e-06 + 10 × 5e-06 = 6e-05(new value — matches base-model pricing, not theus.*profile)
The new fixture documents that bedrock/us.anthropic.* is now being priced via the cheaper base anthropic.* key, underreporting cost by ~9%. This is also internally inconsistent with test_govcloud_completion_cost_calculation, which still asserts us.* profile pricing for the same model string:
expected_base_cost = 10 * 1.1e-06 + 5 * 5.5e-06
assert abs(base_cost - expected_base_cost) < 1e-10Please confirm which pricing key the bedrock cost calculator resolves for us.* inference-profile model strings and verify this fixture was not regenerated from a regressed code path.
Rule Used: What: Flag any modifications to existing tests and... (source)
* fix pricing tests * fix mypy * fix cost expectation since us based model is used now. * fix test get model info
Relevant issues
test_govcloud_completion_cost_calculation
test_govcloud_completion_with_cost_tracking
test_govcloud_cost_per_token_with_region
test_govcloud_model_cost_properties
test_govcloud_model_pricing_verification
test_govcloud_models_in_model_cost
mypy_linting
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/test_litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewDelays in PR merge?
If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).
CI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
🐛 Bug Fix
🧹 Refactoring
📖 Documentation
🚄 Infrastructure
✅ Test
Changes
https://app.circleci.com/pipelines/github/BerriAI/litellm?branch=litellm_fix_gov_pricing_tests