counr
Stop one user from burning your AI bill.
Give every user a hard usage limit. One API call checks and consumes their allowance before you call the model.
Free plan: 10,000 requests a month, 60 a minute.
No card required for the free plan.
The problem
If your app calls an LLM API, you pay for every call, whoever made it. One user with a script, a retry loop or a very long prompt can spend a month of budget in an afternoon, and you find out when the invoice arrives. What you need is a limit per user, enforced before the model call.
How it works
1. Define a metric and a limit
In the dashboard, create a metric such as
ai_tokensand set a default limit, for example 100,000 per month. Until a limit is set, a metric is unlimited.2. Call check-consume before the model call
Send the user's ID as the
subjectand your estimated cost. Use an opaque ID from your own system, not an email address or IP address. It checks and consumes in one atomic step.3. If denied, show an upgrade or wait message
A denial is a normal response (HTTP 200,
allowed: false), not an error. Skip the model call and tell the user.
TypeScript, countr-sdk 0.2.0
import { CountrClient } from "countr-sdk";
const countr = new CountrClient({
apiKey: process.env.COUNTR_API_KEY!,
failOpen: true, // default is false
timeoutMs: 2000, // default is 2000
});
const MAX_OUTPUT_TOKENS = 1000;
export async function answer(userId: string, prompt: string) {
// The cost is an ESTIMATE made before the model runs: a rough input size
// plus your output cap. It is consumed now and is not refunded afterwards,
// even if the real call uses less or fails.
const estimatedTokens = Math.ceil(prompt.length / 4) + MAX_OUTPUT_TOKENS;
const result = await countr.checkConsume({
subject: userId, // your opaque user ID, not an email or IP
metric: "ai_tokens",
cost: estimatedTokens, // positive integer
});
if (!result.allowed) {
return { error: "Usage limit reached. Upgrade or try again later." };
}
if (result.failedOpen) {
// Countr was unreachable: allowed by policy, not by a real check.
console.warn("countr fail-open");
}
return callYourModel(prompt, { maxTokens: MAX_OUTPUT_TOKENS });
}check-consume runs before the model, so the cost is an estimate (for example tokens or cents, as integers). Countr never sees the real usage, and the estimate is not refunded or corrected afterwards. With failOpen: true your app stays up if Countr is unreachable, but those requests are not limited. It is off by default. Failure behaviour.
Not using JavaScript? The same call over HTTP
Request
curl https://api.countr.dev/v1/check-consume \
-H "Authorization: Bearer ck_test_xxx" \
-H "Content-Type: application/json" \
-d '{"subject":"user_123","metric":"ai_tokens","cost":1500}'Response when the user is over their limit
{
"allowed": false,
"remaining": 1200,
"reason": "limit_exceeded"
}Denied when remaining is less than cost, so a denial can still show a positive remaining.
What you can limit
Anything you can count as a positive integer, per user, per day, per month or for their lifetime. Days and months are UTC calendar periods and reset on their own.
- Tokens: estimated input plus output tokens per call
- Requests: cost 1 per call
- Dollars as cents: an estimated cost in whole cents
- Images: cost 1 per image generated
- Seats or projects: a lifetime limit; usage only counts up
- Anything else: if you can count it as a positive integer
Set a default per metric, then give a specific user a higher or lower limit with an override. Counters only go up: there is no API to give units back.
Why not build it yourself?
You can. Redis and a Lua script will do the core of it. What counr saves you is everything around that script:
- Atomic check and consume, so concurrent requests cannot both take the last units
- Daily, monthly and lifetime windows that reset without cron jobs
- Idempotency keys, so a retry does not count twice
- API key management, plus a dashboard for limits, per-user overrides and usage
- Fail-open handling and a timeout in the SDK
The trade-off: it is one more network call on your request path, and a hosted dependency, running in US East.
Pricing
- Free $0/mo10,000 requests/mo
- Starter $5/mo100,000 requests/mo
- Growth $19/mo500,000 requests/mo
- Scale $49/mo1,000,000 requests/mo
A request is one authenticated API call, allowed or denied. There are no overages: requests are denied once the monthly allowance is reached. Full pricing.