From c2fb49c42dd92fa35cf418b3a2ebb310e70bff38 Mon Sep 17 00:00:00 2001 From: Erick Aleman Date: Tue, 21 Apr 2026 16:15:55 -0400 Subject: [PATCH 1/2] fix: validate http_client type in AsyncAPIClient to prevent cryptic TypeError --- src/openai/_base_client.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/openai/_base_client.py b/src/openai/_base_client.py index a1d0960700..b72564c2a7 100644 --- a/src/openai/_base_client.py +++ b/src/openai/_base_client.py @@ -1498,6 +1498,12 @@ def __init__( custom_headers=custom_headers, _strict_response_validation=_strict_response_validation, ) + if http_client is not None and not isinstance(http_client, httpx.AsyncClient): + raise TypeError( + f"Expected http_client to be an instance of httpx.AsyncClient, but got {type(http_client)} instead. " + "If you are using AsyncOpenAI, you must pass an asynchronous HTTP client." + ) + self._client = http_client or AsyncHttpxClientWrapper( base_url=base_url, # cast to a valid type because mypy doesn't understand our type narrowing From 39419148418ba1c342bc7552500cd5ade7d81ced Mon Sep 17 00:00:00 2001 From: Erick Aleman Date: Tue, 21 Apr 2026 17:41:40 -0400 Subject: [PATCH 2/2] fix: address pyright warning for unnecessary isinstance check --- src/openai/_base_client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/openai/_base_client.py b/src/openai/_base_client.py index b72564c2a7..072081c32d 100644 --- a/src/openai/_base_client.py +++ b/src/openai/_base_client.py @@ -1498,7 +1498,7 @@ def __init__( custom_headers=custom_headers, _strict_response_validation=_strict_response_validation, ) - if http_client is not None and not isinstance(http_client, httpx.AsyncClient): + if http_client is not None and not isinstance(cast(Any, http_client), httpx.AsyncClient): raise TypeError( f"Expected http_client to be an instance of httpx.AsyncClient, but got {type(http_client)} instead. " "If you are using AsyncOpenAI, you must pass an asynchronous HTTP client."