AI usage & credits

How to rate-limit AI usage per user

The cleanest per-user cap is credits. Each AI tool has a credit price, each customer holds a balance, and a call is refused when they cannot cover it. So a per-user credit budget is your rate limit. Access gates decide who can call at all, and built-in safe limits stop abuse across the whole app.

01 / CREDITS ARE THE LIMIT

A user can only run what they hold.

Instead of counting requests per minute, cap the resource itself. Price each AI tool in credits, and every call spends that many from the caller's balance. When the balance runs out, the next call is refused until they top up. There is no per-user counter for you to build or store: the balance is the limit.

The caller's balance, in the browserJavaScript
const { balance, reserved, expiring } = await g.credits.balance();
// A tool call is refused when the balance cannot cover its price:
// "Deep Research costs 20 credits. You have 7."
Because the price is reserved before the call and settled at the end, a user cannot start work they cannot pay for, and a failed provider call refunds rather than draining the budget.
02 / GIVE EACH USER A BUDGET

Per plan, per pack, or per cycle.

A per-user limit is just how many credits that user holds. Grant a starting balance on sign-up, top users up on a subscription cycle, or sell packs for pay-as-you-go. Mixing them gives you a free tier with a small monthly budget and paid tiers with more.

Free tier

Grant a small monthly budget so free users can try the AI features without an open tap into your provider bill.

Paid tiers

A subscription tops the user up each cycle; packs add more on demand. Packs never expire, so unused credits carry over unless you design otherwise.

03 / GATE WHO CAN CALL

Some tools, some customers.

Credits cap how much; access gates decide who. Require an entitlement on a tool and only customers who hold it can run it, regardless of balance. That keeps an expensive model behind a paid plan while a cheaper one stays open to everyone.

A person without the entitlement sees a clear message, for example "Deep Research requires Pro Max," rather than a silent failure.
04 / ABUSE LIMITS ARE BUILT IN

Safe limits you never configure.

Separate from your pricing, Gemmein applies safe limits for abuse prevention. They scale with the app's active people, they are never billed, and every app starts with enough headroom that a small app is never refused. You do not set them up; they are there to stop floods, not to shape your product.

Need to meter something that is not an AI call, such as an export or a heavy action? Spend credits from your own server for that action too, on the same balance.
05 / FOR YOUR CODING AGENT

Give your agent the full task.

Building with Cursor, Claude, Bolt, or Lovable? Paste this so your agent caps usage with credits instead of hand-rolling counters.

Prompt for your coding agentCopy and paste

Read https://docs.gemmein.com/llms.txt and https://docs.gemmein.com/ai. I want to rate-limit AI usage per user. Show me how to price an AI tool in credits so each call spends from the caller's balance, grant each user a per-plan credit budget, gate an expensive tool behind an entitlement, and read the caller's balance. Explain how the built-in safe limits handle abuse.

06 / FAQ

Frequently asked questions.

How do I stop one user burning my whole provider budget?

Price the AI tool in credits and give each user a fixed balance. A call is refused when the caller cannot cover its price, so no single user can spend past the credits they hold.

Can I reset the limit each month?

Yes. Grant credits on a plan or a pack. A subscription can top a user up each cycle, and packs never expire, so unused credits carry over unless you design otherwise.

What about abusive bursts of traffic?

Gemmein has built-in safe limits for abuse prevention. They scale with the app's active people, are never billed, and every app starts with enough headroom that a small app is never refused.

Can I meter something that is not an AI call?

Yes. Spend credits from your own server for any action you want to meter, not just AI tool calls.

07 / RELATED

Related.

How to charge credits for AI features · Store your OpenAI key server-side · AI tools on the product page · AI docs

See if Gemmein fits your app.

Point your coding agent at docs.gemmein.com/llms.txt and ask it to confirm the fit before it builds.

Read the builder guide