Skip to content

feat: add HTTP retry support#789

Open
xiantank wants to merge 2 commits into
googleapis:mainfrom
xiantank:feat-http-retry-options
Open

feat: add HTTP retry support#789
xiantank wants to merge 2 commits into
googleapis:mainfrom
xiantank:feat-http-retry-options

Conversation

@xiantank

Copy link
Copy Markdown

Fixes #713.

The Python SDK exposes HttpRetryOptions for opt-in HTTP retries; the Go SDK currently has none. This adds the equivalent HTTPRetryOptions on HTTPOptions, mirroring the Python implementation.

Behavior:

  • Maximum attempts (default: 5, including the initial request)
  • Exponential backoff with jitter (defaults: 1s initial, 60s max, base 2, up to 1s jitter)
  • Retriable HTTP status codes (defaults: 408, 429, 500, 502, 503, 504), plus transport-layer net.Errors
  • Defaults follow https://cloud.google.com/storage/docs/retry-strategy

HTTPOptions.RetryOptions defaults to nil, so existing behavior is unchanged. Both client-level and per-request overrides are supported.

Add HTTPRetryOptions to HTTPOptions so callers can configure automatic
retries on transient failures (network errors and retriable HTTP status
codes). Mirrors the Python SDK's HttpRetryOptions behavior, with the
same defaults (5 attempts, exponential backoff 1s -> 60s, jitter 1s,
retriable codes 408/429/500/502/503/504).

Retry is opt-in: HTTPOptions.RetryOptions defaults to nil which keeps
existing behavior unchanged. Both client-level and per-request override
are supported via patchHTTPOptions.
@Sivasankaran25 Sivasankaran25 self-assigned this May 15, 2026
@Sivasankaran25 Sivasankaran25 added the api:gemini-api Issues related to Gemini API label May 15, 2026
Previously the cap was applied before adding jitter, so the effective
maximum delay was MaxDelay + Jitter (e.g. 61s with the defaults). Apply
the cap after jitter so the configured MaxDelay is the actual upper
bound, matching the Python SDK's HttpRetryOptions semantics
(tenacity.wait_exponential_jitter).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api:gemini-api Issues related to Gemini API

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for retrying 429 in the http client

2 participants