From e8785d5dffa07ad6867d543a096245bf3201326e Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 2 Feb 2024 13:43:48 -0800 Subject: [PATCH 1/3] fix(proxy_server.py): have spend logs be admin controlled only --- litellm/proxy/proxy_server.py | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 9fe25ed6113..85a5b2d8a54 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -556,15 +556,17 @@ async def user_api_key_auth( ) if ( - ( - route.startswith("/key/") - or route.startswith("/user/") - or route.startswith("/model/") - ) - and (not is_master_key_valid) - and (not _has_user_setup_sso()) - and (not general_settings.get("allow_user_auth", False)) - ): + route.startswith("/key/") + or route.startswith("/user/") + or route.startswith("/model/") + or route.startswith("/spend/") + ) and (not is_master_key_valid): + allow_user_auth = False + if ( + general_settings.get("allow_user_auth", False) == True + or _has_user_setup_sso() == True + ): + allow_user_auth = True # user can create and delete their own keys # enters this block when allow_user_auth is set to False if route == "/key/info": # check if user can access this route @@ -590,12 +592,14 @@ async def user_api_key_auth( elif route == "/model/info": # /model/info just shows models user has access to pass + elif allow_user_auth == True and route == "/key/generate": + pass + elif allow_user_auth == True and route == "/key/delete": + pass else: - allow_user_auth = general_settings.get("allow_user_auth", False) raise Exception( f"Only master key can be used to generate, delete, update or get info for new keys/users. Value of allow_user_auth={allow_user_auth}" ) - return UserAPIKeyAuth(api_key=api_key, **valid_token_dict) else: raise Exception(f"Invalid Key Passed to LiteLLM Proxy") From bc688d46625bc9abbb07005c41eed63380320fcf Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 2 Feb 2024 14:03:18 -0800 Subject: [PATCH 2/3] fix(utils.py): dynamic switch langfuse client based on keys --- litellm/utils.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/litellm/utils.py b/litellm/utils.py index d27c658c232..eb124f9ba85 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -1297,7 +1297,10 @@ class Logging: else: print_verbose("reaches langfuse for streaming logging!") result = kwargs["complete_streaming_response"] - if langFuseLogger is None: + if langFuseLogger is None or ( + self.langfuse_public_key != langFuseLogger.public_key + and self.langfuse_secret != langFuseLogger.secret_key + ): langFuseLogger = LangFuseLogger( langfuse_public_key=self.langfuse_public_key, langfuse_secret=self.langfuse_secret, From 643ff0438eef36537fa5506c08005a37c11ec299 Mon Sep 17 00:00:00 2001 From: Krrish Dholakia Date: Fri, 2 Feb 2024 14:33:42 -0800 Subject: [PATCH 3/3] test(test_amazing_s3_logs.py): fix test n --- litellm/tests/test_amazing_s3_logs.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/litellm/tests/test_amazing_s3_logs.py b/litellm/tests/test_amazing_s3_logs.py index b4dfcd54215..ecc6ae26f22 100644 --- a/litellm/tests/test_amazing_s3_logs.py +++ b/litellm/tests/test_amazing_s3_logs.py @@ -85,6 +85,8 @@ def test_s3_logging(): cleaned_keys = [] for key in most_recent_keys: split_key = key.split("_") + if len(split_key) < 2: + continue cleaned_keys.append(split_key[1]) print("\n most recent keys", most_recent_keys) print("\n cleaned keys", cleaned_keys)