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(logging): preserve null end user in callbacks (#38642)
yucheng-berric5cdd2e8e12c
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.pyindex 157d436e482..a8672b5c112 100644--- a/litellm/litellm_core_utils/litellm_logging.py+++ b/litellm/litellm_core_utils/litellm_logging.py@@ -6058,7 +6058,7 @@ def get_standard_logging_object_payload(prompt_tokens=usage_dict.get("prompt_tokens", 0),completion_tokens=usage_dict.get("completion_tokens", 0),request_tags=request_tags,- end_user=end_user_id or "",+ end_user=end_user_id,api_base=StandardLoggingPayloadSetup.strip_trailing_slash(litellm_params.get("api_base", "")) or "",model_group=_model_group,model_id=_model_id,diff --git a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py b/tests/test_litellm/litellm_core_utils/test_litellm_logging.pyindex af9f626dd17..1193160c831 100644--- a/tests/test_litellm/litellm_core_utils/test_litellm_logging.py+++ b/tests/test_litellm/litellm_core_utils/test_litellm_logging.py@@ -3727,6 +3727,41 @@ def test_get_standard_logging_object_payload_includes_litellm_call_id(logging_obassert payload["litellm_call_id"] == call_id+def test_get_standard_logging_object_payload_preserves_absent_end_user_as_none(logging_obj):+ from datetime import datetime+ from typing import Final++ from litellm.litellm_core_utils.litellm_logging import get_standard_logging_object_payload+ from litellm.types.utils import StandardLoggingPayload++ now: Final = datetime.now()+ payload: Final[StandardLoggingPayload | None] = get_standard_logging_object_payload(+ kwargs={+ "model": "gpt-4o",+ "messages": [],+ "litellm_params": {+ "metadata": {+ "user_api_key_alias": "test-key-alias",+ "user_api_key_user_id": "test-key-user",+ "user_api_key_end_user_id": None,+ },+ "proxy_server_request": {"body": {}},+ },+ },+ init_response_obj={},+ start_time=now,+ end_time=now,+ logging_obj=logging_obj,+ status="success",+ )++ assert payload is not None+ assert payload["metadata"]["user_api_key_alias"] == "test-key-alias"+ assert payload["metadata"]["user_api_key_user_id"] == "test-key-user"+ assert payload["metadata"]["user_api_key_end_user_id"] is None+ assert payload["end_user"] is None++# ── Azure Model Router selected-model attribution ────────────────────────────