Skip to content

fix(proxy): decode zstd and gzip request bodies before auth reads them - #47418

Merged
mateo-berri merged 10 commits into
mainfrom
litellm_decode_gzip_zstd_request_bodies
Oct 20, 2026
Merged

mateo-berri merged 10 commits into
mainfrom
litellm_decode_gzip_zstd_request_bodies

Conversation

@mateo-berri

@mateo-berri mateo-berri commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Bodies sent with Content-Encoding: zstd or gzip fail with 400 Invalid JSON
  • The TypeSafe SDK zstd-compresses every request body of 1 KB or more

How it solves it:

User Flow

Before: TypeSafe SDK bodies of 1 KB or more get 400

  1. They create TypeSafeClient(base_url="https://litellm-domain", api_key=<virtual key for jev>, model="jev")
  2. They call system_one(...) with 2 KB of state, and the SDK sends a zstd POST https://litellm-domain/v1/systemone
  3. The proxy answers 400 Invalid JSON: expected value at line 1 column 1 with x-litellm-response-cost: 0
  4. Compressed bodies get 400 on /v1/chat/completions, /v1/responses, /v1/messages, /v1/decisions, and 500 on /anthropic/v1/messages
  5. A jev-only key asking for claude-haiku-5-5 in a zstd body gets that 400, not 403

After: the same call returns answers and a cost

  1. They create TypeSafeClient(base_url="https://litellm-domain", api_key=<virtual key for jev>, model="jev")
  2. They call system_one(...) with 2 KB of state, and the SDK sends a zstd POST https://litellm-domain/v1/systemone
  3. The proxy answers 200 with the answers and x-litellm-response-cost: 3.8304e-05
  4. Those bodies get 200, and a gzip bomb gets 413
  5. A jev-only key asking for claude-haiku-5-5 in a zstd body gets 403 key_model_access_denied

Decisions

Decisions and their alternatives

This supersedes #41567 by @enternal111, which decoded gzip only, and adds zstd and the size cap to the same idea

Pass-through routes are decoded too. Skipping them would not forward the body as sent, since on main a compressed JSON body to a pass-through route gets a 500, and a non-JSON one reaches the target as {} with Content-Encoding still set. Two kinds of routes are the exception and get the body and Content-Encoding as sent, like on main. /plugin-proxy/ is an admin-only reverse proxy that forwards the raw body with its headers. The Claude Code gateway's OTLP export routes (/claude_code_gateway/v1/metrics, /logs, and /traces) decode gzip themselves and accept bodies the middleware refuses, such as two gzip members or a body over the ratio limit

The middleware is registered innermost, inside CORS, the security headers, in-flight tracking, and RequestSizeLimitMiddleware. So its errors carry the same headers as any other error, and the wire size is checked before any decoding. It still runs before every body reader, so auth, the route handlers, and pass-through routes all see the decoded body. Decoding in the handler or in the shared body reader would leave auth checking the compressed bytes

Only a single gzip or zstd coding is decoded, matched without regard to case or surrounding spaces. No header, identity, br, deflate, a list such as gzip, zstd, and websocket requests pass through untouched, so anyone sending those today sees no change. The alternatives were a 415 for codings the proxy can't decode, as RFC 9110 suggests, or decoding stacked codings. x-gzip is decoded as gzip, since RFC 9110 section 8.4.1.3 asks recipients to treat the two the same

A body labeled gzip or zstd that doesn't start with that format's magic number (1f 8b for gzip, 28 b5 2f fd for zstd) reaches the route as sent, with the header dropped. Some clients set the header on plain JSON. On main those requests work on the LLM routes, while pass-through routes forward the header and the vendor answers 400, so dropping the header makes both work. The proxy reads those first bytes before any size limit, so a plain body over the decoded size limit, or a plain body labeled zstd on a proxy without zstd support, also reaches the route as sent. The alternative was a 400 for every body that fails to decode

Decoding stops at the smaller of two limits. The first is 200 times the body's size on the wire, set by MAX_REQUEST_BODY_DECOMPRESSION_RATIO, the same default as Apache's DeflateInflateRatioLimit. Without it a 250 KB body could make the proxy inflate 50 MB before auth on every request. The second is MAX_DECOMPRESSED_REQUEST_BODY_SIZE_MB (default 50), lowered to max_request_size_mb when that enterprise setting is on, so the operator's limit applies to the decoded body too. Past the ratio the proxy answers 413 Request body expands more than 200 times when decoded, and past the size limit 413 Request body is larger than 50 MB when decoded. A body already over the size limit on the wire gets the 413 body RequestSizeLimitMiddleware already sends. The decoder stops at the limit plus one byte, so a 200 MB bomb never inflates past it. A new env var is used for the size limit because max_request_size_mb is enterprise-only and unset by default, which would leave open-source proxies with no bomb protection

A body must be exactly one gzip member or one zstd frame. Concatenated members or frames, a truncated stream, or bytes after the end get a 400 with type: invalid_request_error. The alternative was to accept several members like Python's gzip.decompress does. A zstd body that starts with a skippable frame (50 to 5f, then 2a 4d 18) counts as zstd, so it gets that 400 instead of reaching the route as raw bytes

Each worker holds at most MAX_DECOMPRESSED_REQUEST_BODIES_IN_FLIGHT_MB (default 200) of decoded bodies at a time. Before decoding, a request reserves the decoded size its data declares (the gzip trailer or the zstd frame header), capped by the two limits above, or those limits when it declares none. It keeps only its decoded size while the route runs and gives that back when the route returns. A body that decodes past its declared size gets a 400. A request that doesn't fit gets 503 overloaded_error with Retry-After: 1, the shape admission control uses, and a request always fits when no other decoded body is held. Without it, 16 parallel 391 KB bodies with no key took the proxy from 0.6 GB to 3.2 GB before auth rejected them. The alternatives were reserving the worst case for every request, which let only 4 bodies over 256 KB decode at once per worker, a cap on how many bodies decode at once, which ignores their size, or giving the budget back right after decoding, which leaves decoded bodies waiting on auth uncounted

Bodies are decoded before auth, because auth reads the body to check the requested model against the key. So a caller with no key can still make a worker decode up to the limits above, and the in-flight budget bounds how much it holds at once. Decoding and parsing those bodies also slows every other request on that worker while the flood lasts. Two keyless senders at 3.3 MB/s took a keyed call's median from 19 ms to 320 ms on one worker, and a plain-body flood on main needs about 68 times the bandwidth for the same slowdown. The budget caps memory, not that latency. Checking for a key header first was the alternative, but a made-up key passes that check and custom auth can read any header. An operator who wants no decoding before auth sets MAX_DECOMPRESSED_REQUEST_BODY_SIZE_MB=0, which answers every compressed body with 413

max_request_size_mb is now read the same way in both size middlewares and the auth size check, through pydantic's lax parsing. So "10" means 10 MB, where on main a string raised a TypeError on every request, and true still means 1 MB as on main. Without a license the auth size check returns before it reads the setting, as on main, so a value it can't parse, such as "10MB", changes nothing there

The zstd decoder refuses windows over 8 MB, the limit RFC 9659 sets for the zstd content coding, so a crafted frame can't make the decoder allocate a huge window. Such a frame gets the same 400

Decoding runs in a worker thread, like the response gzip middleware, so a 50 MB decode doesn't block the event loop. The middleware drops content-encoding, content-length, and transfer-encoding and sets content-length to the decoded size on a copy of the request scope. A client that disconnects mid-body gets no response, and an empty body with a supported coding reaches the route empty

zstd comes from the standard library's compression.zstd on Python 3.14 and from backports-zstd below that. It is a proxy extra dependency, and the proxy-dev group carries it too so the type checker resolves it. It is PSF-2.0 licensed, so it is added to the license allowlist. The zstandard package was the alternative, but its API differs from the standard library's. A proxy installed without it still starts and decodes gzip, and answers a zstd body with 415 and Accept-Encoding: gzip, as RFC 9110 describes

With backports-zstd installed, requests and aiohttp add zstd to their default Accept-Encoding and urllib3 decodes zstd replies, which Python 3.14 installs already do on main. litellm's provider calls set their own Accept-Encoding and don't change. Leaving zstd out of the proxy extra was the alternative, but then the proxy can't decode zstd bodies below Python 3.14

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Last updated: c7060ca. QA and /live-pr-risk ran on 81faa75, the last commit with a product diff

Two workers per proxy, real provider calls

Case Before After
SDK, zstd 400 200
SDK, disallowed model 400 403
Chat, gzip, x-gzip, stream 400, 400, 400 200, 200, 200
Responses, gzip 400 200
Messages, gzip 400 200
Pass-through, zstd 500 200
Decisions, zstd 400 200
gzip bomb, corrupt zstd, skippable frame 400, 400, 400 413, 400, 400
Plain bodies 200, 200, 403 200, 200, 403
Plain labeled gzip 200, 403 200, 403
CORS, corrupt zstd 200, 400 with CORS 200, 400 with CORS
Plugin proxy, zstd 200, sent as is 200, sent as is
Parallel gzip, then SDK 16 x 401, SDK 400 8 x 401, 8 x 503, SDK 200
1 MB gzip burst 16 x 400 16 x 403
SDK spend log row 400, no call id 200, row with spend
Quoted max_request_size_mb 500, 500 200, 200
Setup, config.yaml, the client script, and the curl bodies

Both proxies ran python litellm/proxy/proxy_cli.py --config config.yaml --port $PORT --num_workers 2 from their own worktree on one .env and database. The client is typesafe-sdk==0.7.5 on Python 3.14.3, plus curl for the other routes, on real TypeSafe, OpenAI, and Anthropic calls. $JEV_KEY may use only jev, and $LITELLM_KEY all three models

The quoted max_request_size_mb case ran one more proxy per leg the same way, with LITELLM_LICENSE set and max_request_size_mb: "10" added under general_settings

model_list:
  - model_name: jev
    litellm_params:
      model: typesafe/jev-latest
      api_key: os.environ/TYPESAFE_API_KEY
  - model_name: gpt-5.6
    litellm_params:
      model: openai/gpt-5.6
      api_key: os.environ/OPENAI_API_KEY
  - model_name: claude-haiku-5-5
    litellm_params:
      model: anthropic/claude-haiku-5-5
      api_key: os.environ/ANTHROPIC_API_KEY

general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
  database_url: os.environ/DATABASE_URL
  plugins:
    - name: notes
      url: "http://127.0.0.1:59122"

jev_client.py, run as python jev_client.py <base url> <key> small|large default|off [model]

import sys

import httpx2
from typesafe_sdk import Choice, Noul, RetryPolicy, TypeSafeClient, TypeSafeError

base_url, api_key, size, compression = sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4]
model = sys.argv[5] if len(sys.argv) > 5 else ("jev" if "127.0.0.1" in base_url else "jev-latest")

ticket = "Customer wrote: I was charged twice for my order #4411 and want one of the charges refunded today."
state = ticket if size == "small" else ticket + " Order history: " + " ".join(
    f"order #{4000 + i} shipped on time and was paid once." for i in range(40)
)


def show(response: httpx2.Response) -> None:
    response.read()
    sent = response.request
    print(
        f"request  POST {sent.url.path}  content-encoding={sent.headers.get('content-encoding', '-')}"
        f"  bytes on the wire={len(sent.content)}"
    )
    print(
        f"response {response.status_code}  x-litellm-response-cost={response.headers.get('x-litellm-response-cost', '-')}"
        f"  x-litellm-call-id={response.headers.get('x-litellm-call-id', '-')}"
    )
    if response.status_code != 200:
        print(f"body     {response.text[:300]}")


with TypeSafeClient(
    api_key=api_key,
    base_url=base_url,
    model=model,
    retry=RetryPolicy(max_retries=0),
    compression=None if compression == "default" else False,
    http_client=httpx2.Client(timeout=60, event_hooks={"response": [show]}),
) as client:
    try:
        result = client.system_one(
            state=state,
            questions={
                "is_refund_request": Noul(instructions="Is the customer asking for a refund?"),
                "urgency": Choice(
                    instructions="How urgent is this?",
                    criteria={"low": "can wait a week", "high": "needs action today"},
                ),
            },
        )
    except TypeSafeError as error:
        print(f"client   {type(error).__name__}: {str(error)[:300]}")
    else:
        print(
            f"client   is_refund_request={result.nouls['is_refund_request'].noul:.3f}"
            f"  urgency={result.choices['urgency'].choice}  usage={result.usage}"
        )

Each curl body is the JSON request for its route, compressed with Python's gzip.compress or compression.zstd.compress. bomb.json.gz is a 61 KB chat request whose message is 60 MB of a, corrupt.json.zst is a zstd frame with its last 6 bytes cut and junk added, chat.json is the uncompressed chat request, skippable_then_chat.json.zst is a 4-byte zstd skippable frame followed by the zstd chat request, and flood.json.gz is a 523 KB gzip chat request that decodes to 45 MB. The notes plugin is a 20-line Python HTTP server that answers with the Content-Encoding, byte count, and SHA-256 prefix of the body it received

Before (f07596a)

