The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix _return_user_api_key_auth_obj (#7591)
Ishaan Jaff0b5c1392f77c
diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.pyindex 1f127e370be..c0b92deb087 100644--- a/litellm/proxy/auth/user_api_key_auth.py+++ b/litellm/proxy/auth/user_api_key_auth.py@@ -732,7 +732,7 @@ async def user_api_key_auth( # noqa: PLR0915)if is_master_key_valid:- _user_api_key_obj = _return_user_api_key_auth_obj(+ _user_api_key_obj = await _return_user_api_key_auth_obj(user_obj=None,user_role=LitellmUserRoles.PROXY_ADMIN,api_key=master_key,@@ -1177,7 +1177,7 @@ async def user_api_key_auth( # noqa: PLR0915# No token was found when looking up in the DBraise Exception("Invalid proxy server token passed")if valid_token_dict is not None:- return _return_user_api_key_auth_obj(+ return await _return_user_api_key_auth_obj(user_obj=user_obj,api_key=api_key,parent_otel_span=parent_otel_span,@@ -1240,7 +1240,7 @@ async def user_api_key_auth( # noqa: PLR0915)-def _return_user_api_key_auth_obj(+async def _return_user_api_key_auth_obj(user_obj: Optional[LiteLLM_UserTable],api_key: str,parent_otel_span: Optional[Span],@@ -1250,14 +1250,18 @@ def _return_user_api_key_auth_obj(user_role: Optional[LitellmUserRoles] = None,) -> UserAPIKeyAuth:end_time = datetime.now()- user_api_key_service_logger_obj.service_success_hook(- service=ServiceTypes.AUTH,- call_type=route,- start_time=start_time,- end_time=end_time,- duration=end_time.timestamp() - start_time.timestamp(),- parent_otel_span=parent_otel_span,++ asyncio.create_task(+ user_api_key_service_logger_obj.async_service_success_hook(+ service=ServiceTypes.AUTH,+ call_type=route,+ start_time=start_time,+ end_time=end_time,+ duration=end_time.timestamp() - start_time.timestamp(),+ parent_otel_span=parent_otel_span,+ ))+retrieved_user_role = (user_role or _get_user_role(user_obj=user_obj) or LitellmUserRoles.INTERNAL_USER)diff --git a/tests/proxy_unit_tests/test_user_api_key_auth.py b/tests/proxy_unit_tests/test_user_api_key_auth.pyindex a5bc06db62f..7940679cdbf 100644--- a/tests/proxy_unit_tests/test_user_api_key_auth.py+++ b/tests/proxy_unit_tests/test_user_api_key_auth.py@@ -141,12 +141,13 @@ async def test_check_blocked_team():("proxy_admin_viewer", "proxy_admin_viewer"),],)-def test_returned_user_api_key_auth(user_role, expected_role):+async def test_returned_user_api_key_auth(user_role, expected_role):from litellm.proxy._types import LiteLLM_UserTable, LitellmUserRolesfrom litellm.proxy.auth.user_api_key_auth import _return_user_api_key_auth_objfrom datetime import datetime- new_obj = _return_user_api_key_auth_obj(+ new_obj = await _return_user_api_key_auth_obj(user_obj=LiteLLM_UserTable(user_role=user_role, user_id="", max_budget=None, user_email=""),