mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-16 09:22:22 +00:00
fix(proxy): keep the internal stream usage strip flag out of the logged request body
This commit is contained in:
parent
2bee13d569
commit
f73f0111d4
2 changed files with 15 additions and 3 deletions
|
|
@ -2501,6 +2501,7 @@ def refresh_proxy_server_request_body_snapshot(
|
|||
"litellm_logging_obj",
|
||||
VECTOR_STORE_CALLER_METADATA_KWARG,
|
||||
STREAM_USAGE_INJECTED_FIELD,
|
||||
"_litellm_strip_stream_usage",
|
||||
}
|
||||
)
|
||||
| _TRANSPORT_ONLY_CREDENTIAL_KEYS
|
||||
|
|
|
|||
|
|
@ -1202,24 +1202,35 @@ def test_body_snapshot_excludes_team_callback_credentials() -> None:
|
|||
}, proxy_request
|
||||
|
||||
|
||||
def test_body_snapshot_keeps_the_stream_usage_injection_marker_out_of_the_stored_request() -> None:
|
||||
@pytest.mark.parametrize(
|
||||
("route_type", "request_input"),
|
||||
[
|
||||
("acompletion", {"messages": [{"role": "user", "content": "hi"}]}),
|
||||
("atext_completion", {"prompt": "hi"}),
|
||||
],
|
||||
)
|
||||
def test_body_snapshot_keeps_the_stream_usage_injection_marker_out_of_the_stored_request(
|
||||
route_type: str, request_input: dict[str, object]
|
||||
) -> None:
|
||||
from litellm.proxy.common_request_processing import stream_usage_tracking_updates
|
||||
from litellm.proxy.litellm_pre_call_utils import refresh_proxy_server_request_body_snapshot
|
||||
from litellm.types.litellm_params import STREAM_USAGE_INJECTED_FIELD
|
||||
|
||||
request: Final = {"model": "gpt-5-mini", "messages": [{"role": "user", "content": "hi"}], "stream": True}
|
||||
request: Final = {"model": "gpt-5-mini", **request_input, "stream": True}
|
||||
proxy_request: Final = {"body": dict(request)}
|
||||
data: Final = {
|
||||
**request,
|
||||
**stream_usage_tracking_updates(request, {}, "acompletion", lambda: True),
|
||||
**stream_usage_tracking_updates(request, {}, route_type, lambda: True),
|
||||
"proxy_server_request": proxy_request,
|
||||
}
|
||||
|
||||
refresh_proxy_server_request_body_snapshot(data)
|
||||
|
||||
assert data[STREAM_USAGE_INJECTED_FIELD] is True
|
||||
assert data["_litellm_strip_stream_usage"] is True
|
||||
assert proxy_request["body"]["stream_options"] == {"include_usage": True}
|
||||
assert STREAM_USAGE_INJECTED_FIELD not in proxy_request["body"]
|
||||
assert "_litellm_strip_stream_usage" not in proxy_request["body"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue