Skip to content

Commit f0985a8

Browse files
committed
fix: honor system proxy env vars for Anthropic online requests (#699)
aiohttp.ClientSession ignores HTTP_PROXY/HTTPS_PROXY/ALL_PROXY unless trust_env=True is set explicitly, unlike requests/httpx. Since the shared online request path posts directly via aiohttp rather than the anthropic SDK client, proxy env vars were silently ignored, causing timeouts or direct connections in proxied environments. Sets trust_env=True on the shared aiohttp session used by all online request processors, and adds a regression test asserting the session created by aiohttp_connector trusts the environment.
1 parent 6d5e247 commit f0985a8

2 files changed

Lines changed: 23 additions & 1 deletion

File tree

‎src/bespokelabs/curator/request_processor/online/base_online_request_processor.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ def free_capacity(self, tracker, tokens):
315315
def aiohttp_connector(self, tcp_limit: int) -> aiohttp.ClientSession:
316316
"""Create an aiohttp connector with rate limiting."""
317317
connector = aiohttp.TCPConnector(limit=10 * tcp_limit)
318-
return aiohttp.ClientSession(connector=connector)
318+
# trust_env=True makes aiohttp honor HTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXY,
319+
# which it otherwise ignores unlike requests/httpx (see issue #699).
320+
return aiohttp.ClientSession(connector=connector, trust_env=True)
319321

320322
async def process_requests_from_file(
321323
self,
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import pytest
2+
3+
from bespokelabs.curator.request_processor.online.anthropic_online_request_processor import AnthropicOnlineRequestProcessor
4+
5+
6+
@pytest.mark.asyncio
7+
async def test_aiohttp_connector_trusts_env_proxy():
8+
"""Ensure the shared aiohttp session honors HTTP(S)_PROXY/ALL_PROXY env vars.
9+
10+
aiohttp.ClientSession ignores proxy environment variables unless trust_env=True
11+
is set explicitly, unlike requests/httpx. Without it, requests (e.g. to the
12+
Anthropic API) silently bypass any configured system proxy. See issue #699.
13+
14+
aiohttp_connector doesn't touch instance state, so we bypass __init__ (which
15+
makes a live network call to fetch header-based rate limits) via object.__new__.
16+
"""
17+
processor = object.__new__(AnthropicOnlineRequestProcessor)
18+
19+
async with processor.aiohttp_connector(tcp_limit=1) as session:
20+
assert session.trust_env is True

0 commit comments

Comments
 (0)