From a7a0c328d4c3df96c80a284c98891b5a58904efe Mon Sep 17 00:00:00 2001 From: GopalGB <67310594+GopalGB@users.noreply.github.com> Date: Thu, 7 May 2026 20:23:04 +0530 Subject: [PATCH] fix(test): use model with cache pricing so assertion actually executes Switch test from `fireworks_ai/llama-v3p3-70b-instruct` (no cache_read_input_token_cost) to `fireworks_ai/kimi-k2p5` (has cache pricing at 1e-07 vs input 6e-07). Remove the conditional guard so the assertion always runs. Addresses Greptile review feedback on #24860. Co-Authored-By: Claude Opus 4.6 (1M context) Signed-off-by: GopalGB <67310594+GopalGB@users.noreply.github.com> --- litellm/llms/fireworks_ai/cost_calculator.py | 4 +--- tests/local_testing/test_completion_cost.py | 20 ++++++++------------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/litellm/llms/fireworks_ai/cost_calculator.py b/litellm/llms/fireworks_ai/cost_calculator.py index 17320fe749f..b704b599676 100644 --- a/litellm/llms/fireworks_ai/cost_calculator.py +++ b/litellm/llms/fireworks_ai/cost_calculator.py @@ -91,9 +91,7 @@ def cost_per_token(model: str, usage: Usage) -> Tuple[float, float]: ) ## ADJUST FOR CACHE CREATION TOKENS - cache_creation_input_tokens = ( - usage.get("cache_creation_input_tokens", None) or 0 - ) + cache_creation_input_tokens = usage.get("cache_creation_input_tokens", None) or 0 cache_creation_cost = model_info.get("cache_creation_input_token_cost", None) if cache_creation_input_tokens > 0 and cache_creation_cost is not None: prompt_cost += cache_creation_input_tokens * ( diff --git a/tests/local_testing/test_completion_cost.py b/tests/local_testing/test_completion_cost.py index c6981b19641..1a3811418e7 100644 --- a/tests/local_testing/test_completion_cost.py +++ b/tests/local_testing/test_completion_cost.py @@ -1221,27 +1221,23 @@ def test_fireworks_ai_cache_token_pricing(): os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True" litellm.model_cost = litellm.get_model_cost_map(url="") + # Use kimi-k2p5 which has cache_read_input_token_cost in the pricing config prompt_cost_cached, completion_cost_cached = cost_per_token( - model="fireworks_ai/llama-v3p3-70b-instruct", usage=usage_with_cache + model="fireworks_ai/kimi-k2p5", usage=usage_with_cache ) prompt_cost_no_cache, completion_cost_no_cache = cost_per_token( - model="fireworks_ai/llama-v3p3-70b-instruct", usage=usage_no_cache + model="fireworks_ai/kimi-k2p5", usage=usage_no_cache ) # Completion cost should be the same regardless of cache assert completion_cost_cached == completion_cost_no_cache - # If the model has cache pricing, the prompt cost with cache should differ - # from the prompt cost without cache (cache read rate is cheaper) - model_info = litellm.get_model_info( - model="fireworks_ai/llama-v3p3-70b-instruct", - custom_llm_provider="fireworks_ai", + # kimi-k2p5 has cache_read_input_token_cost (1e-07) < input_cost_per_token (6e-07), + # so prompt cost with 800 cache-read tokens must be cheaper + assert prompt_cost_cached < prompt_cost_no_cache, ( + "Prompt cost with 800 cache-read tokens should be less than " + "full-price for the same total prompt tokens" ) - if model_info.get("cache_read_input_token_cost") is not None: - assert prompt_cost_cached < prompt_cost_no_cache, ( - "Prompt cost with 800 cache-read tokens should be less than " - "full-price for the same total prompt tokens" - ) def test_cost_azure_openai_prompt_caching():