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: 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.pyindex 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, Unionimport aiohttpimport aiohttp.client_exceptions+import aiohttp.http_exceptionsimport httpxfrom 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 dataverbose_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 itreturn+ except aiohttp.http_exceptions.TransferEncodingError as e:+ # Handle transfer encoding errors gracefully+ verbose_logger.debug(f"Transfer encoding error, but continuing: {e}")+ returnexcept Exception:# For other exceptions, use the normal mappingwith 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"),