Fix Gemini http_options timeout unit: seconds → milliseconds
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 <noreply@anthropic.com>
This commit is contained in:
parent
74585c5c18
commit
9ecabafa2b
1 changed files with 7 additions and 7 deletions
|
|
@ -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"
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue