Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Crazylife's avatar

Too many attempt when call api

I am facing an issue where response keep returning Too Many Attempts. after first call of api.

My kernal.php

    protected $middlewareGroups = [
        'web' => [
            \App\Http\Middleware\EncryptCookies::class,
            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
            \Illuminate\Session\Middleware\StartSession::class,
            // \Illuminate\Session\Middleware\AuthenticateSession::class,
            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
            \App\Http\Middleware\VerifyCsrfToken::class,
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],

        'api' => [
            // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
            'throttle:api',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
    ];

If I am changing throttle:api to throttle:60,1', then it worked. But I didn't change this before, it's a new project.

RouteServiceProvider

    protected function configureRateLimiting()
    {
        RateLimiter::for('api', function (Request $request) {
            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
        });
    }

May i know is that any missed configuration?

0 likes
7 replies
Tray2's avatar

In your code where you call your api you do it more than set times thus getting that response.

You need to limit your number of calls to the api.

Crazylife's avatar

@Tray2 Not really, i am calling just once then it hit this issue. As what i know throttle:api should be same as 'throttle:60,1, right? CMIIW. It worked perfectly, but suddenly became like this.

Sinnbeck's avatar

@Crazylife Can you try giving it your own name?

 protected function configureRateLimiting()
    {
        RateLimiter::for('foobar', function (Request $request) {
            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
        });
    }

'api' => [
            // \Laravel\Sanctum\Http\Middleware\EnsureFrontendRequestsAreStateful::class,
            'throttle:foobar',
            \Illuminate\Routing\Middleware\SubstituteBindings::class,
        ],
Crazylife's avatar

My bad, accidentally removed the configuration function in boot() in router service provider. Solved.

Please or to participate in this conversation.