Repository navigation
🐛 Fix proxy caching between requests in aiohttp transport - #17122
Merged
Merged
Conversation
|
@lcfyi is attempting to deploy a commit to the CLERKIEAI Team on Vercel. A member of the Team first needs to authorize it. |
Contributor
|
@AlexsanderHamir please take a look when possible |
lcfyi
force-pushed
the
lcfyi/fix-caching-between-calls
branch
from
November 27, 2025 19:57
6ab2b76 to
e96ed00
Compare
Contributor
Author
|
I rebased on main, looks like CI is running and not dying on lockfile issues anymore. |
AlexsanderHamir
approved these changes
Nov 29, 2025
Contributor
|
I benchmarked the behavior before and after this PR, and found no performance regressions. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Title
Fix proxy caching between requests in aiohttp transport
Relevant issues
Couldn't find one at a glance, this may have just been an edge case we encountered and nobody else has.
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unitWill let CI pass for (2) and (3). My change may have hit a linter whammy so there are a fair number of whitespace / formatting changes from ruff.
Type
🐛 Bug Fix
✅ Test
Changes
Background
This PR fixes a bug in the
LiteLLMAiohttpTransportproxy cache when multiple endpoints are sent through the same session. A concrete example of where this can happen is in the/v1/messagesAnthropic adapter, which fetches an anthropic client from the cache here:litellm/litellm/llms/custom_httpx/llm_http_handler.py
Lines 1795 to 1797 in be97073
If we have multiple backends that have mixed proxy settings (e.g.
amazonaws.comandazure.com,NO_PROXY=amazonaws.com HTTP_PROXY=foo.com), we'll get unwanted behaviour depending on when the requests land on the process:amazonaws.comrequest lands first, we'll cache theNO_PROXY, and subsequent requests will not pass in a proxy configuration (there's some extra weird behaviour here because we do pass intrust_envto aiohttp, meaning it'll will actually use theHTTP_PROXYvariable if it's properly formed)azure.comrequest lands first, we'll cache the proxy configuration, and subsequent requests will usefoo.comThe fix
This PR basically makes the proxy cache depend on the request URL rather than caching it once ~forever.
I chose the full URL as the cache key since I don't think there are any request URLs that have constantly rotating query params that'd bust the cache, but correct me if I'm wrong.I ended up caching with the host as key, see the last 2 commits on this PR. I wrote a test to reflect this behaviour.