AnswersAI usage

How to rate-limit AI usage per user

Use credits to cap AI usage per person. Each AI tool has a credit price, each person holds a balance, and a call is refused when they cannot cover it, so a credit budget is your rate limit. You choose which plans and products can use each tool. A built-in cap of 20 AI calls per person per minute stops bursts, and app-wide safe limits stop abuse across the whole app.

01 / CREDITS

Cap usage with credits

Price each AI tool in credits, and every call spends from the person's balance. When the balance runs out, the next call is refused until they top up. You build and store no per-person counter. Gemmein keeps the per-minute count itself (section 04).

The person'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."
A per-call tool spends its price before the call. A per-token tool reserves a credit ceiling before the call and settles at the end. Either way, a person cannot start work they cannot pay for. If the provider fails before its first byte, the call is refunded. A call that fails after the first byte is charged: the full price on a per-call tool, the credit ceiling on a per-token tool.
02 / BUDGETS

Give each person a budget

Top people up each subscription period, sell packs for pay-as-you-go, or grant credits by hand. Mixing them gives each paid tier its own budget, with packs for more.

Credits by hand

Grant credits to one person from the dashboard or through a relay, for a trial or a goodwill top-up. Their spending stays capped at what you grant.

Paid tiers

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

03 / WHO CAN CALL

Limit which people can run a tool

Credits limit how much a person can run. Access limits which tools they can run. Require access on a tool, and only people who have it can run the tool, whatever their balance. That keeps an expensive model behind a paid plan while a cheaper one stays open to everyone.

A person without access sees a clear message, for example "Deep Research requires Pro Max."
04 / ABUSE LIMITS

Built-in abuse limits

Separately from your pricing, each person can make up to 20 AI calls a minute. The next call is refused with 429 ai_capped and a resetAt time. App-wide safe limits sit above that. They scale with the app's active people, are never billed, and start high enough that a small app is never refused. You don't configure any of them.

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

Prompt for your coding agent

Paste this into Cursor, Claude, Bolt or Lovable so your agent caps usage with credits and writes no counters of its own.

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 person's balance, grant each person a per-plan credit budget, require access on an expensive tool, and read the person's balance. Explain how the built-in safe limits handle abuse.

Add Gemmein to your AI. Then tell it what you want.

Building is free. No card until you go live.