diff --git a/litellm/caching/caching.py b/litellm/caching/caching.py index 4a1b9f3430c..e5c88646401 100644 --- a/litellm/caching/caching.py +++ b/litellm/caching/caching.py @@ -848,7 +848,7 @@ class Cache: else: cache_key = self.get_cache_key(**kwargs) # rebind-ok: derive caller key if cache_key is not None: - cache_control_args: Final[DynamicCacheControl] = kwargs.get("cache", {}) + cache_control_args: Final[DynamicCacheControl] = cast(DynamicCacheControl, kwargs.get("cache", {})) max_age = cache_control_args.get("s-maxage") or cache_control_args.get("s-max-age") or float("inf") cache_lookup_kwargs: Final = self._get_safe_cache_lookup_kwargs(kwargs) if dynamic_cache_object is not None: @@ -883,7 +883,7 @@ class Cache: else: cache_key = self.get_cache_key(**kwargs) # rebind-ok: derive caller key if cache_key is not None: - cache_control_args: Final = kwargs.get("cache", {}) + cache_control_args: Final[DynamicCacheControl] = cast(DynamicCacheControl, kwargs.get("cache", {})) max_age: Final = cache_control_args.get( "s-max-age", cache_control_args.get("s-maxage", float("inf")) ) @@ -956,7 +956,7 @@ class Cache: return verbose_logger.error("%s: %s", message, exc) - async def async_add_cache(self, result, dynamic_cache_object: BaseCache | None = None, **kwargs): + async def async_add_cache(self, result: object, dynamic_cache_object: BaseCache | None = None, **kwargs: object): """ Async implementation of add_cache """ diff --git a/litellm/proxy/hooks/batch_redis_get.py b/litellm/proxy/hooks/batch_redis_get.py index 3e5bbe57e51..75de6d7c3b7 100644 --- a/litellm/proxy/hooks/batch_redis_get.py +++ b/litellm/proxy/hooks/batch_redis_get.py @@ -4,7 +4,7 @@ ### [BETA] this is in Beta. And might change. import traceback -from typing import Final, Literal +from typing import Final, Literal, cast # noqa: TID251 # typed cache kwargs boundary from fastapi import HTTPException @@ -106,7 +106,7 @@ class _PROXY_BatchRedisRequests(CustomLogger): ) # returns ":" - we pass redis_namespace in async_pre_call_hook. Done to avoid rewriting the async_set_cache logic if cache_key is not None and self.in_memory_cache is not None: - cache_control_args: Final = kwargs.get("cache", {}) + cache_control_args: Final[DynamicCacheControl] = cast(DynamicCacheControl, kwargs.get("cache", {})) max_age: Final = cache_control_args.get("s-max-age", cache_control_args.get("s-maxage", float("inf"))) cached_result = self.in_memory_cache.get_cache(cache_key, *args, **kwargs) if cached_result is None: diff --git a/litellm/proxy/spend_tracking/spend_tracking_utils.py b/litellm/proxy/spend_tracking/spend_tracking_utils.py index 72a104ff1dc..6f7babc5922 100644 --- a/litellm/proxy/spend_tracking/spend_tracking_utils.py +++ b/litellm/proxy/spend_tracking/spend_tracking_utils.py @@ -610,7 +610,10 @@ def get_logging_payload( elif not isinstance(response_obj, BaseModel) and not isinstance(response_obj, dict): response_obj = {"result": str(response_obj)} # standardize this function to be used across, s3, dynamoDB, langfuse logging - litellm_params: Final = kwargs.get("litellm_params", {}) + litellm_params_value: Final[object] = kwargs.get("litellm_params", {}) + litellm_params: Final[dict[str, object]] = ( + cast(dict[str, object], litellm_params_value) if isinstance(litellm_params_value, Mapping) else {} + ) metadata: Final = get_litellm_metadata_from_kwargs(kwargs) routing_litellm_params: Final[Mapping[str, object] | None] = ( litellm_params if isinstance(litellm_params, Mapping) else None @@ -880,7 +883,7 @@ def get_logging_payload( metadata=metadata, requested_model=persisted_model_group, selected_model=model_name, - selected_provider=custom_llm_provider, + selected_provider=(custom_llm_provider if isinstance(custom_llm_provider, str) else None), router_correlation_id=litellm_call_id, ), used_client_oauth_token=resolve_used_client_oauth_token(