From 9d3475d0f25f39c1b997a2d5065ff4c4f23eefa2 Mon Sep 17 00:00:00 2001 From: Sami Rusani Date: Fri, 7 Aug 2026 17:40:35 +0200 Subject: [PATCH] fix(httpx): avoid masked request content rebinding --- litellm/llms/custom_httpx/http_handler.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.py index 0ffd603deac..d7156b125ae 100644 --- a/litellm/llms/custom_httpx/http_handler.py +++ b/litellm/llms/custom_httpx/http_handler.py @@ -434,14 +434,19 @@ def _safe_read_response(response: httpx.Response, timeout: float | None = None) def _build_masked_request(original_request: httpx.Request, masked_url: str) -> httpx.Request: """Build a masked request without forcing unread streaming bodies into memory.""" - headers = httpx.Headers(original_request.headers) + headers: Final = httpx.Headers(original_request.headers) try: - request_content = original_request.content + request_content: Final = original_request.content except httpx.RequestNotRead: - request_content = b"" headers.pop("content-length", None) headers.pop("transfer-encoding", None) headers.pop("content-type", None) + return httpx.Request( + method=original_request.method, + url=masked_url, + headers=headers, + content=b"", + ) return httpx.Request( method=original_request.method,