diff --git a/tests/test_litellm/proxy/auth/test_auth_exception_handler.py b/tests/test_litellm/proxy/auth/test_auth_exception_handler.py index 4328eac8432..d5ef71cd1d1 100644 --- a/tests/test_litellm/proxy/auth/test_auth_exception_handler.py +++ b/tests/test_litellm/proxy/auth/test_auth_exception_handler.py @@ -36,7 +36,7 @@ from litellm.proxy._types import ( ProxyException, UserAPIKeyAuth, ) -from litellm.proxy.auth.auth_exception_handler import UserAPIKeyAuthExceptionHandler +from litellm.proxy.auth.auth_exception_handler import UserAPIKeyAuthExceptionHandler, _as_proxy_exception from litellm.proxy.auth.model_access_denied import ModelAccessDeniedHTTPException @@ -1053,6 +1053,21 @@ async def test_handle_authentication_error_keeps_internal_message_on_model_acces assert [r for r in caplog.records if r.levelname == "WARNING" and "internal-models" in r.getMessage()] == [] +def test_as_proxy_exception_keeps_jwt_scope_denial_message_shape(): + detail = {"error": "The model `gpt-5.6` is unavailable for this API key or does not exist."} + denial = ModelAccessDeniedHTTPException( + internal_message="model=gpt-5.6 not allowed. Allowed_models=['internal-models']", + status_code=status.HTTP_403_FORBIDDEN, + detail=detail, + ) + plain = _as_proxy_exception(HTTPException(status_code=status.HTTP_403_FORBIDDEN, detail=detail)) + + converted = _as_proxy_exception(denial) + + assert converted.to_dict() == plain.to_dict() + assert converted.internal_message == denial.internal_message + + @pytest.mark.asyncio @pytest.mark.parametrize("unset_value", [None, ""]) async def test_handle_authentication_error_no_extra_denial_log_when_message_not_configured(