Skip to content

fix: respect Gemini API RetryInfo delay on 429 responses#1041

Draft
anyasabo wants to merge 1 commit into
datalab-to:masterfrom
anyasabo:fix/gemini-retry-delay
Draft

fix: respect Gemini API RetryInfo delay on 429 responses#1041
anyasabo wants to merge 1 commit into
datalab-to:masterfrom
anyasabo:fix/gemini-retry-delay

Conversation

@anyasabo

@anyasabo anyasabo commented Jun 2, 2026

Copy link
Copy Markdown

While using this on the gemini free tier, I was hitting the tier rate limits. I saw the api was replying with info about when to retry, but we were ignoring it. This PR uses the retry info if it's available, so we can play nicer with the rate limits.

Somewhat frustratingly, there is a lingering PR that has yet to be reviewed that implements this upstream. But in the meantime we can do it here.

clanker generated below


Summary

  • Parse retryDelay from google.rpc.RetryInfo in 429 error responses and use it as the retry sleep duration
  • Falls back to the existing linear backoff (tries * retry_wait_time) when the field is absent or malformed
  • Handles both response shapes ({'error': {'details': [...]}} and flat {'details': [...]})

This avoids burning through all retries with fixed backoff when the API tells you exactly how long to wait — particularly useful on the free tier where per-minute rate limits are tight.

Ref: googleapis/python-genai#2114 (same fix at the SDK transport layer, not yet merged)
Fixes: #490

@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

Parse retryDelay from the google.rpc.RetryInfo error details and use it
as the sleep duration before retrying. Falls back to the existing linear
backoff (tries * retry_wait_time) when the field is absent or malformed.

Ref: googleapis/python-genai#2114
Ref: datalab-to#490
@anyasabo anyasabo force-pushed the fix/gemini-retry-delay branch from ca78a54 to b8a9bf7 Compare June 6, 2026 21:18
@anyasabo

anyasabo commented Jun 6, 2026

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gemini API exhausted, need some pause mechanism or something

1 participant