-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Description
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
When using the OpenAI Python SDK with the SyncClient in scenarios involving multiple sequential or concurrent API calls, the client occasionally raises a httpx.PoolTimeout error. This occurs because the default connection pool size in httpx is too small for certain workloads, and the SDK does not currently expose or document ways to adjust it for the SyncClient.
The issue becomes more frequent in:
High-throughput scripts making multiple API calls in a loop.
Multi-threaded or multi-process environments.
Long-running applications where connections are not released quickly enough.
This behavior causes unexpected failures even when network connectivity is stable.
To Reproduce
from openai import OpenAI
import time
client = OpenAI() # Uses default SyncClient under the hood
for i in range(50): # simulate multiple API calls
try:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": f"Request number {i}"}]
)
print(f"Response {i}:", response.choices[0].message["content"])
except Exception as e:
print(f"Error on request {i}:", e)
time.sleep(0.1) # minimal delay
Code snippets
OS
macos
Python version
python v3 11.4
Library version
openai v1.0.1