This commit is contained in:
devin-ai-integration[bot] 2026-10-27 02:24:43 +00:00 • committed by GitHub
commit 01d93a7784
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 75 additions and 1 deletions

View file

@ -1484,6 +1484,19 @@ object rather than ``True`` because ``request_data`` is the client body: JSON ca
client can neither hide a guardrail block nor force a row by sending the key or a ``litellm_call_id`` itself."""
_PROXY_ONLY_LLM_API_ERRORS: Final = (HTTPException, ProxyException, GuardrailRaisedException)
_PROXY_ONLY_ERROR_NON_OPTIONAL_PARAM_KEYS: Final = frozenset(
{
"model",
"user",
"litellm_logging_obj",
"litellm_params",
"optional_params",
"standard_callback_dynamic_params",
"start_time",
"completion_start_time",
"call_type",
}
)
_LOG_DB_METRICS_CALL_TYPES: Final = frozenset(("get_data", "insert_data", "update_data", "delete_data"))
@ -3909,7 +3922,7 @@ class ProxyLogging:
for k, v in request_data.items():
if k in litellm_param_keys:
_litellm_params[k] = v
elif k not in ("model", "user", "litellm_logging_obj"):
elif k not in _PROXY_ONLY_ERROR_NON_OPTIONAL_PARAM_KEYS:
_optional_params[k] = v
attribution: Final = _stamp_deployment_attribution(

View file

@ -2878,6 +2878,67 @@ async def test_handle_logging_proxy_only_error_syncs_normalized_call_type(
assert logging_obj.model_call_details["call_type"] == expected_call_type
@pytest.mark.asyncio
async def test_proxy_only_error_failure_callback_preserves_trusted_litellm_params(
monkeypatch: pytest.MonkeyPatch,
):
from litellm.caching.caching import DualCache
from litellm.integrations.custom_logger import CustomLogger
from litellm.proxy.utils import ProxyLogging, hash_token
class FailureCaptureLogger(CustomLogger):
def __init__(self):
self.failure_kwargs: Dict[str, Any] | None = None
async def async_log_failure_event(
self,
kwargs: Dict[str, Any],
response_obj: object,
start_time: datetime,
end_time: datetime,
) -> None:
self.failure_kwargs = kwargs
capture_logger = FailureCaptureLogger()
monkeypatch.setattr(litellm, "callbacks", [capture_logger])
monkeypatch.setattr(litellm, "input_callback", [])
monkeypatch.setattr(litellm, "success_callback", [])
monkeypatch.setattr(litellm, "failure_callback", [])
monkeypatch.setattr(litellm, "_async_success_callback", [])
monkeypatch.setattr(litellm, "_async_failure_callback", [])
monkeypatch.setattr(litellm.utils, "callback_list", [])
await ProxyLogging(user_api_key_cache=DualCache())._handle_logging_proxy_only_error(
request_data={
"model": "openai/gpt-4o-mini",
"messages": [{"role": "user", "content": "test"}],
"litellm_logging_obj": None,
"litellm_params": {"metadata": {"foo": "bar"}},
"temperature": 0.2,
},
user_api_key_dict=UserAPIKeyAuth(
api_key="sk-test",
key_alias="alias-1",
team_id="team-1",
team_alias="t1",
),
route="/v1/chat/completions",
original_exception=HTTPException(status_code=400, detail="request rejected"),
)
callback_kwargs = capture_logger.failure_kwargs
assert callback_kwargs is not None
litellm_params_metadata = callback_kwargs["litellm_params"]["metadata"]
assert litellm_params_metadata["user_api_key_hash"] == hash_token("sk-test")
assert litellm_params_metadata["user_api_key_alias"] == "alias-1"
assert litellm_params_metadata["user_api_key_team_id"] == "team-1"
assert litellm_params_metadata["user_api_key_team_alias"] == "t1"
standard_metadata = callback_kwargs["standard_logging_object"]["metadata"]
assert standard_metadata["user_api_key_hash"] == hash_token("sk-test")
assert standard_metadata["user_api_key_team_id"] == "team-1"
assert callback_kwargs["optional_params"]["temperature"] == 0.2
@pytest.mark.asyncio
async def test_during_call_hook_parallel_execution():
"""