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

adityar15's avatar

Counting Sanctum API usage

I have a SaaS which is served using APIs created with Laravel Sanctum. I want to keep track of API usage count as there will be monthly subscription plans based on each having limit on the API usage. For eg: Plan 1 -> costs $10 -> 1000 requests per day Plan 2 -> costs $20 -> 2500 requests per day and so on.

What is the best approach to do this?

0 likes
2 replies
Nakov's avatar

I would create a middleware and group the routes which will count into the total of requests with it, and each time a request is made you can increase the count for the specific user and also prevent the call in case the limit has been reached so you can redirect them to a payment / upgrade of plan page.

https://laravel.com/docs/8.x/middleware

2 likes
adityar15's avatar

I see. I was thinking along the same lines. Thanks for the answer, I will give it a try.

Please or to participate in this conversation.