Environment
google-genai version: 1.64.0
- Python: 3.13.2
Description
The SDK's async request path (_async_request_once) switches to aiohttp at runtime when the
package is installed. This means any auth or transport customisation applied to the internal
_httpx_client (e.g. _httpx_client._auth = my_auth) is silently ignored for all await/
ainvoke calls.
There is no public API to supply a custom aiohttp session or per-request headers for the async
path, making it impossible to inject auth credentials (e.g. a rotating Bearer token) for async
usage without monkey-patching an internal method.
Current workaround
original = api_client._async_request_once
async def _patched(http_request, stream=False):
http_request.headers["Authorization"] = f"Bearer {get_token()}"
return await original(http_request, stream=stream)
api_client._async_request_once = _patched
Expected behavior
The SDK should provide a supported hook for injecting per-request headers (or a custom async
session/transport) that works consistently regardless of whether the underlying async backend is
httpx or aiohttp. For example: an async_http_options.headers dict or an auth callback
parameter on Client.init that is applied on every async request.
Environment
google-genaiversion: 1.64.0Description
The SDK's async request path (
_async_request_once) switches toaiohttpat runtime when thepackage is installed. This means any auth or transport customisation applied to the internal
_httpx_client(e.g._httpx_client._auth = my_auth) is silently ignored for allawait/ainvokecalls.There is no public API to supply a custom aiohttp session or per-request headers for the async
path, making it impossible to inject auth credentials (e.g. a rotating Bearer token) for async
usage without monkey-patching an internal method.
Current workaround
Expected behavior
The SDK should provide a supported hook for injecting per-request headers (or a custom async
session/transport) that works consistently regardless of whether the underlying async backend is
httpx or aiohttp. For example: an async_http_options.headers dict or an auth callback
parameter on Client.init that is applied on every async request.