Does anyone know of a repeatable, official, retry logic for the Gemini API? I see 100s of code “cookbook” examples, scant return codes listed in the official API docs, but no robust examples of how to handle the various codes that are returned (429,503, etc.).
This seems to work for 429 responses, but not for 503 responses:
from google.generativeai.types import RequestOptions
from google.api_core import retry
...
response = model.generate_content(user_message,
request_options=RequestOptions(
retry=retry.Retry(
initial=10,
multiplier=2,
maximum=60,
timeout=300
)
)
)