Skip to content

Add automatic retry with exponential backoff for 429 responses#326

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/add-retry-support-429-responses
Draft

Add automatic retry with exponential backoff for 429 responses#326
Copilot wants to merge 2 commits intomainfrom
copilot/add-retry-support-429-responses

Conversation

Copy link

Copilot AI commented Feb 24, 2026

Large-scale Twilio API usage frequently encounters 429 rate-limit responses. The Go SDK had no retry mechanism, requiring callers to implement their own backoff logic.

Changes

  • Client.MaxRetries int — new opt-in field (default 0 = disabled, backward compatible); set to a positive value to enable automatic retries on 429
  • retryAfterDuration — computes the wait before each retry: honours the Retry-After response header (numeric seconds and HTTP-date/RFC 7231 formats), falling back to exponential backoff (500 ms → 1 s → 2 s … capped at 64 s)
  • doWithErr — retries the request up to MaxRetries times when the server returns HTTP 429, resetting the request body via GetBody between attempts
  • SendRequest — sets req.GetBody on POST/PUT/PATCH and JSON requests so the body can be replayed on retry

Usage

client := twilio.NewRestClientWithParams(twilio.ClientParams{
    Username: accountSid,
    Password: authToken,
})
client.SetMaxRetries(3) // retry up to 3 times on 429

Or directly:

client.Client.MaxRetries = 3
Original prompt

This section details on the original issue you should resolve

<issue_title>Add automatic retry support for 429 responses</issue_title>
<issue_description>### Issue Summary

When working in large production environments, it is quite easy to run into scenarios where the Twilio API returns a 429 due to rate limiting. The Node SDK added support for automatic retry with exponential backoff in twilio/twilio-node#886. It would be great if the Go SDK could add similar functionality.
</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Co-authored-by: manisha1997 <28821901+manisha1997@users.noreply.github.com>
Copilot AI changed the title [WIP] Add automatic retry support for 429 responses Add automatic retry with exponential backoff for 429 responses Feb 24, 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.

Add automatic retry support for 429 responses

2 participants