feat: auto-detect aiohttp transport for async client#739
feat: auto-detect aiohttp transport for async client#739fern-support wants to merge 2 commits intomainfrom
Conversation
When httpx_aiohttp is installed, the async client automatically uses it as the transport layer, providing native async DNS resolution via aiodns instead of httpx's blocking threadpool-based getaddrinfo. This prevents ConnectError failures under high async concurrency. Users opt in with `pip install cohere[aiohttp]` — no code changes needed. Users who want plain httpx can pass `httpx_client=DefaultAsyncHttpxClient()`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
| "Dataset": ".types", | ||
| "DatasetPart": ".types", | ||
| "DefaultAioHttpClient": "._default_clients", | ||
| "DefaultAsyncHttpxClient": "._default_clients", |
There was a problem hiding this comment.
New entries break alphabetical ordering in lookup dict
Low Severity
"DefaultAioHttpClient" and "DefaultAsyncHttpxClient" are inserted between "DatasetPart" and "DatasetType" in the _dynamic_imports dict, splitting the "Dataset*" group and breaking the alphabetical sort convention maintained throughout the file. Alphabetically, "Default" sorts after "Debug" (since 'b' < 'f'), so these entries belong after "DebugV2ChatStreamResponse". The same misordering occurs in __all__, where the entries are placed before the "Debug*" entries instead of after them.


Summary
httpx_aiohttpis installed, the async client automatically uses it as the transport layer, providing native async DNS resolution viaaiodns(c-ares) instead of httpx's blocking threadpool-basedgetaddrinfo. This preventsConnectErrorfailures under high async concurrency.pip install cohere[aiohttp]— no code changes required. Users who want plain httpx can passhttpx_client=DefaultAsyncHttpxClient().DefaultAioHttpClientandDefaultAsyncHttpxClientconvenience classes exported from the top-levelcoherepackage.Changes
pyproject.tomlaiohttpandhttpx_aiohttpas optional deps +[aiohttp]extrasrc/cohere/_default_clients.pyDefaultAioHttpClient,DefaultAsyncHttpxClient,COHERE_DEFAULT_TIMEOUTsrc/cohere/base_client.py_make_default_async_client(), updatedAsyncBaseCohere.__init__src/cohere/__init__.pytests/test_aiohttp_autodetect.pyTest plan
pip install -e .— verifyhttpx_aiohttpis NOT installed, async client uses plainhttpx.AsyncClientpip install -e ".[aiohttp]"— verify async client auto-usesHttpxAiohttpClienthttpx_client=DefaultAsyncHttpxClient()with aiohttp installed — verify plain httpx is usedhttpx_client=DefaultAioHttpClient()without aiohttp installed — verify clearRuntimeErrorpytest tests/test_aiohttp_autodetect.py🤖 Generated with Claude Code
Note
Medium Risk
Changes the default async HTTP transport selection when
httpx_aiohttpis installed, which can subtly affect request behavior and dependency resolution. Most logic is isolated and covered by new unit tests, but it impacts all async client users who install the new extra.Overview
Async client transport auto-detection: the SDK now prefers
httpx_aiohttp.HttpxAiohttpClientforAsyncBaseCoherewhenhttpx_aiohttpis available, falling back to plainhttpx.AsyncClientotherwise (via new_make_default_async_client).New opt-in extra + convenience clients: adds optional deps
aiohttp/httpx_aiohttpbehind a newcohere[aiohttp]extra, and introducesDefaultAioHttpClient(errors with install hint when extra missing) plusDefaultAsyncHttpxClient(applies default timeout/redirect settings), both exported fromcohere.Updates
poetry.lockto reflect the new optional dependency group and refreshed lock metadata, and adds tests validating the autodetect and default-client behaviors.Written by Cursor Bugbot for commit 1b08620. This will update automatically on new commits. Configure here.