googleapis / googleapis/python-genai

Retry logic should respect server-provided retryDelay from 429 responses

Open
#1,875 6 comments 2 reactions 1 assignee Claimed by @Venkaiahbabuneelam View on GitHub
priority: p3 type: feature request
Dominant language
Python
Stars
4k
Forks
1k
Avg merge
2d 11h
Merged PRs (30d)
40

Description

When a `429 RESOURCE_EXHAUSTED` error is returned, the API response includes a suggested retry delay in `google.rpc.RetryInfo`:

```json
{
"error": {
"code": 429,
"message": "You exceeded your current quota... Please retry in 53.016342224s.",
"status": "RESOURCE_EXHAUSTED",
"details": [
{
"@type": "type.googleapis.com/google.rpc.RetryInfo",
"retryDelay": "53s"
}
]
}
}
```

The SDK ignores this value and uses fixed exponential backoff (~1s, ~2s, ~4s, ~8s, ~17s), wasting all 5 retry attempts in ~33 seconds when the server explicitly says to wait ~53 seconds.

**Proposed solution**

The SDK should parse `retryDelay` from `google.rpc.RetryInfo` in 429 responses and use that value (with optional jitter) instead of fixed exponential backoff. When no `retryDelay` is provided, fall back to exponential backoff.

[Source code](https://github.com/googleapis/python-genai/blob/main/google/genai/_api_client.py#L482-L486)
[Downstream issue](github.com/langchain-ai/langchain-google/issues/945)
[Forum discussion](https://discuss.ai.google.dev/t/429-errors-despite-waiting-after-retrydelay/96899)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.