fix: respect Gemini API RetryInfo delay on 429 responses#1041
Draft
anyasabo wants to merge 1 commit into
Draft
Conversation
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
ca78a54 to
b8a9bf7
Compare
Author
|
I have read the CLA Document and I hereby sign the CLA |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
retryDelayfromgoogle.rpc.RetryInfoin 429 error responses and use it as the retry sleep durationtries * retry_wait_time) when the field is absent or malformed{'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