diff --git a/google/genai/_api_client.py b/google/genai/_api_client.py index bb9865cc4..a8bddbecd 100644 --- a/google/genai/_api_client.py +++ b/google/genai/_api_client.py @@ -2101,7 +2101,9 @@ async def aclose(self) -> None: """Closes the API async client.""" # Let users close the custom client explicitly by themselves. Otherwise, # close the client when the object is garbage collected. - if not self._http_options.httpx_async_client: + if not self._http_options.httpx_async_client and getattr( + self, '_async_httpx_client', None + ): await self._async_httpx_client.aclose() # type: ignore[union-attr] if self._aiohttp_session and not self._http_options.aiohttp_client: await self._aiohttp_session.close()