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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(passthrough): stop forwarding client Accept-Encoding upstream
mateo-berrid0be6eee8a34
diff --git a/litellm/passthrough/utils.py b/litellm/passthrough/utils.pyindex e419322dca6..1572913f46e 100644--- a/litellm/passthrough/utils.py+++ b/litellm/passthrough/utils.py@@ -69,6 +69,9 @@ class BasePassthroughUtils:# Header We Should NOT forwardrequest_headers.pop("content-length", None)request_headers.pop("host", None)+ # accept-encoding must stay client-negotiated: forwarding e.g. "br" when+ # the brotli package is absent relays undecodable bytes to the caller+ request_headers.pop("accept-encoding", None)custom_header_names: Final = {header_name.lower() for header_name in headers}for header_name in list(request_headers.keys()):diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_vertex_passthrough_load_balancing.py b/tests/test_litellm/proxy/pass_through_endpoints/test_vertex_passthrough_load_balancing.pyindex aaf1dad4910..02464ad5caa 100644--- a/tests/test_litellm/proxy/pass_through_endpoints/test_vertex_passthrough_load_balancing.py+++ b/tests/test_litellm/proxy/pass_through_endpoints/test_vertex_passthrough_load_balancing.py@@ -568,6 +568,31 @@ def test_forward_headers_custom_wins_case_insensitive_over_request_authorizationassert result["x-request-id"] == "req-123"+def test_forward_headers_never_forwards_client_accept_encoding():+ """+ The client's Accept-Encoding must not reach the upstream provider: the proxy's+ HTTP client decodes the upstream body and advertises only encodings it can+ decode. Forwarding e.g. "br" on an install without the brotli package makes+ the proxy relay raw compressed bytes with the content-encoding header stripped+ (garbled JSON for /v1/models and count_tokens through the Anthropic passthrough).+ """+ from litellm.passthrough.utils import BasePassthroughUtils++ request_headers = {+ "accept-encoding": "gzip, deflate, br, zstd",+ "x-request-id": "req-123",+ }++ result = BasePassthroughUtils.forward_headers_from_request(+ request_headers=request_headers,+ headers={},+ forward_headers=True,+ )++ assert "accept-encoding" not in result+ assert result["x-request-id"] == "req-123"++@pytest.mark.asyncioasync def test_vertex_passthrough_custom_model_name_replaced_in_url():"""