From 9de0fcea93078ee13b88c8a686392a932851ecda Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Mon, 18 May 2026 13:30:58 +0000 Subject: [PATCH] fix: address bug detection findings (cache token order, mutable defaults) Co-authored-by: Yassin Kortam --- litellm/cost_calculator.py | 8 ++++---- litellm/llms/dashscope/rerank/transformation.py | 9 ++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index da72eb9bb69..b05cd01af2c 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -365,11 +365,11 @@ def cost_per_token( # noqa: PLR0915 if _pt_details is not None: _cache_read_tokens = float(getattr(_pt_details, "cached_tokens", 0) or 0) # OpenAI-compatible providers report cache-write tokens under - # either `cache_creation_tokens` or `cache_write_tokens` (kimi-k2 - # uses the latter). Mirror db_spend_update_writer to stay symmetric. + # either `cache_write_tokens` (kimi-k2) or `cache_creation_tokens`. + # Mirror db_spend_update_writer to stay symmetric. _cache_creation_tokens = float( - getattr(_pt_details, "cache_creation_tokens", 0) - or getattr(_pt_details, "cache_write_tokens", 0) + getattr(_pt_details, "cache_write_tokens", 0) + or getattr(_pt_details, "cache_creation_tokens", 0) or 0 ) diff --git a/litellm/llms/dashscope/rerank/transformation.py b/litellm/llms/dashscope/rerank/transformation.py index faa1688b5a1..629f3cf4af7 100644 --- a/litellm/llms/dashscope/rerank/transformation.py +++ b/litellm/llms/dashscope/rerank/transformation.py @@ -159,10 +159,13 @@ class DashScopeRerankConfig(BaseRerankConfig): model_response: RerankResponse, logging_obj: LiteLLMLoggingObj, api_key: Optional[str] = None, - request_data: dict = {}, - optional_params: dict = {}, - litellm_params: dict = {}, + request_data: Optional[dict] = None, + optional_params: Optional[dict] = None, + litellm_params: Optional[dict] = None, ) -> RerankResponse: + request_data = request_data or {} + optional_params = optional_params or {} + litellm_params = litellm_params or {} try: response_json = raw_response.json() except Exception: