mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-25 22:20:43 +00:00
* fix(http_handler): stop advertising zstd so streamed responses survive per-event frames httpx builds one zstd decompressor per response and reuses it across chunk boundaries, so an upstream that compresses each streamed event as its own zstd frame dies on the second event with "cannot use a decompressobj multiple times". httpx offers zstd whenever the optional zstandard package is importable, which is any install that also carries langchain, langsmith or httpx[zstd], so litellm now pins Accept-Encoding to the encodings that survive chunked reads on both the sync and async handlers, disable_default_headers included. * fix(http_handler): guard the private httpx accept-encoding import Reading ACCEPT_ENCODING straight off httpx._client makes importing litellm fail outright if a future httpx renames it, and the dependency accepts any release under 1.0. Fall back to gzip and deflate, which httpx can always decode Move the streaming regression onto an httpx MockTransport that hands back one zstd frame per event, so tests/test_litellm keeps its mocked-networking rule and the suite drops a listening socket along with its sleeps * fix(http): drop zstd from every litellm-built httpx client httpx reuses one zstd decompressor across a response's chunks, so a stream framed one zstd frame per event dies on the second frame. The accept-encoding narrowing now lives in a shared module and reaches the OpenAI SDK, MCP, Azure and base client factories, not just the two custom_httpx handlers. LITELLM_ACCEPT_ENCODING overrides the header for deployments that want zstd back. * fix(openai): route the SDK-built clients through litellm's http client The text completion, files, batches, assistants, fine-tuning and image variation handlers passed litellm.client_session straight to the OpenAI SDK, which is None unless the caller sets it, so the SDK built its own httpx client with httpx's own Accept-Encoding. POST /v1/completions with "stream": true therefore still asked upstreams for zstd and still died on the second event with "cannot use a decompressobj multiple times". Same for Azure through the Cloudflare AI Gateway, which also handed a sync client to AsyncAzureOpenAI. Moderation keeps its own client and only gains the header. A blank LITELLM_ACCEPT_ENCODING now leaves the default in place rather than sending an empty header. * fix: send the Accept-Encoding header through the OpenAI and Azure SDK clients The previous commit reached the SDK-built clients by handing them the client litellm builds, which also swapped in litellm's aiohttp transport and its SSL, proxy-mount and timeout settings. That is a much larger change than the header needs, and it took the files, batches and assistants calls off httpx entirely. Pass `default_headers` on the SDK constructors instead. The header is the only thing that changes; every client keeps the transport, SSL settings, proxy mounts and timeouts it had before. Two `http_client` arguments are corrected along the way: the async image variations client and the async Cloudflare AI Gateway client were both handed the sync `litellm.client_session`, so a deployment that set one would give an async client a sync transport. The header helpers now return a `Mapping` rather than a fresh dict, which keeps the new call sites off the mutable-structure budget. * fix(image variations): give each SDK client the session that matches it The async image variations path builds its client params and hands them to `AsyncOpenAI`, and the sync path hands its own to `OpenAI`, but the two param blocks sit in the opposite order from the calls that consume them. The previous commit read them in source order and put `aclient_session` on the sync one, so a deployment that sets either session got a `TypeError: Invalid http_client argument` on every image variation. Each block now carries the session its SDK class accepts. The async path also stops getting the sync session, which it had since before this branch. The new test drives both entry points against a loopback upstream with both sessions set, and fails on either wiring being crossed. --------- Co-authored-by: mateo-berri <277851410+mateo-berri@users.noreply.github.com> |
||
|---|---|---|
| .. | ||
| __init__.py | ||
| test_accept_encoding.py | ||
| test_aiohttp_cleanup_closed.py | ||
| test_aiohttp_handler.py | ||
| test_aiohttp_so_keepalive.py | ||
| test_aiohttp_transport.py | ||
| test_asgi_handler.py | ||
| test_async_client_cleanup.py | ||
| test_container_handler.py | ||
| test_credential_leak_prevention.py | ||
| test_gemini_session_leak.py | ||
| test_http2_connection_spread.py | ||
| test_http_handler.py | ||
| test_llm_http_handler.py | ||
| test_mock_transport.py | ||
| test_sse_lines.py | ||