From c00728f3750eac55f531d22143eba166d7d4026b Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Mon, 23 Mar 2026 13:05:27 +0000 Subject: [PATCH] Fix Gemini LLM AssertionError: force httpx transport over aiohttp google-genai SDK uses aiohttp when it's available in the environment (installed via llama-index-core), causing AssertionError (connector is None) on async requests. Pass httpx_async_client in HttpOptions to bypass aiohttp. Co-Authored-By: Claude Sonnet 4.6 --- backend/app/services/llm_service.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/app/services/llm_service.py b/backend/app/services/llm_service.py index c72df529..98a67224 100755 --- a/backend/app/services/llm_service.py +++ b/backend/app/services/llm_service.py @@ -36,8 +36,17 @@ def get_gemini_client(): Creating a new client per call avoids event loop mismatch issues that occur when caching clients in ASGI environments where requests may come on different event loops. The overhead is minimal compared to the LLM API call. + + Force httpx transport to avoid aiohttp AssertionError (connector is None) + that occurs when aiohttp is installed in the environment via other packages. """ - return genai.Client(api_key=GEMINI_API_KEY) + from google.genai import types as genai_types + return genai.Client( + api_key=GEMINI_API_KEY, + http_options=genai_types.HttpOptions( + httpx_async_client=httpx.AsyncClient(timeout=600.0) + ) + ) def get_openai_client():