Skip to content

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]

fix: aiohttp handle transfer encoding errors gracefully

Ishaan Jaff3b930f67366d
diff --git a/litellm/llms/custom_httpx/aiohttp_transport.py b/litellm/llms/custom_httpx/aiohttp_transport.py
index ca408651e64..81dab9f674b 100644
--- a/litellm/llms/custom_httpx/aiohttp_transport.py
+++ b/litellm/llms/custom_httpx/aiohttp_transport.py
@@ -5,6 +5,7 @@ from typing import Callable, Dict, Union
import aiohttp
import aiohttp.client_exceptions
+import aiohttp.http_exceptions
import httpx
from aiohttp.client import ClientResponse, ClientSession
@@ -81,13 +82,20 @@ class AiohttpResponseStream(httpx.AsyncByteStream):
self.CHUNK_SIZE
):
yield chunk
- except aiohttp.ClientPayloadError as e:
+ except (
+ aiohttp.ClientPayloadError,
+ aiohttp.client_exceptions.ClientPayloadError,
+ ) as e:
# Handle incomplete transfers more gracefully
# Log the error but don't re-raise if we've already yielded some data
verbose_logger.debug(f"Transfer incomplete, but continuing: {e}")
# If the error is due to incomplete transfer encoding, we can still
# return what we've received so far, similar to how httpx handles it
return
+ except aiohttp.http_exceptions.TransferEncodingError as e:
+ # Handle transfer encoding errors gracefully
+ verbose_logger.debug(f"Transfer encoding error, but continuing: {e}")
+ return
except Exception:
# For other exceptions, use the normal mapping
with map_aiohttp_exceptions():
@@ -203,7 +211,6 @@ class LiteLLMAiohttpTransport(AiohttpTransport):
data=data,
allow_redirects=False,
auto_decompress=False,
- compress=False,
timeout=ClientTimeout(
sock_connect=timeout.get("connect"),
sock_read=timeout.get("read"),