feat(openai): add optional aiohttp backend support for improved concurrency #33084
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Introduction
The OpenAI Python SDK now supports an optional aiohttp backend that removes concurrency limits seen with HTTPX. This PR exposes an opt-in path in LangChain's OpenAI integration to allow
http_client=DefaultAioHttpClient()
or an environment variable toggle.Based on this issue
What changed
http_client
andhttp_async_client
parameters to supportDefaultAioHttpClient
LC_OPENAI_USE_AIOHTTP
environment variable for convenient opt-inopenai[aiohttp]
is not installedWhy
Improve throughput for parallel chains, graphs, and agents without breaking existing users. The default HTTPX async client in OpenAI has concurrency limitations that can be removed by using the aiohttp backend.
How to enable
Option 1: Install and set environment variable
Option 2: Pass explicit client
pip install "openai[aiohttp]"
Backwards compatibility
✅ No breaking changes - this is an optional parameter only
✅ Existing behavior preserved - default httpx clients still used by default
✅ Graceful degradation - warns and falls back if aiohttp not available
✅ Proper precedence - explicit client parameters override environment variables
Testing
References
Code Quality Checklist
make lint
andmake format
passReady for review 🚀