fix(providers): remove custom cloud httpx client, let SDK handle proxy defaults
chengyongru reviewed #4367 and identified that the cloud branch created a bare httpx.AsyncClient that lacked the SDK's default settings (follow_redirects, connection pool limits). Since the SDK's DefaultAsyncHttpxClient already has trust_env=True and proper defaults, the simplest fix is to let http_client stay None for cloud endpoints. Also updated the test to match the new behavior (http_client is None).
This commit is contained in:
@@ -417,14 +417,9 @@ class OpenAICompatProvider(LLMProvider):
|
||||
timeout=timeout_s,
|
||||
transport=httpx.AsyncHTTPTransport(proxy=None, limits=_local_limits),
|
||||
)
|
||||
else:
|
||||
# Cloud endpoints: respect proxy environment variables
|
||||
# (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY, NO_PROXY) so corporate
|
||||
# or VPN proxies work without explicit configuration.
|
||||
http_client = httpx.AsyncClient(
|
||||
timeout=timeout_s,
|
||||
trust_env=True,
|
||||
)
|
||||
# else: http_client stays None → SDK creates DefaultAsyncHttpxClient
|
||||
# which already reads proxy env vars via trust_env=True, has proper
|
||||
# connection limits, and follows redirects.
|
||||
self._client = AsyncOpenAI(
|
||||
api_key=self._api_key_for_client,
|
||||
base_url=self._effective_base,
|
||||
|
||||
@@ -16,10 +16,10 @@ async def test_openai_compat_provider_defers_sdk_client_until_first_use() -> Non
|
||||
|
||||
kwargs = mock_async_openai.call_args.kwargs
|
||||
_assert_openai_compat_timeout(kwargs["timeout"])
|
||||
# Cloud endpoints get an httpx client with trust_env=True to respect
|
||||
# proxy environment variables (HTTP_PROXY, HTTPS_PROXY, ALL_PROXY).
|
||||
assert kwargs["http_client"] is not None
|
||||
assert kwargs["http_client"]._trust_env is True
|
||||
# Cloud endpoints pass http_client=None so the SDK creates its own
|
||||
# DefaultAsyncHttpxClient, which already handles proxy env vars,
|
||||
# connection limits, and redirects correctly.
|
||||
assert kwargs["http_client"] is None
|
||||
|
||||
|
||||
async def test_openai_compat_provider_sets_timeout_on_local_http_client() -> None:
|
||||
|
||||
Reference in New Issue
Block a user