Api
Laravel 8
Laravel 9
Laravel 10
Laravel 11
Laravel 12
429 Too Many Requests in Laravel - Rate Limiting Fix
This error occurs when a client exceeds the rate limit configured for API routes or specific endpoints.
The Error
Error Message
429 Too Many Requests / Rate limit exceeded
Common Causes
- 1 Too many requests in short time period
- 2 Rate limiter configured too strictly
- 3 Bot or script making excessive requests
- 4 Shared IP affecting multiple users
- 5 Forgot to configure rate limiter for high-traffic endpoints
Solutions
1
Configure rate limiting in RouteServiceProvider
PHP
// In App\Providers\RouteServiceProvider
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Support\Facades\RateLimiter;
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by(
$request->user()?->id ?: $request->ip()
);
});
}
2
Create custom rate limiters
PHP
// Different limits for different endpoints
RateLimiter::for('uploads', function (Request $request) {
return Limit::perMinute(10)->by($request->user()->id);
});
RateLimiter::for('search', function (Request $request) {
return Limit::perMinute(30)->by($request->ip());
});
// Apply to routes
Route::middleware(['throttle:uploads'])->post('/upload', ...);
Route::middleware(['throttle:search'])->get('/search', ...);
3
Handle rate limit in frontend
JavaScript
axios.get('/api/data')
.catch(error => {
if (error.response.status === 429) {
const retryAfter = error.response.headers['retry-after'];
console.log(`Rate limited. Retry after ${retryAfter} seconds`);
// Show user-friendly message
}
});
4
Disable rate limiting for testing
PHP
// In routes/api.php temporarily
Route::withoutMiddleware('throttle:api')
->get('/test', function () {
return 'No rate limit';
});
Need Help With Your Laravel Project?
I specialize in building custom Laravel applications, process automation, and SaaS development. Whether you need to eliminate repetitive tasks or build something from scratch, let's discuss your project.
About Hafiz
Senior Full Stack Developer. I build production software with Laravel, Filament, Vue, and AI integrations, and write about the real decisions behind shipping it.
Get in touch →