Skip to content

[Fixes] Aiohttp transport fixes - add handling for aiohttp.ClientPayloadError and ssl_verification settings - #11162

Merged
ishaan-jaff merged 9 commits into
mainfrom
litellm_fixes_for_transport_encoding
May 27, 2025
Merged

[Fixes] Aiohttp transport fixes - add handling for aiohttp.ClientPayloadError and ssl_verification settings#11162
ishaan-jaff merged 9 commits into
mainfrom
litellm_fixes_for_transport_encoding

Conversation

@ishaan-jaff

@ishaan-jaff ishaan-jaff commented May 26, 2025

Copy link
Copy Markdown
Contributor

[Fixes] Aiohttp transport fixes

  • Use Aiohttp as default transport
  • Add explicit handling for aiohttp.ClientPayloadError
  • Ensure ssl_verify settings are respected by aiohttp

This PR enhances the Aiohttp transport by adding explicit handling for aiohttp.ClientPayloadError, ensures ssl_verify

Relevant issues

Pre-Submission checklist

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

  • I have Added testing in the tests/litellm/ directory, Adding at least 1 test is a hard requirement - see details
  • I have added a screenshot of my new test passing locally
  • My PR passes all unit tests on make test-unit
  • My PR's scope is as isolated as possible, it only solves 1 specific problem

Type

🆕 New Feature
✅ Test

Changes

@vercel

vercel Bot commented May 26, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
litellm ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 27, 2025 4:13am

Copilot AI 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.

Pull Request Overview

This PR enhances the Aiohttp transport by adding explicit handling for aiohttp.ClientPayloadError, ensures ssl_verify defaults to True when unset, and standardizes date formats in a backup JSON.

  • Gracefully continue streaming on incomplete payload errors in AiohttpResponseStream.
  • Default ssl_verify to True in transport builders and update test expectations.
  • Normalize deprecation_date to YYYY-MM-DD form in the backup JSON.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 6 comments.

File Description
tests/local_testing/test_ollama.py Added assertions and debug prints to verify SSL settings in the new Aiohttp transport
litellm/model_prices_and_context_window_backup.json Updated deprecation_date entries to zero-padded YYYY-MM-DD format
litellm/llms/custom_httpx/http_handler.py Set ssl_verify=True when None and streamline verify_ssl assignment
litellm/llms/custom_httpx/aiohttp_transport.py Expanded AIOHTTP_EXC_MAP, added handling for ClientPayloadError, and removed external import

Comment on lines +278 to +289
print("type of transport in client=", type(client.client._transport))
print("vars in transport in client=", vars(client.client._transport))
litellm_created_session = client.client._transport._get_valid_client_session()
print("litellm_created_session=", litellm_created_session)
# check session ssl
print("litellm_created_session ssl=", litellm_created_session.connector._ssl)


# create aiohttp transport with ssl_verify=False
import aiohttp
aiohttp_session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False))
print("aiohttp_session ssl=", aiohttp_session.connector._ssl)

Copilot AI May 27, 2025

Copy link

Choose a reason for hiding this comment

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

[nitpick] Remove or replace debug print statements in tests; use assertions directly or a logger if needed to avoid noisy output in CI.

Suggested change
print("type of transport in client=", type(client.client._transport))
print("vars in transport in client=", vars(client.client._transport))
litellm_created_session = client.client._transport._get_valid_client_session()
print("litellm_created_session=", litellm_created_session)
# check session ssl
print("litellm_created_session ssl=", litellm_created_session.connector._ssl)
# create aiohttp transport with ssl_verify=False
import aiohttp
aiohttp_session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False))
print("aiohttp_session ssl=", aiohttp_session.connector._ssl)
assert isinstance(client.client._transport, object), "Transport type is not as expected"
assert vars(client.client._transport), "Transport variables are missing or empty"
litellm_created_session = client.client._transport._get_valid_client_session()
assert litellm_created_session is not None, "litellm_created_session is None"
# check session ssl
assert litellm_created_session.connector._ssl is False, "SSL verification is not disabled in litellm_created_session"
# create aiohttp transport with ssl_verify=False
import aiohttp
aiohttp_session = aiohttp.ClientSession(connector=aiohttp.TCPConnector(verify_ssl=False))
assert aiohttp_session.connector._ssl is False, "SSL verification is not disabled in aiohttp_session"

Copilot uses AI. Check for mistakes.
from litellm._logging import verbose_logger

AIOHTTP_EXC_MAP = {
AIOHTTP_EXC_MAP: Dict = {

Copilot AI May 27, 2025

Copy link

Choose a reason for hiding this comment

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

Annotate the exception map with concrete types, e.g., Dict[Type[Exception], Type[Exception]], to improve readability and static analysis.

Suggested change
AIOHTTP_EXC_MAP: Dict = {
AIOHTTP_EXC_MAP: Dict[Type[BaseException], Type[BaseException]] = {

Copilot uses AI. Check for mistakes.
# Network related exceptions
aiohttp.ClientConnectorError: httpx.ConnectError,
aiohttp.ClientOSError: httpx.ConnectError,
aiohttp.ClientConnectorError: httpx.ConnectError,

Copilot AI May 27, 2025

Copy link

Choose a reason for hiding this comment

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

This key is duplicated in AIOHTTP_EXC_MAP; remove one occurrence to avoid confusion and ensure a single mapping per exception.

Suggested change
aiohttp.ClientConnectorError: httpx.ConnectError,

Copilot uses AI. Check for mistakes.
aiohttp.ConnectionTimeoutError: httpx.ConnectTimeout,
aiohttp.SocketTimeoutError: httpx.ReadTimeout,
# Proxy related exceptions
aiohttp.ClientProxyConnectionError: httpx.ProxyError,

Copilot AI May 27, 2025

Copy link

Choose a reason for hiding this comment

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

Duplicate mapping for ClientProxyConnectionError found; consolidate into one entry.

Copilot uses AI. Check for mistakes.
aiohttp.ServerDisconnectedError: httpx.ReadError,
# Response related exceptions
aiohttp.ClientConnectionError: httpx.NetworkError,
aiohttp.ClientPayloadError: httpx.ReadError,

Copilot AI May 27, 2025

Copy link

Choose a reason for hiding this comment

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

The ClientPayloadError mapping appears twice; deduplicate this entry to keep the map clear and unambiguous.

Suggested change
aiohttp.ClientPayloadError: httpx.ReadError,

Copilot uses AI. Check for mistakes.
Comment thread litellm/__init__.py
@ishaan-jaff ishaan-jaff changed the title [Fixes] Aiohttp transport fixes - add handling for aiohttp.ClientPayloadError [Fixes] Aiohttp transport fixes - add handling for aiohttp.ClientPayloadError and ssl_verification settings May 27, 2025
@ishaan-jaff
ishaan-jaff merged commit 4d2edc4 into main May 27, 2025
@ishaan-berri
ishaan-berri deleted the litellm_fixes_for_transport_encoding branch March 26, 2026 21:53
fzowl pushed a commit to fzowl/litellm that referenced this pull request Jun 24, 2026
…loadError` and ssl_verification settings (BerriAI#11162)

* fix: AiohttpResponseStream transport

* fix: use AiohttpResponseStream transport by default

* fix: AiohttpResponseStream transport

* fixes: mapping aiohttp exceptions

* fixes: aiohttp rollout

* fixes: add support ssl_verify for aiohttp

* fixes: add support ssl_verify for aiohttp

* fixes: remove duplicates
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants