{"id":3060,"date":"2025-04-18T12:41:10","date_gmt":"2025-04-18T12:41:10","guid":{"rendered":"https:\/\/www.devopssupport.in\/blog\/?p=3060"},"modified":"2025-04-18T12:41:12","modified_gmt":"2025-04-18T12:41:12","slug":"laravel-throttle-middleware-how-to-increase-api-rate-limit-safely-and-for-429-too-many-requests","status":"publish","type":"post","link":"https:\/\/www.devopssupport.in\/blog\/laravel-throttle-middleware-how-to-increase-api-rate-limit-safely-and-for-429-too-many-requests\/","title":{"rendered":"Laravel Throttle Middleware: How to Increase API Rate Limit Safely and for 429 Too Many Requests"},"content":{"rendered":"\n<p>If you&#8217;re working with Laravel APIs, you might have encountered this default throttle setting:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>'api' => &#91;\n    'throttle:60,1',\n    'bindings',\n],\n<\/code><\/pre>\n\n\n\n<p>This line lives in your <code>app\/Http\/Kernel.php<\/code> file and controls how many requests a user can make to your API. In this blog post, we\u2019ll explore <strong>what it means<\/strong>, <strong>why you might want to change it<\/strong>, and <strong>how to safely increase the rate limit<\/strong> for your Laravel application.<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83e\udde0 What Does <code>'throttle:60,1'<\/code> Mean?<\/h2>\n\n\n\n<p>This throttle rule applies a <strong>rate limit<\/strong> to all API requests:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>60<\/code> = number of requests allowed<\/li>\n\n\n\n<li><code>1<\/code> = time in <strong>minutes<\/strong><\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd01 In short:<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>Each user (or IP) can make <strong>60 requests per minute<\/strong> to your API.<\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udeab Why You Might Want to Change It<\/h2>\n\n\n\n<p>You may want to increase the throttle limit if:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Your frontend app sends many background requests.<\/li>\n\n\n\n<li>You&#8217;re integrating with another system (like a mobile app or a microservice).<\/li>\n\n\n\n<li>Users are getting <code>429 Too Many Requests<\/code> errors frequently.<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u2705 How to Increase the Throttle Value<\/h2>\n\n\n\n<p>To change the limit, go to:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>app\/Http\/Kernel.php\n<\/code><\/pre>\n\n\n\n<p>Find this section:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>protected $middlewareGroups = &#91;\n    'api' => &#91;\n        'throttle:60,1',\n        'bindings',\n    ],\n];\n<\/code><\/pre>\n\n\n\n<p>Change it to something like:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>'api' => &#91;\n    'throttle:200,1', \/\/ Allow 200 requests per minute\n    'bindings',\n],\n<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Tip:<\/h3>\n\n\n\n<p>You can adjust this as needed, for example:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>'throttle:100,1'<\/code> \u2192 100 req\/min<\/li>\n\n\n\n<li><code>'throttle:500,5'<\/code> \u2192 500 requests every 5 minutes<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83c\udfaf Apply Custom Throttle to Specific Routes (Optional)<\/h2>\n\n\n\n<p>If you don\u2019t want to increase the throttle globally, you can apply it to <strong>specific routes<\/strong> like this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Route::middleware(&#91;'auth:api', 'throttle:300,1'])->get('\/profile', function () {\n    return response()->json(&#91;'user' => auth()->user()]);\n});\n<\/code><\/pre>\n\n\n\n<p>Or create a group:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Route::middleware(&#91;'auth:api', 'throttle:500,5'])->group(function () {\n    Route::get('\/orders', 'OrderController@index');\n    Route::get('\/products', 'ProductController@index');\n});\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Bonus: Create Named Custom Throttle<\/h2>\n\n\n\n<p>In <code>RouteServiceProvider.php<\/code>:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>use Illuminate\\Cache\\RateLimiting\\Limit;\nuse Illuminate\\Support\\Facades\\RateLimiter;\n\npublic function boot()\n{\n    RateLimiter::for('custom-api', function ($request) {\n        return Limit::perMinute(300)->by($request->ip());\n    });\n}\n<\/code><\/pre>\n\n\n\n<p>Then in routes:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Route::middleware(&#91;'throttle:custom-api'])->get('\/my-endpoint', 'MyController@method');\n<\/code><\/pre>\n\n\n\n<p>Laravel makes it easy to control your API traffic using the throttle middleware. If you&#8217;re experiencing issues like <code>429 Too Many Requests<\/code>, just increasing the limit in <code>Kernel.php<\/code> or applying custom route-level throttling can solve your problem efficiently.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;re working with Laravel APIs, you might have encountered this default throttle setting: This line lives in your app\/Http\/Kernel.php file and controls how many requests a&#8230; <\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3060","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3060","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/comments?post=3060"}],"version-history":[{"count":2,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3060\/revisions"}],"predecessor-version":[{"id":3062,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/posts\/3060\/revisions\/3062"}],"wp:attachment":[{"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/media?parent=3060"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/categories?post=3060"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.devopssupport.in\/blog\/wp-json\/wp\/v2\/tags?post=3060"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}