Skip to content

fix: honor system proxy env vars for Anthropic online requests - #725

Merged
madiator merged 1 commit into
bespokelabsai:mainfrom
EpicSRN021:fix/anthropic-proxy-699
Jul 13, 2026
Merged

madiator merged 1 commit into
bespokelabsai:mainfrom
EpicSRN021:fix/anthropic-proxy-699

Conversation

@EpicSRN021

Copy link
Copy Markdown
Contributor

Summary

Fixes #699 — Anthropic client fails to use system proxy.

Curator's online (non-batch) request path doesn't actually call the anthropic SDK client — AnthropicOnlineRequestProcessor.call_single_request posts directly to the Anthropic REST endpoint using the shared aiohttp.ClientSession created in BaseOnlineRequestProcessor.aiohttp_connector. That session was constructed without trust_env=True.

Unlike requests/httpx, aiohttp.ClientSession does not read HTTP_PROXY/HTTPS_PROXY/ALL_PROXY/NO_PROXY env vars unless trust_env=True is explicitly passed. Without it, aiohttp always connects directly, bypassing any configured system/corporate proxy — exactly what's reported in #699.

This PR sets trust_env=True on that shared session. Since aiohttp_connector is used by all online request processors (not just Anthropic), this also fixes the same class of bug for other providers that go through the same path.

Why not just bump the anthropic dependency (as proposed in #698)?

#698 proposed both trust_env=True and bumping anthropic to >=0.54.0. I checked current main and the dependency is already on ^0.84.0, well past 0.54.0, so that half is already moot. It also wouldn't have fixed this bug on its own: the online path never calls the anthropic SDK client, so an SDK version bump has no effect here. The batch path (anthropic_batch_request_processor.py) does use the real AsyncAnthropic/httpx-based client, which defaults trust_env=True already, so it was never actually affected by this bug.

Verification

Added a unit test (tests/unittests/test_base_online_request_processor.py) asserting the session returned by aiohttp_connector has trust_env=True. Confirmed it fails on main and passes with this change.

I also verified the fix end-to-end with a local fake proxy: pointed HTTPS_PROXY at a local TCP listener and made a request to api.anthropic.com through an aiohttp.ClientSession.

  • Before the fix (trust_env=False): request went straight to the real API, completely bypassing the local proxy.
  • After the fix (trust_env=True): the local proxy received CONNECT api.anthropic.com:443 HTTP/1.1 — aiohttp correctly tunneled through the configured proxy.

Test plan

  • pytest tests/unittests/test_base_online_request_processor.py passes with the fix, fails without it
  • Ran full tests/unittests/ suite — no regressions (pre-existing failures needing live network/API-key access are unrelated to this change and present identically on main)
  • Manually verified proxying behavior with a local fake-proxy script (see description above)

…kelabsai#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.
@madiator madiator assigned madiator and unassigned madiator Jul 12, 2026
@madiator
madiator self-requested a review July 12, 2026 23:03
@madiator
madiator merged commit b346fdf into bespokelabsai:main Jul 13, 2026
1 check failed
@madiator madiator mentioned this pull request Jul 13, 2026
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.

bug: Anthropic client fails to use system proxy

2 participants