httpx.PoolTimeout, fixed by disabling HTTP keepalive
This is a deeply odd error, insofar as it's something that happens 100% of the time only when my code is invoking Anthropic (via client libraries 0.28.0) from our CI environment (hosted in AWS us-east-2).
We get a anthropic.APITimeoutError: Request timed out, thrown from a httpx.PoolTimeout, thrown from a httpcore.PoolTimeout during a generally unremarkable test case. The following change in usage/invocation prevents it entirely:
- async_client = AsyncAnthropic()
+ http_client = httpx.AsyncClient(
+ limits=httpx.Limits(max_connections=None, max_keepalive_connections=0)
+ )
+ async_client = AsyncAnthropic(http_client=http_client)
What version of httpx are you using?
If you're not on the latest I would strongly recommend upgrading, there were some issues with older versions of httpx not closing connections properly.
Indeed, this was observed when behind a few releases (httpx 0.25.2) -- I'll retest on 0.27.0 and see if that resolves the issue.
Unfortunately, the issue still reproduces with httpx 0.27.0.
Ah! Updating httpx alone didn't solve the problem.
I had a dependency pinning anyio, which prevented httpcore from being updated. Updating that pin to permit a modern anyio permits newer httpcore to be pulled in, and that resolves the problem.
Perhaps anthropic-sdk-python should explicitly specify appropriate minimum versions of both?
Glad this problem was fixed for you! We don't want to pin when we can avoid it, as it can cause worse problems for people in some situations.