From 921f6d307ed39f094dd92eaf8fa65a2b89c9214e Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Thu, 11 Apr 2024 15:05:22 -0700 Subject: [PATCH] fix - stop printing api_key in debug mode --- litellm/router.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/litellm/router.py b/litellm/router.py index 37b0ede00..8bb943af9 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -1900,8 +1900,12 @@ class Router: local_only=True, ) # cache for 1 hr else: + _api_key = api_key + if _api_key is not None and isinstance(_api_key, str): + # only show first 5 chars of api_key + _api_key = _api_key[:8] + "*" * 15 verbose_router_logger.debug( - f"Initializing Azure OpenAI Client for {model_name}, Api Base: {str(api_base)}, Api Key:{api_key}" + f"Initializing Azure OpenAI Client for {model_name}, Api Base: {str(api_base)}, Api Key:{_api_key}" ) azure_client_params = { "api_key": api_key, @@ -1998,8 +2002,12 @@ class Router: ) # cache for 1 hr else: + _api_key = api_key + if _api_key is not None and isinstance(_api_key, str): + # only show first 5 chars of api_key + _api_key = _api_key[:8] + "*" * 15 verbose_router_logger.debug( - f"Initializing OpenAI Client for {model_name}, Api Base:{str(api_base)}, Api Key:{api_key}" + f"Initializing OpenAI Client for {model_name}, Api Base:{str(api_base)}, Api Key:{_api_key}" ) cache_key = f"{model_id}_async_client" _client = openai.AsyncOpenAI( # type: ignore