This commit is contained in:
Harshil Kaneria 2026-11-05 23:13:25 +00:00 • committed by GitHub
commit 41b6d70775
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View file

@ -1647,7 +1647,9 @@ class Logging(LiteLLMLoggingBaseClass):
# log raw request to provider (like LangFuse) -- if opted in.
if self.log_raw_request_response is True or litellm.log_raw_request_response is True:
_litellm_params: Final = self.model_call_details.get("litellm_params", {})
_metadata: Final = _litellm_params.get("metadata", {}) or {}
if _litellm_params.get("metadata") is None:
_litellm_params["metadata"] = {}
_metadata: Final = _litellm_params["metadata"]
try:
self.model_call_details["raw_request_typed_dict"] = RawRequestTypedDict(
raw_request_api_base=self._get_masked_api_base(str(additional_args.get("api_base") or "")),

View file

@ -8662,6 +8662,26 @@ def test_pre_call_redacts_and_masks_raw_request(logging_obj):
assert "key=*****" in raw_api_base
@pytest.mark.parametrize("litellm_params", [{}, {"metadata": None}, {"metadata": {}}])
def test_pre_call_keeps_raw_request_when_request_has_no_metadata(logging_obj, litellm_params):
"""Callbacks read raw_request from litellm_params metadata, which SDK calls often leave unset."""
logging_obj.model_call_details["litellm_params"] = litellm_params
logging_obj.log_raw_request_response = True
logging_obj.pre_call(
input="hi",
api_key="",
additional_args={
"api_base": "https://api.openai.com/v1/chat/completions",
"headers": {},
"complete_input_dict": {"model": "gpt-4o-mini"},
},
)
raw_request = logging_obj.model_call_details["litellm_params"]["metadata"]["raw_request"]
assert "https://api.openai.com/v1/chat/completions" in raw_request
_PRIVATE_RAW_REQUEST_ARGS: Final = {
"api_base": "https://api.openai.com/v1/chat/completions",
"headers": {},