Retry-After & 429 retries
The package paces outgoing requests proactively. To also react to a server’s own signals, use ->adaptive() or combine the middleware with Laravel’s own ->retry() and RateLimits::retryAfter() to honour a 429 Too Many Requests / Retry-After response:
use RoundlyConsulting\HttpClientRateLimits\Facades\RateLimits;
Http::rateLimit(RateLimits::perMinute(60))
->retry(3, throw: false, sleepMilliseconds: fn ($attempt, $exception) =>
(RateLimits::retryAfter($exception) ?? $attempt) * 1000)
->get('https://api.example.com/things');Reading Retry-After yourself
RateLimits::retryAfter() accepts a Response or a RequestException, parses both the delta-seconds and HTTP-date forms of the header (a date in the past gives 0), caps the result at one day (86 400 s), and returns null when it’s absent or unparseable:
use RoundlyConsulting\HttpClientRateLimits\Facades\RateLimits;
$response = Http::get('https://api.example.com/things');
if ($response->status() === 429) {
$seconds = RateLimits::retryAfter($response); // ?int: "120" or an HTTP-date, null when absent
}Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.