diff --git a/litellm/integrations/langfuse/langfuse_handler.py b/litellm/integrations/langfuse/langfuse_handler.py index f9d27f6cf00..b96e5f4bacf 100644 --- a/litellm/integrations/langfuse/langfuse_handler.py +++ b/litellm/integrations/langfuse/langfuse_handler.py @@ -86,9 +86,7 @@ class LangFuseHandler: if globalLangfuseLogger is not None: return globalLangfuseLogger - credentials_dict: Dict[ - str, Any - ] = ( + credentials_dict: Dict[str, Any] = ( {} ) # the global langfuse logger uses Environment Variables, there are no dynamic credentials globalLangfuseLogger = in_memory_dynamic_logger_cache.get_cache( @@ -160,6 +158,9 @@ class LangFuseHandler: bool: True if the dynamic langfuse credentials are passed, False otherwise """ + if standard_callback_dynamic_params is None: + return False + if ( standard_callback_dynamic_params.get("langfuse_host") is not None or standard_callback_dynamic_params.get("langfuse_public_key") is not None diff --git a/tests/test_litellm/integrations/langfuse/test_langfuse_handler.py b/tests/test_litellm/integrations/langfuse/test_langfuse_handler.py new file mode 100644 index 00000000000..e7fe5b27120 --- /dev/null +++ b/tests/test_litellm/integrations/langfuse/test_langfuse_handler.py @@ -0,0 +1,39 @@ +from litellm.integrations.langfuse.langfuse_handler import LangFuseHandler + + +class TestLangFuseHandlerDynamicCredentials: + def test_dynamic_credentials_none_returns_false(self): + """_dynamic_langfuse_credentials_are_passed should return False when + standard_callback_dynamic_params is None (env-var-only config).""" + result = LangFuseHandler._dynamic_langfuse_credentials_are_passed(None) + assert result is False + + def test_dynamic_credentials_empty_dict_returns_false(self): + """_dynamic_langfuse_credentials_are_passed should return False when + standard_callback_dynamic_params is an empty dict.""" + result = LangFuseHandler._dynamic_langfuse_credentials_are_passed({}) + assert result is False + + def test_dynamic_credentials_with_langfuse_host_returns_true(self): + result = LangFuseHandler._dynamic_langfuse_credentials_are_passed( + {"langfuse_host": "http://localhost:3000"} + ) + assert result is True + + def test_dynamic_credentials_with_public_key_returns_true(self): + result = LangFuseHandler._dynamic_langfuse_credentials_are_passed( + {"langfuse_public_key": "pk-lf-test"} + ) + assert result is True + + def test_dynamic_credentials_with_secret_key_returns_true(self): + result = LangFuseHandler._dynamic_langfuse_credentials_are_passed( + {"langfuse_secret_key": "sk-lf-test"} + ) + assert result is True + + def test_dynamic_credentials_with_secret_returns_true(self): + result = LangFuseHandler._dynamic_langfuse_credentials_are_passed( + {"langfuse_secret": "sk-lf-test"} + ) + assert result is True