From 2d4cb092718bd68b118e76ad137f78d3f6fa3f86 Mon Sep 17 00:00:00 2001 From: mateo Date: Tue, 6 Oct 2026 00:08:43 +0000 Subject: [PATCH] fix: preserve hidden params in duck-typed cost responses Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> --- litellm/cost_calculator.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 9fe192bc4d4..cbdf2c77542 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -18,6 +18,7 @@ from litellm.constants import ( DEFAULT_MAX_LRU_CACHE_SIZE, DEFAULT_REPLICATE_GPU_PRICE_PER_SECOND, ) +from litellm.litellm_core_utils.hidden_params import HIDDEN_PARAMS_ATTR from litellm.litellm_core_utils.llm_cost_calc.tool_call_cost_tracking import ( StandardBuiltInToolCostTracking, ) @@ -2023,8 +2024,12 @@ def response_cost_calculator( response_cost = 0.0 else: if isinstance(response_object, BaseModel): - if hasattr(response_object, "_hidden_params"): - provider_response_cost: Final = get_response_cost_from_hidden_params(response_object.hidden_params) + if hasattr(response_object, HIDDEN_PARAMS_ATTR): + hidden_params: Final = cast( + dict[str, object] | BaseModel, + getattr(response_object, HIDDEN_PARAMS_ATTR), + ) + provider_response_cost: Final = get_response_cost_from_hidden_params(hidden_params) if provider_response_cost is not None: return provider_response_cost