diff --git a/litellm/llms/sap/__init__.py b/litellm/llms/sap/__init__.py new file mode 100644 index 00000000000..e69de29bb2d diff --git a/litellm/llms/sap/credentials.py b/litellm/llms/sap/credentials.py index c303ccb8524..2484ec33e0c 100644 --- a/litellm/llms/sap/credentials.py +++ b/litellm/llms/sap/credentials.py @@ -226,6 +226,9 @@ def _parse_service_key_once( "SAP service key is a string but not valid JSON. Skipping this source." ) return None + verbose_logger.warning( + f"SAP service key has unexpected type '{type(service_key).__name__}'. Expected str or dict. Ignoring." + ) return None def _resolve_credential_from_service_key( @@ -484,11 +487,16 @@ def get_token_creator( cert_pair=(cert_path, key_path), ) # Case 3: file-based cert/key - return _request_token( - auth_url=auth_url, - client_id=client_id, - timeout=timeout, - cert_pair=(cert_file_path, key_file_path), + if cert_file_path and key_file_path: + return _request_token( + auth_url=auth_url, + client_id=client_id, + timeout=timeout, + cert_pair=(cert_file_path, key_file_path), + ) + # Defensive guard: should never reach here due to validate_credentials() + raise ValueError( + "Invalid authentication configuration: no valid credentials found. " ) def get_token() -> str: diff --git a/tests/test_litellm/llms/sap/test_sap_fetch_creds.py b/tests/test_litellm/llms/sap/test_sap_fetch_creds.py index 34c752c45e2..7815c0b88d6 100644 --- a/tests/test_litellm/llms/sap/test_sap_fetch_creds.py +++ b/tests/test_litellm/llms/sap/test_sap_fetch_creds.py @@ -123,7 +123,7 @@ def test_partial_credentials_missing_auth_url(monkeypatch): creds = sap_credentials.fetch_credentials() creds.pop('resource_group') - with pytest.raises(ValueError, match="SAP AI Core credentials not found."): + with pytest.raises(ValueError, match="SAP AI Core credentials not found"): sap_credentials.validate_credentials(**creds) def test_credentials_without_authentication_mode(monkeypatch): @@ -138,5 +138,5 @@ def test_credentials_without_authentication_mode(monkeypatch): creds.pop('resource_group') # validate_credentials should raise because no authentication mode is provided - with pytest.raises(ValueError, match="SAP AI Core credentials are incomplete."): + with pytest.raises(ValueError, match="SAP AI Core credentials are incomplete"): sap_credentials.validate_credentials(**creds)