SDK, zstd

  1. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large default
    
  2. Observed

    request  POST /v1/systemone  content-encoding=zstd  bytes on the wire=391
    response 400  x-litellm-response-cost=0  x-litellm-call-id=-
    body     {"error":{"message":"litellm.BadRequestError: Invalid Decisions request: 1 validation error for dict[str,any]\n  Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=b'(\\xb5/\\xfd`\\xcd\\x07\\xed...1a\\xf7z\\x07XLaW\\x9f\\x01', input_type=bytes]\n    For further informati
    client   TypeSafeBadRequestError: POST http://localhost:$PORT/v1/systemone: 400 litellm.BadRequestError: Invalid Decisions request: 1 validation error for dict[str,any]
      Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=b'(\xb5/\xfd`\xcd\x07\xed...1a\xf7z\x07XLaW\x9f\x01', input_type=bytes]
        For fur
    

SDK, disallowed model

Steps and output
  1. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large default claude-haiku-5-5
    
  2. Observed

    request  POST /v1/systemone  content-encoding=zstd  bytes on the wire=398
    response 400  x-litellm-response-cost=0  x-litellm-call-id=-
    body     {"error":{"message":"litellm.BadRequestError: Invalid Decisions request: 1 validation error for dict[str,any]\n  Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=b'(\\xb5/\\xfd`\\xda\\x07%\\x0...fw\\x80\\xc5\\x14v\\xf5\\x19', input_type=bytes]\n    For further informat
    client   TypeSafeBadRequestError: POST http://localhost:$PORT/v1/systemone: 400 litellm.BadRequestError: Invalid Decisions request: 1 validation error for dict[str,any]
      Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=b'(\xb5/\xfd`\xda\x07%\x0...fw\x80\xc5\x14v\xf5\x19', input_type=bytes]
        For fur
    

Chat, gzip, x-gzip, stream

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @chat.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 400 Bad Request
    x-litellm-response-cost: 0
    {"error":{"message":"/chat/completions: Missing required parameter: 'messages'.","type":"invalid_request_error","param":"messages","code":"400"}}
    
  3. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: x-gzip' --data-binary @chat.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  4. Observed

    HTTP/1.1 400 Bad Request
    x-litellm-response-cost: 0
    {"error":{"message":"/chat/completions: Missing required parameter: 'messages'.","type":"invalid_request_error","param":"messages","code":"400"}}
    
  5. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @chat_stream.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  6. Observed

    HTTP/1.1 400 Bad Request
    x-litellm-response-cost: 0
    {"error":{"message":"/chat/completions: Missing required parameter: 'messages'.","type":"invalid_request_error","param":"messages","code":"400"}}
    

Responses, gzip

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @responses.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 400 Bad Request
    x-litellm-response-cost: 0
    {"error":{"message":"/responses: Missing required parameter: 'input'.","type":"invalid_request_error","param":"input","code":"400"}}
    

Messages, gzip

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @messages.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 400 Bad Request
    {"type":"error","error":{"type":"invalid_request_error","message":"anthropic_messages: Missing required parameter: 'messages'."}}
    

Pass-through, zstd

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/anthropic/v1/messages -H "Authorization: Bearer $LITELLM_KEY" -H 'anthropic-version: 2023-06-01' -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @passthrough_messages.json.zst | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 500 Internal Server Error
    {"error":{"message":"Internal server error","type":"internal_server_error"}}
    

Decisions, zstd

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/decisions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @decisions.json.zst | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 400 Bad Request
    x-litellm-response-cost: 0
    {"error":{"message":"litellm.BadRequestError: Invalid Decisions request: 1 validation error for dict[str,any]\n  Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=b'(\\xb5/\\xfd \\xf7u\\x05\\x0...xfa\\xb4\\x9c\\xb6\\xe6\\x13', input_type=bytes]\n    For further informat
    

gzip bomb, corrupt zstd, skippable frame

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @bomb.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 400 Bad Request
    x-litellm-response-cost: 0
    {"error":{"message":"/chat/completions: Missing required parameter: 'messages'.","type":"invalid_request_error","param":"messages","code":"400"}}
    
  3. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @corrupt.json.zst | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  4. Observed

    HTTP/1.1 400 Bad Request
    x-litellm-response-cost: 0
    {"error":{"message":"/chat/completions: Missing required parameter: 'messages'.","type":"invalid_request_error","param":"messages","code":"400"}}
    
  5. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @skippable_then_chat.json.zst | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  6. Observed

    HTTP/1.1 400 Bad Request
    x-litellm-response-cost: 0
    {"error":{"message":"/chat/completions: Missing required parameter: 'messages'.","type":"invalid_request_error","param":"messages","code":"400"}}
    

Plain bodies

Steps and output
  1. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY small default
    
  2. Observed

    request  POST /v1/systemone  content-encoding=-  bytes on the wire=358
    response 200  x-litellm-response-cost=1.4658e-05  x-litellm-call-id=ffd0d0d9-113c-40eb-80fd-1ec6dacefbd1
    client   is_refund_request=0.990  urgency=high  usage=input_tokens=349 output_tokens=51
    
  3. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large off
    
  4. Observed

    request  POST /v1/systemone  content-encoding=-  bytes on the wire=2253
    response 200  x-litellm-response-cost=3.8304e-05  x-litellm-call-id=29a7cd1a-fcdb-4d57-9b8c-1b05b10ed21b
    client   is_refund_request=0.990  urgency=high  usage=input_tokens=912 output_tokens=51
    
  5. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large off claude-haiku-5-5
    
  6. Observed

    request  POST /v1/systemone  content-encoding=-  bytes on the wire=2266
    response 403  x-litellm-response-cost=-  x-litellm-call-id=-
    body     {"error":{"message":"The requested model 'claude-haiku-5-5' is not available for this API key, or the model name is invalid. Check the models available to you and try again.","type":"key_model_access_denied","param":"model","code":"403"}}
    client   TypeSafePermissionDeniedError: POST http://localhost:$PORT/v1/systemone: 403 The requested model 'claude-haiku-5-5' is not available for this API key, or the model name is invalid. Check the models available to you and try again.
    

Plain labeled gzip

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @chat.json | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 200 OK
    x-litellm-response-cost: 0.000132
    {"id":"chatcmpl-EasxFUGCsyDyLtZg1tUaNFcvyeGdg","created":1792459761,"model":"gpt-5.6","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant","annotations":[],"refusal":null},"provider_specific_fields":{}}],"usage":{"completion_tokens":4
    
  3. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @plain_51mb.json | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  4. Observed

    HTTP/1.1 100 Continue
    HTTP/1.1 403 Forbidden
    {"error":{"message":"The requested model 'no-such-model' is not available for this API key, or the model name is invalid. Check the models available to you and try again.","type":"key_model_access_denied","param":"model","code":"403"}}
    

CORS, corrupt zstd

Steps and output
  1. Run

    curl -sS -i -X OPTIONS http://localhost:$PORT/v1/chat/completions -H 'Origin: http://localhost:3000' -H 'Access-Control-Request-Method: POST' -H 'Access-Control-Request-Headers: authorization, content-type, content-encoding' | grep -aiE '^HTTP/|^access-control-allow-(origin|headers|methods):' | cut -c1-200 | head -4
    
  2. Observed

    HTTP/1.1 200 OK
    access-control-allow-origin: *
    access-control-allow-methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT
    access-control-allow-headers: authorization, content-type, content-encoding
    
  3. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H 'Origin: http://localhost:3000' -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @corrupt.json.zst | grep -aiE '^HTTP/|^access-control-allow-origin:|^x-content-type-options:|^\{' | cut -c1-300 | head -4
    
  4. Observed

    HTTP/1.1 400 Bad Request
    access-control-allow-origin: *
    x-content-type-options: nosniff
    {"error":{"message":"/chat/completions: Missing required parameter: 'messages'.","type":"invalid_request_error","param":"messages","code":"400"}}
    

Plugin proxy, zstd

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/plugin-proxy/notes/v1/run -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @decisions.json.zst | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 200 OK
    {"plugin_saw_content_encoding": "zstd", "plugin_saw_bytes": 183, "plugin_saw_sha256": "5a77f93769d32279"}
    

Parallel gzip, then SDK

Steps and output
  1. Run

    (for i in {1..16}; do curl -s -o /dev/null -w '%{http_code}\n' http://localhost:$PORT/v1/chat/completions -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @flood.json.gz & done; sleep 0.2; curl -s -o /dev/null -w 'liveliness %{http_code} in %{time_total}s\n' http://localhost:$PORT/health/liveliness; wait) | sort | uniq -c
    
  2. Observed

         16 401
          1 liveliness 200 in 0.236897s
    
  3. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large default
    
  4. Observed

    request  POST /v1/systemone  content-encoding=zstd  bytes on the wire=391
    response 400  x-litellm-response-cost=0  x-litellm-call-id=-
    body     {"error":{"message":"litellm.BadRequestError: Invalid Decisions request: 1 validation error for dict[str,any]\n  Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=b'(\\xb5/\\xfd`\\xcd\\x07\\xed...1a\\xf7z\\x07XLaW\\x9f\\x01', input_type=bytes]\n    For further informati
    client   TypeSafeBadRequestError: POST http://localhost:$PORT/v1/systemone: 400 litellm.BadRequestError: Invalid Decisions request: 1 validation error for dict[str,any]
      Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=b'(\xb5/\xfd`\xcd\x07\xed...1a\xf7z\x07XLaW\x9f\x01', input_type=bytes]
        For fur
    

1 MB gzip burst

Steps and output
  1. Run

    (for i in {1..16}; do curl -s -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @burst_1mb.json.gz | grep -aoE '^HTTP/1.1 [0-9]+|"type":"[a-z_]+"' | paste -sd' ' - & done; wait) | sort | uniq -c
    
  2. Observed

         16 HTTP/1.1 400 "type":"invalid_request_error"
    

SDK spend log row

Steps and output
  1. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large default
    
  2. Observed

    request  POST /v1/systemone  content-encoding=zstd  bytes on the wire=391
    response 400  x-litellm-response-cost=0  x-litellm-call-id=-
    body     {"error":{"message":"litellm.BadRequestError: Invalid Decisions request: 1 validation error for dict[str,any]\n  Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=b'(\\xb5/\\xfd`\\xcd\\x07\\xed...1a\\xf7z\\x07XLaW\\x9f\\x01', input_type=bytes]\n    For further informati
    client   TypeSafeBadRequestError: POST http://localhost:$PORT/v1/systemone: 400 litellm.BadRequestError: Invalid Decisions request: 1 validation error for dict[str,any]
      Invalid JSON: expected value at line 1 column 1 [type=json_invalid, input_value=b'(\xb5/\xfd`\xcd\x07\xed...1a\xf7z\x07XLaW\x9f\x01', input_type=bytes]
        For fur
    

Quoted max_request_size_mb

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' --data-binary @chat.json | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 500 Internal Server Error
    {"error":{"message":"Internal server error","type":"internal_server_error"}}
    
  3. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @chat.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  4. Observed

    HTTP/1.1 500 Internal Server Error
    {"error":{"message":"Internal server error","type":"internal_server_error"}}
    

After (81faa75)

SDK, zstd

  1. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large default
    
  2. Observed

    request  POST /v1/systemone  content-encoding=zstd  bytes on the wire=391
    response 200  x-litellm-response-cost=3.8304e-05  x-litellm-call-id=28b2e135-b0c9-47cc-8ea4-dc206b036100
    client   is_refund_request=0.990  urgency=high  usage=input_tokens=912 output_tokens=51
    

SDK, disallowed model

Steps and output
  1. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large default claude-haiku-5-5
    
  2. Observed

    request  POST /v1/systemone  content-encoding=zstd  bytes on the wire=398
    response 403  x-litellm-response-cost=-  x-litellm-call-id=-
    body     {"error":{"message":"The requested model 'claude-haiku-5-5' is not available for this API key, or the model name is invalid. Check the models available to you and try again.","type":"key_model_access_denied","param":"model","code":"403"}}
    client   TypeSafePermissionDeniedError: POST http://localhost:$PORT/v1/systemone: 403 The requested model 'claude-haiku-5-5' is not available for this API key, or the model name is invalid. Check the models available to you and try again.
    

Chat, gzip, x-gzip, stream

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @chat.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 200 OK
    x-litellm-response-cost: 0.000132
    {"id":"chatcmpl-EauEgmiQpKVXNvmumSk1nc18J4x4C","created":1792464686,"model":"gpt-5.6","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant","annotations":[],"refusal":null},"provider_specific_fields":{}}],"usage":{"completion_tokens":4
    
  3. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: x-gzip' --data-binary @chat.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  4. Observed

    HTTP/1.1 200 OK
    x-litellm-response-cost: 0.000132
    {"id":"chatcmpl-EauEsIz5crdhXPOaED43EzYep86ia","created":1792464698,"model":"gpt-5.6","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant","annotations":[],"refusal":null},"provider_specific_fields":{}}],"usage":{"completion_tokens":4
    
  5. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @chat_stream.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  6. Observed

    HTTP/1.1 200 OK
    data: {"id":"chatcmpl-EauEhFUcraScDxXoraEl9QhZqeFJj","object":"chat.completion.chunk","created":1792464687,"model":"gpt-5.6","service_tier":"default","choices":[{"index":0,"delta":{"role":"assistant","content":""}}]}
    data: {"id":"chatcmpl-EauEhFUcraScDxXoraEl9QhZqeFJj","object":"chat.completion.chunk","created":1792464687,"model":"gpt-5.6","service_tier":"default","choices":[{"index":0,"delta":{"content":"pong"}}]}
    

Responses, gzip

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/responses -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @responses.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 200 OK
    x-litellm-response-cost: 0.000152
    {"id":"resp_muNjoGkXwt335KPXb_6tmip7HiHxJ-uMYlqlcNZfHQXIg-d0tTMcRZWMEWGIToz_nURrK_28VJ3yx8T_GUZQaenrXmJG2li1W1de67EfzFr45mNd1U5Zo6qfKHE5JugU9rvOk6-KtnG2cliBAwyFMXeIJ8PB5LZ1yfl72ZZvSj994-KygZiPnDVoX83JEdMlwhfb4_d7zrlKEQIWIUZUfAZFx9jLgGLBYsey7fPhqS8lKXZs2ZMPOhb3_RmftdzD3jaqbp3SIXPX6d-Y0ln9zlbbegpYbO_c
    

Messages, gzip

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/messages -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @messages.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 200 OK
    x-litellm-response-cost: 4.2999999999999995e-06
    {"model":"claude-haiku-5-5","id":"msg_011CgCjL24omPMbYFeYYBCJp","type":"message","role":"assistant","content":[{"type":"text","text":"Pong"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":18,"cache_creation_input_tokens":0,"cache_read_inpu
    

Pass-through, zstd

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/anthropic/v1/messages -H "Authorization: Bearer $LITELLM_KEY" -H 'anthropic-version: 2023-06-01' -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @passthrough_messages.json.zst | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 200 OK
    {"model":"claude-haiku-5-5","id":"msg_011CgCjL7ZTGZQcQ84tGghK8","type":"message","role":"assistant","content":[{"type":"text","text":"Pong"}],"container":null,"stop_reason":"end_turn","stop_sequence":null,"stop_details":null,"usage":{"input_tokens":18,"cache_creation_input_tokens":0,"cache_read_inpu
    

Decisions, zstd

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/decisions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @decisions.json.zst | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 200 OK
    x-litellm-response-cost: 1.2222e-05
    {"model":"jev-1.13.0","answers":[{"type":"predicate","name":"is_refund_request","probability":0.99}],"usage":{"input_tokens":291,"input_tokens_details":{"cached_tokens":0,"cache_write_tokens":0},"output_tokens":23,"output_tokens_details":{"reasoning_tokens":0},"total_tokens":314}}
    

gzip bomb, corrupt zstd, skippable frame

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @bomb.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 413 Request Entity Too Large
    {"error":{"message":"Request body expands more than 200 times when decoded","type":"invalid_request_error","param":null,"code":"413"}}
    
  3. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @corrupt.json.zst | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  4. Observed

    HTTP/1.1 400 Bad Request
    {"error":{"message":"Request body has data after the end of its zstd stream","type":"invalid_request_error","param":null,"code":"400"}}
    
  5. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @skippable_then_chat.json.zst | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  6. Observed

    HTTP/1.1 400 Bad Request
    {"error":{"message":"Request body has data after the end of its zstd stream","type":"invalid_request_error","param":null,"code":"400"}}
    

Plain bodies

Steps and output
  1. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY small default
    
  2. Observed

    request  POST /v1/systemone  content-encoding=-  bytes on the wire=358
    response 200  x-litellm-response-cost=1.4658e-05  x-litellm-call-id=1431ca30-a4d6-45e5-ac41-165c1c723b91
    client   is_refund_request=0.990  urgency=high  usage=input_tokens=349 output_tokens=51
    
  3. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large off
    
  4. Observed

    request  POST /v1/systemone  content-encoding=-  bytes on the wire=2253
    response 200  x-litellm-response-cost=3.8304e-05  x-litellm-call-id=055a0f81-d60c-424c-bb86-98570201cd69
    client   is_refund_request=0.990  urgency=high  usage=input_tokens=912 output_tokens=51
    
  5. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large off claude-haiku-5-5
    
  6. Observed

    request  POST /v1/systemone  content-encoding=-  bytes on the wire=2266
    response 403  x-litellm-response-cost=-  x-litellm-call-id=-
    body     {"error":{"message":"The requested model 'claude-haiku-5-5' is not available for this API key, or the model name is invalid. Check the models available to you and try again.","type":"key_model_access_denied","param":"model","code":"403"}}
    client   TypeSafePermissionDeniedError: POST http://localhost:$PORT/v1/systemone: 403 The requested model 'claude-haiku-5-5' is not available for this API key, or the model name is invalid. Check the models available to you and try again.
    

Plain labeled gzip

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @chat.json | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 200 OK
    x-litellm-response-cost: 0.000132
    {"id":"chatcmpl-EauEnSEuaX1pxrXHqUNul9fwAM7EJ","created":1792464693,"model":"gpt-5.6","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant","annotations":[],"refusal":null},"provider_specific_fields":{}}],"usage":{"completion_tokens":4
    
  3. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @plain_51mb.json | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  4. Observed

    HTTP/1.1 100 Continue
    HTTP/1.1 403 Forbidden
    {"error":{"message":"The requested model 'no-such-model' is not available for this API key, or the model name is invalid. Check the models available to you and try again.","type":"key_model_access_denied","param":"model","code":"403"}}
    

CORS, corrupt zstd

Steps and output
  1. Run

    curl -sS -i -X OPTIONS http://localhost:$PORT/v1/chat/completions -H 'Origin: http://localhost:3000' -H 'Access-Control-Request-Method: POST' -H 'Access-Control-Request-Headers: authorization, content-type, content-encoding' | grep -aiE '^HTTP/|^access-control-allow-(origin|headers|methods):' | cut -c1-200 | head -4
    
  2. Observed

    HTTP/1.1 200 OK
    access-control-allow-origin: *
    access-control-allow-methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT
    access-control-allow-headers: authorization, content-type, content-encoding
    
  3. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H 'Origin: http://localhost:3000' -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @corrupt.json.zst | grep -aiE '^HTTP/|^access-control-allow-origin:|^x-content-type-options:|^\{' | cut -c1-300 | head -4
    
  4. Observed

    HTTP/1.1 400 Bad Request
    access-control-allow-origin: *
    x-content-type-options: nosniff
    {"error":{"message":"Request body has data after the end of its zstd stream","type":"invalid_request_error","param":null,"code":"400"}}
    

Plugin proxy, zstd

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/plugin-proxy/notes/v1/run -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: zstd' --data-binary @decisions.json.zst | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 200 OK
    {"plugin_saw_content_encoding": "zstd", "plugin_saw_bytes": 183, "plugin_saw_sha256": "5a77f93769d32279"}
    

Parallel gzip, then SDK

Steps and output
  1. Run

    (for i in {1..16}; do curl -s -o /dev/null -w '%{http_code}\n' http://localhost:$PORT/v1/chat/completions -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @flood.json.gz & done; sleep 0.2; curl -s -o /dev/null -w 'liveliness %{http_code} in %{time_total}s\n' http://localhost:$PORT/health/liveliness; wait) | sort | uniq -c
    
  2. Observed

          8 401
          8 503
          1 liveliness 200 in 2.891797s
    
  3. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large default
    
  4. Observed

    request  POST /v1/systemone  content-encoding=zstd  bytes on the wire=391
    response 200  x-litellm-response-cost=3.8304e-05  x-litellm-call-id=a2d6acb3-5468-495c-b12c-a891ab58b0f3
    client   is_refund_request=0.990  urgency=high  usage=input_tokens=912 output_tokens=51
    

1 MB gzip burst

Steps and output
  1. Run

    (for i in {1..16}; do curl -s -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @burst_1mb.json.gz | grep -aoE '^HTTP/1.1 [0-9]+|"type":"[a-z_]+"' | paste -sd' ' - & done; wait) | sort | uniq -c
    
  2. Observed

         16 HTTP/1.1 403 "type":"key_model_access_denied"
    

SDK spend log row

Steps and output
  1. Run

    python jev_client.py http://localhost:$PORT $JEV_KEY large default
    
  2. Observed

    request  POST /v1/systemone  content-encoding=zstd  bytes on the wire=391
    response 200  x-litellm-response-cost=3.8304e-05  x-litellm-call-id=f3e9a17a-49ea-47d7-a899-a66f33a8715d
    client   is_refund_request=0.990  urgency=high  usage=input_tokens=912 output_tokens=51
    
  3. Run

    sleep 30; curl -sS "http://localhost:$PORT/spend/logs?request_id=f3e9a17a-49ea-47d7-a899-a66f33a8715d" -H "Authorization: Bearer $LITELLM_MASTER_KEY" | jq -c '.[] | {request_id, call_type, model, spend, total_tokens, status}'
    
  4. Observed

    {"request_id":"f3e9a17a-49ea-47d7-a899-a66f33a8715d","call_type":"asystemone","model":"typesafe/jev-latest","spend":0.000038304,"total_tokens":963,"status":"success"}
    

Quoted max_request_size_mb

Steps and output
  1. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' --data-binary @chat.json | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  2. Observed

    HTTP/1.1 200 OK
    x-litellm-response-cost: 0.000132
    {"id":"chatcmpl-EauFQLdLbd7vDhcsQ2Hf9cpBtHtym","created":1792464732,"model":"gpt-5.6","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant","annotations":[],"refusal":null},"provider_specific_fields":{}}],"usage":{"completion_tokens":4
    
  3. Run

    curl -sS -i http://localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_KEY" -H 'Content-Type: application/json' -H 'Content-Encoding: gzip' --data-binary @chat.json.gz | grep -aiE "^HTTP/|^x-litellm-response-cost:|^\{|^data: \{" | cut -c1-300 | head -3
    
  4. Observed

    HTTP/1.1 200 OK
    x-litellm-response-cost: 0.000132
    {"id":"chatcmpl-EauFR9pE3UOsmuKZX34VabaRCJRiZ","created":1792464733,"model":"gpt-5.6","object":"chat.completion","choices":[{"finish_reason":"stop","index":0,"message":{"content":"pong","role":"assistant","annotations":[],"refusal":null},"provider_specific_fields":{}}],"usage":{"completion_tokens":4
    

/live-pr-risk (81faa75)

Two regressions in 04c1a68, both fixed in 81faa75

Base, head, and head merged with main ran side by side, two workers each, with a recorder in front of each real provider

Breaking. At 04c1a68, Claude Code OTLP exports to /claude_code_gateway/v1/logs, /metrics, and /traces with two gzip members got 400, and one decoding past 200 times its size got 413, where main answers 200. Fixed in 81faa75, since those routes now get the body as sent. All 12 exports (plain, gzip, two members, over the ratio, on each route) answer 200 on head and on the merged tree, like main, and an export with no key gets 401 on all three

Backward incompatible. At 04c1a68 a proxy with no license and an unparseable max_request_size_mb such as "10MB" failed requests that pass on main. Fixed in 81faa75, with a regression test. With backports-zstd installed, requests and aiohttp advertise zstd by default, as Python 3.14 installs already do on main. Every recorded provider call keeps the same headers on all three trees

Regression risk. Plain bodies skip the middleware, and every plain-body scenario matched main on head and the merged tree. What stays untested live only sees compressed bodies, which no route accepted on main: Vertex, Bedrock SigV4, and the other pass-through families, multipart uploads, MCP, SCIM, and SAML. On the retired /v1/traces and /v1/logs routes a two-member or over-ratio gzip body gets 400 or 413 instead of 410

Scenario diffs. Main against head and the merged tree differ only in gzip chat (400 to 200), zstd /anthropic (500 to 200), a plain body labeled gzip on /anthropic (vendor 400 to 200, the header is no longer forwarded), and a deleted key that still answers on a sibling worker, which main does too (5 of 5 tries on main, 3 of 5 on head)

Not verified. The realtime websocket with an unparseable limit, /v1/files (files_settings unset on all trees), Vertex and Bedrock SigV4 with a compressed body, multipart uploads, MCP, SCIM, SAML, and the published Docker image

Type

Bug Fix
Test

Caveats (if any)

Medium

  • Keyless gzip floods slow other requests, since bodies decode before auth
    • Two senders at 3.3 MB/s took keyed p50 from 19 ms to 320 ms
    • Main needs about 68 times that bandwidth
    • MAX_DECOMPRESSED_REQUEST_BODY_SIZE_MB=0 turns decoding off
  • A valid, very repetitive body over 200 times its size gets 413
    • Raise MAX_REQUEST_BODY_DECOMPRESSION_RATIO or turn off SDK compression

Low

  • Stampbot approved at the first commit, before the product code
  • Keyless compressed calls get 400, 413, or 503, not 401
  • Decode errors use the OpenAI error shape on every route
  • Two gzip members or two zstd frames get 400, though the specs allow them
  • The decoder's 400, 413, and 503 write no log line or metric

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Bugbot summary

[!NOTE]
Medium Risk
New request-path middleware decodes bodies before auth on every worker, which changes security/DoS surface (keyless decode load, memory budget) though limits and bypass routes are explicit; touches core proxy ingress for all compressed POSTs.

Overview
Adds RequestBodyDecompressionMiddleware so the proxy transparently inflates gzip / zstd (and x-gzip) request bodies before auth and route handlers read them—fixing clients like the TypeSafe SDK that send compressed JSON and previously hit “invalid JSON” or wrong auth outcomes on compressed bytes.

Decoding is bounded by new env defaults (50 MB decoded size, 200× expansion ratio, 200 MB in-flight decoded memory per worker) with 413 / 400 / 503 responses for bombs, bad streams, and overload; enterprise max_request_size_mb now applies to decoded size via shared configured_max_request_size_mb() (Pydantic parsing, including quoted "10"). /plugin-proxy/ and Claude Code gateway OTLP paths still receive raw bodies unchanged.

backports-zstd is added for Python < 3.14; send_request_too_large is shared with the existing size-limit middleware.

Reviewed by Cursor Bugbot for commit c7060ca. Bugbot is set up for automated code reviews on this repo. Configure here.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litellm-stampbot

@kerry-berri

kerry-berri commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

litellm-stampbot: risk low

Approved at 728967d.

Rules (stampbot/risk_rules.yml):

  • low: 0 changed source lines (only tests, docs, cookbook, markdown or the cost map changed), approved without asking Bugbot or the judge

Judge: skipped, the rules alone decided.

Pushes do not re-run this check. Comment @litellm-stampbot again to re-check the new head.

@kerry-berri kerry-berri added the risk:low Small, isolated, low-risk change label Oct 19, 2026

@kerry-berri kerry-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Low risk by rule and by judgement at 728967d

@codecov

codecov Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.26740% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...iddleware/request_body_decompression_middleware.py 99.61% 1 Missing ⚠️
litellm/proxy/proxy_server.py 75.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@codspeed

codspeed Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 1 benchmark spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 32 untouched benchmarks


Comparing litellm_decode_gzip_zstd_request_bodies (c7060ca) with main (daa133d)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (da80552) during the generation of this report, so daa133d was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@litereview

litereview Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

✅ code-review

5/5 · Ready for human review

Scope: full · Full PR review.

No correctness findings.

Checks and execution details
  • Passed · Real testing evidence (required): Not applicable: no LLM translation changes in the scoped paths. The changed files are litellm/constants.py, litellm/proxy/auth/auth_utils.py, litellm/proxy/middleware/*, litellm/proxy/proxy_server.py, pyproject.toml, uv.lock, the license ini and tests. None of them is under litellm/llms/** or litellm/litellm_core_utils/prompt_templates/**.

  • Passed · Compatibility requirements (required): No supported behavior breaks.

  • Before: a body with gzip or zstd Content-Encoding failed on LLM routes with 400 invalid JSON. It failed on pass-through routes with a 500 or reached the target as {}.

  • After: the proxy decodes it, or returns 413 or 400.

  • Unchanged paths: requests with no header, identity, br, deflate, multiple codings, websocket requests, /plugin-proxy/ and the Claude Code OTLP routes all pass through as before (_coding_for).

  • Mislabeled plain bodies: a plain body labeled gzip or zstd now reaches the route as sent with the header dropped. LLM routes accepted these before, so nothing that worked now fails.

  • max_request_size_mb: a quoted value such as "10" crashed before at "10" &lt;= 0 in _mb_to_bytes with a TypeError. It now parses. A non-numeric value such as "10MB" also raised before.

  • Dependency: backports-zstd is a new dependency for Python below 3.14. Without it, only zstd-magic bodies get 415.

No ! marker is needed.

  • Passed · Changed behavior and result consistency (required): Traced the request through middleware registration in proxy_server.py. RequestBodyDecompressionMiddleware is added first, so it is innermost: inside CORS, SecurityHeaders, in-flight tracking, RequestSizeLimitMiddleware and AdmissionControl. The path continues through _coding_for, _receive_prefix, the magic-number check, _receive_body (wire cap), _max_decoded_length with budget reservation, then _decode in a thread. _identity_scope drops the encoding and length headers and sets content-length, and _replay_body feeds the downstream body readers: auth, _read_request_body, and pass-through request.body().

Boundary cases checked against code and tests:

  • empty body
  • signature split across chunks
  • operator limit of None, 0, lower or higher than the cap
  • skippable zstd frame
  • truncated gzip, trailing data and an understated gzip ISIZE
  • ratio exactly at and above the limit
  • the budget's first-reservation rule (reserved_bytes == 0)
  • client disconnect during the prefix and body reads
  • premium and non-premium getters for both size middlewares and check_if_request_size_is_safe

Proxy-level tests show auth reads the decoded model: a zstd or gzip body naming a model outside the key gets 403, and the upstream mock is never called.

Standards: the new code adds no source comments, uses Final and X | None, and its tests sit in tests/unit.

  • Passed · Targeted unit and proxy tests (optional): .venv/bin/python -m pytest -n 4 tests/unit/proxy/middleware/test_request_body_decompression_middleware.py tests/unit/proxy/auth/test_auth_utils.py tests/unit/proxy/decisions_endpoints/test_endpoints.py tests/unit/proxy/middleware gave 1077 passed in 44s. The run includes the decompression-bomb memory test, with peak memory under 100 MiB for a 200 MiB bomb.

View review · Reviewed c7060ca45def

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@greptile-apps

greptile-apps Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The changes since the previous review appear safe to merge

Summary

The PR adds gzip and zstd request decoding before auth, with size, expansion, and in-flight memory limits

Since the previous review, only test-case labels changed. All test inputs and checks remain intact. The three earlier unnumbered findings remain fixed

  • Compressed request bodies reach proxy routes as decoded JSON.
  • Request-size checks read the same parsed setting.

Reviews (9) · Last reviewed commit: "test(proxy): name the decompression test..." · Reviewed by Greptile

Comment thread litellm/proxy/proxy_server.py Resolved
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

Comment thread litellm/proxy/proxy_server.py Resolved
@veria-ai

veria-ai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

All previously flagged issues have been addressed. No open security concerns remain on this pull request.

Security review

No open security issues remain on this pull request.

Fixed/addressed: 1 · PR risk: 0/10

Limit the decoded size by an expansion ratio and the operator's max_request_size_mb, pass bodies without the coding's magic number through, answer 415 when zstd is unavailable, and register the middleware innermost so errors carry CORS and security headers
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

…in bodies as sent

Each worker holds at most MAX_DECOMPRESSED_REQUEST_BODIES_IN_FLIGHT_MB of
decoded bodies and answers 503 past it. /plugin-proxy/ bodies reach the
plugin as sent, a zstd skippable frame counts as zstd, the decoded-size 413
names the decoded limit, and an integer max_request_size_mb stays an integer
in the 413 text.
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

…nd body-less request messages in the decompression middleware
@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@litereview code-review

@mateo-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit c7060ca. Configure here.

@mateo-berri

mateo-berri commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor Author

codecov/patch first showed 81% before every shard's coverage arrived, and it reads 99% now that the late upload finished

@mateo-berri
mateo-berri merged commit e34c779 into main Oct 20, 2026
113 of 114 checks passed
@mateo-berri
mateo-berri deleted the litellm_decode_gzip_zstd_request_bodies branch October 20, 2026 05:11
@tavren27 tavren27 mentioned this pull request Oct 28, 2026
4 of 6 tasks
@mateo-berri

Copy link
Copy Markdown
Contributor Author

Post-merge audit is in #48766. Its ten real-proxy cases pass at this merge commit, and the eight regression cases fail at its parent

mateo-berri added a commit that referenced this pull request Oct 28, 2026
* test(proxy): audit #47418

* test(proxy): hold the stream open past its first chunk and require cost headers in the audit cells

---------

Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk:low Small, isolated, low-risk change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants