Skip to content

Instantly share code, notes, and snippets.

@olliefr
Created February 28, 2026 06:59
Show Gist options
  • Select an option

  • Save olliefr/a75bc7178a0485d81f69dd3c814dba46 to your computer and use it in GitHub Desktop.

Select an option

Save olliefr/a75bc7178a0485d81f69dd3c814dba46 to your computer and use it in GitHub Desktop.
Help your ADK agents deal with Gemini error 429

Help your ADK agents deal with Gemini error 429

Your agent.py likely passes a model ID as a string when creating the root_agent:

root_agent = Agent(
    # ...
    model=os.getenv("MODEL"),
    # ...
)

When you pass a string, the Agent constructor creates a model instance with default settings. Those defaults are not very resilient to transient errors such as HTTP 429 (rate limiting).

You can improve resilience by explicitly configuring retry behavior.

This requires two small changes.

1. Add the necessary imports

from google.adk.models import Gemini
from google.genai.types import HttpRetryOptions

2. Instantiate the model with retry settings

Instead of passing the model ID string, create a configured Gemini instance and pass it to Agent:

root_agent = Agent(
    # ...
    model=Gemini(
      model=os.getenv("MODEL"),
      retry_options=HttpRetryOptions(
        initial_delay=2,
        attempts=500,
        max_delay=16,
        jitter=2.0,
      ),
    ),
    # ...
)

The HttpRetryOptions values above are based on observed behavior under specific conditions and may not be optimal for your workload.

  • attempts is set high to keep retrying rather than failing early.
  • Increasing delays did not significantly improve success rates in my case, but results may vary depending on service congestion level and dynamic quota value.

Adjust the parameters according to your experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment