Error in using Async client of openai, when I use custom http_client with httpx

I made a this kinda code using openai async client.

DEFAULT_TIMEOUT = httpx.Timeout(timeout=100, connect=100, pool=100)
DEFAULT_LIMITS = httpx.Limits(max_connections=2, max_keepalive_connections=2)

OpenAIHTTPClient = httpx.Client(timeout=DEFAULT_TIMEOUT, limits=DEFAULT_LIMITS)
response = OpenAIHTTPClient.get("https://example.org")
print(response.text)
OPENAI = openai.AsyncOpenAI(api_key=oai_key, http_client=OpenAIHTTPClient)

In case of using custom OpenAIHTTPClient, then it will break, but if i set http_client default, then it works. I need to scale up this, so I think this is necessary for me. Can you help me why it happend?


2024-01-11 20:09:42,817:INFO - HTTP Request: POST https://api.openai.com/v1/threads "HTTP/1.1 200 OK"
2024-01-11 20:09:42,827:INFO - Retrying request to /threads in 0.973660 seconds
2024-01-11 20:09:44,027:INFO - HTTP Request: POST https://api.openai.com/v1/threads "HTTP/1.1 200 OK"
2024-01-11 20:09:44,027:INFO - Retrying request to /threads in 1.647062 seconds
2024-01-11 20:09:45,869:INFO - HTTP Request: POST https://api.openai.com/v1/threads "HTTP/1.1 200 OK"
Traceback (most recent call last):
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1339, in _request
    response = await self._client.send(
               ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object Response can't be used in 'await' expression

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1339, in _request
    response = await self._client.send(
               ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object Response can't be used in 'await' expression

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1339, in _request
    response = await self._client.send(
               ^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: object Response can't be used in 'await' expression

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/client.py", line 28, in <module>
    asyncio.run(main())
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/client.py", line 24, in main
    a = await OPENAI.beta.threads.create()
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/resources/beta/threads/threads.py", line 313, in create
    return await self._post(
           ^^^^^^^^^^^^^^^^^
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1536, in post
    return await self.request(cast_to, opts, stream=stream, stream_cls=stream_cls)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1315, in request
    return await self._request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1358, in _request
    return await self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1418, in _retry_request
    return await self._request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1358, in _request
    return await self._retry_request(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1418, in _retry_request
    return await self._request(
           ^^^^^^^^^^^^^^^^^^^^
  File "/Users/parkgyutae/dev/Pado/ASQ_Dart/dart_assistant/venv/lib/python3.11/site-packages/openai/_base_client.py", line 1367, in _request
    raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.