Update: The actual error is the fact that low timeouts return a confusing generic error (500).
Expected behavior: Setting the timeout via HttpOptions as illustrated in the docs should be working, eg, HttpOptions(timeout=1000).
Actual behavior: If I set a timeout (see example below), I get an immediate API response: Error: 500 INTERNAL. {'error': {'code': 500, 'message': 'An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting', 'status': 'INTERNAL'}}
Environment details
- Programming language: Python
- OS: MacOS Sequoia 15.6
- Language runtime version: 3.13
- Package version: 1.32
Steps to reproduce
- Run the below script and you'll get
Error: 500 INTERNAL. {'error': {'code': 500, 'message': 'An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting', 'status': 'INTERNAL'}}
IF you comment out the line setting timeout in the client, it all works.
MRE
#!/usr/bin/env python3
"""
Minimal script to test Google GenAI direct client calls with timeout.
"""
import asyncio
import os
from google.genai import Client
from google.genai.types import HttpOptions
from dotenv import load_dotenv
load_dotenv()
async def main():
# Get API key from environment
api_key = os.getenv("GEMINI_API_KEY")
if not api_key:
print("Error: GEMINI_API_KEY environment variable not set")
return
# Create client with timeout
client = Client(
api_key=api_key,
http_options=HttpOptions(timeout=20.0*100), # 2 seconds timeout
)
try:
# Use the aio client for async operations
response = await client.aio.models.generate_content(
model="gemini-2.5-flash",
contents="Write a 50 words long, detailed haiku about a rainy day in London. Include vivid imagery and emotions.",
)
# Extract text from response
print(f"Response: {response.text}")
except Exception as e:
print(f"Error: {e}")
print(f"Error type: {type(e)}")
if __name__ == "__main__":
asyncio.run(main())
Thank you for any advice on how to avoid this :)
Update: The actual error is the fact that low timeouts return a confusing generic error (500).
Expected behavior: Setting the timeout via
HttpOptionsas illustrated in the docs should be working, eg,HttpOptions(timeout=1000).Actual behavior: If I set a timeout (see example below), I get an immediate API response:
Error: 500 INTERNAL. {'error': {'code': 500, 'message': 'An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting', 'status': 'INTERNAL'}}Environment details
Steps to reproduce
Error: 500 INTERNAL. {'error': {'code': 500, 'message': 'An internal error has occurred. Please retry or report in https://developers.generativeai.google/guide/troubleshooting', 'status': 'INTERNAL'}}IF you comment out the line setting
timeoutin the client, it all works.MRE
Thank you for any advice on how to avoid this :)