From 9ecabafa2b4c10c2690ed4be4f0ccf9ebf830f2f Mon Sep 17 00:00:00 2001 From: Vadym Samoilenko Date: Mon, 2 Mar 2026 12:52:25 +0000 Subject: [PATCH] =?UTF-8?q?Fix=20Gemini=20http=5Foptions=20timeout=20unit:?= =?UTF-8?q?=20seconds=20=E2=86=92=20milliseconds?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit google-genai SDK expects http_options 'timeout' in milliseconds. Passing 45 (seconds) was interpreted as 45ms → ~1s deadline, which Google API rejected with 400 INVALID_ARGUMENT 'Manually set deadline 1s is too short. Minimum allowed deadline is 10s.' Primary: 45_000ms (45s), Fallback: 150_000ms (150s) Co-Authored-By: Claude Sonnet 4.6 --- backend/app/services/gemini_service.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/backend/app/services/gemini_service.py b/backend/app/services/gemini_service.py index 4401541..d15c659 100755 --- a/backend/app/services/gemini_service.py +++ b/backend/app/services/gemini_service.py @@ -11,11 +11,10 @@ from app.models.schemas import SubReview, RagStatus # Configure logging logger = logging.getLogger(__name__) -# Timeout (seconds) for each Gemini API call. -# Set at the HTTP client level so the network connection is actually closed -# on timeout — asyncio.wait_for alone cannot cancel SDK-internal retries. -_PRIMARY_TIMEOUT = 45 -_FALLBACK_TIMEOUT = 150 +# Timeout for each Gemini API call. +# google-genai http_options 'timeout' is in MILLISECONDS. +_PRIMARY_TIMEOUT_MS = 45_000 # 45 seconds +_FALLBACK_TIMEOUT_MS = 150_000 # 150 seconds class GeminiService: @@ -30,13 +29,14 @@ class GeminiService: """ # Two separate clients with different HTTP-level timeouts so the # network connection is torn down when the deadline is reached. + # Note: google-genai http_options 'timeout' is in milliseconds. self.primary_client = genai.Client( api_key=api_key, - http_options={"timeout": _PRIMARY_TIMEOUT}, + http_options={"timeout": _PRIMARY_TIMEOUT_MS}, ) self.fallback_client = genai.Client( api_key=api_key, - http_options={"timeout": _FALLBACK_TIMEOUT}, + http_options={"timeout": _FALLBACK_TIMEOUT_MS}, ) self.model = "gemini-3.1-pro-preview" self.fallback_model = "gemini-3-flash-preview"