From b3bd15e35a841b55355498269afc725596e3ac81 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Fri, 10 Jan 2025 14:00:48 -0800 Subject: [PATCH] speed up use_custom_pricing_for_model (#7674) --- litellm/litellm_core_utils/litellm_logging.py | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.py index f066e95b1f3..7f486da0ef9 100644 --- a/litellm/litellm_core_utils/litellm_logging.py +++ b/litellm/litellm_core_utils/litellm_logging.py @@ -2561,19 +2561,22 @@ def _get_custom_logger_settings_from_proxy_server(callback_name: str) -> Dict: def use_custom_pricing_for_model(litellm_params: Optional[dict]) -> bool: + """ + Check if the model uses custom pricing + + Returns True if any of `SPECIAL_MODEL_INFO_PARAMS` are present in `litellm_params` or `model_info` + """ if litellm_params is None: return False - for k, v in litellm_params.items(): - if k in SPECIAL_MODEL_INFO_PARAMS and v is not None: + + metadata: dict = litellm_params.get("metadata", {}) or {} + model_info: dict = metadata.get("model_info", {}) or {} + + for _custom_cost_param in SPECIAL_MODEL_INFO_PARAMS: + if litellm_params.get(_custom_cost_param, None) is not None: + return True + elif model_info.get(_custom_cost_param, None) is not None: return True - metadata: Optional[dict] = litellm_params.get("metadata", {}) - if metadata is None: - return False - model_info: Optional[dict] = metadata.get("model_info", {}) - if model_info is not None: - for k, v in model_info.items(): - if k in SPECIAL_MODEL_INFO_PARAMS: - return True return False