Skip to content

fix: validate http_client type in AsyncAPIClient#3110

Open
EaCognitive wants to merge 2 commits intoopenai:mainfrom
EaCognitive:fix-async-proxy-typeerror
Open

fix: validate http_client type in AsyncAPIClient#3110
EaCognitive wants to merge 2 commits intoopenai:mainfrom
EaCognitive:fix-async-proxy-typeerror

Conversation

@EaCognitive
Copy link
Copy Markdown

Fixes #1095

Problem

When a user passes a synchronous httpx.Client to AsyncOpenAI via the http_client parameter, the library crashes during a request with a cryptic TypeError: object Response can't be used in 'await' expression. This happens because the SDK expects an asynchronous client and tries to await the result of .send(), which in a sync client returns a Response object instead of a coroutine.

Solution

Added a type validation check in AsyncAPIClient.__init__. If an http_client is provided, we now explicitly verify that it is an instance of httpx.AsyncClient. If not, we raise a clear TypeError during initialization.

Changes

  • src/openai/_base_client.py: Added isinstance check for http_client in AsyncAPIClient.__init__.

Verification

  • Verified that passing a sync client now raises a helpful TypeError instead of crashing later with a cryptic one.

@EaCognitive EaCognitive requested a review from a team as a code owner April 21, 2026 20:16
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.

When using openai asynchronous request, an error occurs when defining the proxy with http_client

1 participant