Purrx

Daily quotas per user

Protect your AI bill with a daily deck limit per user: one counter per user per day, checked before generating, and refunded when generation fails through no fault of the user.

10 min+30 XPHands-on

Every deck costs you model calls. Without a limit, a single user refreshing in a loop, or a script, or your own front-end bug, can use your entire API quota by lunchtime, and nobody else gets a deck. A per user keeps usage fair and costs predictable.

user-42:2026-09-15

used 9 of 10

consume()

10 of 10: allowed

generation fails

Gemini overloaded

refund()

back to 9 of 10

One counter per user per day. A request uses one up front; if generation fails because of us or the model, it's given back.

One counter per user per day

The key is the user and today's date: user-42:2026-09-15. Tomorrow the key is different, so the count starts from zero with no reset job to write.

  • consume(userId): if today's count is already at the limit, refuse without changing anything. Otherwise add one, and say how many are left.
  • refund(userId): take one back, never going below zero.

Key takeaways

  • A per-user daily limit stops one person, or one bug, from spending your whole budget.
  • Key the counter by user and date, so tomorrow starts fresh with no cleanup job.
  • If generation fails because of you or the model, give the user their deck back.

Sign in to run the exercise

Reading is free. Writing code here needs an account so we have somewhere to keep your Gemini key and the +30 XP you are about to earn.