Skip to content

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]

fix(proxy): strip client standard_logging_object before the failure logging handler

mateo-berri919bf1a09785
diff --git a/litellm/proxy/utils.py b/litellm/proxy/utils.py
index acafc600b80..19dcd64c58d 100644
--- a/litellm/proxy/utils.py
+++ b/litellm/proxy/utils.py
@@ -2309,6 +2309,11 @@ class ProxyLogging:
)
)
+ # Auth and pass-through failure bodies are unstripped client input, and
+ # the logging handler below flattens body keys into model_call_details,
+ # so drop the key before it can masquerade as the built payload.
+ request_data.pop("standard_logging_object", None)
+
### LOGGING ###
if self._is_proxy_only_llm_api_error(
original_exception=original_exception,
@@ -2322,9 +2327,6 @@ class ProxyLogging:
original_exception=original_exception,
)
- # Auth and pass-through failures reach this hook with the raw request
- # body unstripped, so only the logging object may supply this key.
- request_data.pop("standard_logging_object", None)
request_data.update(_failure_fields_to_lift(request_data))
# Remove before callbacks iterate — not serialisable
diff --git a/tests/test_litellm/proxy/test_proxy_utils.py b/tests/test_litellm/proxy/test_proxy_utils.py
index 71af44d6682..07877514b69 100644
--- a/tests/test_litellm/proxy/test_proxy_utils.py
+++ b/tests/test_litellm/proxy/test_proxy_utils.py
@@ -556,6 +556,41 @@ class TestPostCallFailureHookLiftsStandardLoggingObject:
await self._run(request_data_with_obj)
assert "standard_logging_object" not in request_data_with_obj
+ @pytest.mark.asyncio
+ async def test_pass_through_failure_never_relifts_client_supplied_key(self):
+ from datetime import datetime
+ from unittest.mock import AsyncMock, patch
+
+ from fastapi import HTTPException
+
+ from litellm.litellm_core_utils.litellm_logging import Logging
+ from litellm.proxy._types import UserAPIKeyAuth
+
+ logging_obj = Logging(
+ model="claude-haiku-4-5",
+ messages=[{"role": "user", "content": "hi"}],
+ stream=False,
+ call_type="pass_through_endpoint",
+ start_time=datetime.now(),
+ litellm_call_id="test-call-id",
+ function_id="test-function-id",
+ )
+ request_data = {
+ "litellm_logging_obj": logging_obj,
+ "standard_logging_object": {"model_id": "client-injected"},
+ "metadata": {},
+ }
+ proxy_logging_obj = ProxyLogging(user_api_key_cache=DualCache())
+ proxy_logging_obj.alert_types = []
+ with patch.object(proxy_logging_obj, "update_request_status", new=AsyncMock()):
+ await proxy_logging_obj.post_call_failure_hook(
+ request_data=request_data,
+ original_exception=HTTPException(status_code=401, detail="unauthorized"),
+ user_api_key_dict=UserAPIKeyAuth(request_route="/v1/chat/completions"),
+ )
+ assert "standard_logging_object" not in request_data
+ assert "standard_logging_object" not in logging_obj.model_call_details
+
@pytest.mark.asyncio
async def test_no_standard_logging_object_is_noop(self):
logging_obj = MagicMock()