mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
fix(logging): zero out response_cost for cache hits in _process_hidden_params_and_response_cost (#21841)
When a cached response had `response_cost` pre-calculated in its `_hidden_params` (from the original response), `_process_hidden_params_and_response_cost` was using it directly without checking `cache_hit`, so cached responses were reported with non-zero cost instead of 0. Fixes test_cost_tracking_with_caching.
This commit is contained in:
parent
8c7f667df2
commit
d427ff6705
1 changed files with 3 additions and 1 deletions
|
|
@ -1632,7 +1632,9 @@ class Logging(LiteLLMLoggingBaseClass):
|
|||
self.model_call_details["litellm_params"]["metadata"] = {}
|
||||
self.model_call_details["litellm_params"]["metadata"]["hidden_params"] = getattr(logging_result, "_hidden_params", {}) # type: ignore
|
||||
|
||||
if "response_cost" in hidden_params:
|
||||
if self.model_call_details.get("cache_hit") is True:
|
||||
self.model_call_details["response_cost"] = 0.0
|
||||
elif "response_cost" in hidden_params:
|
||||
self.model_call_details["response_cost"] = hidden_params["response_cost"]
|
||||
else:
|
||||
self.model_call_details["response_cost"] = self._response_cost_calculator(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue