General
One API Unlimited Quota Token Abuse: How to Find It Before Your Balance Drains
Table of contents
Step 1: enumerate every token with unlimited quotaStep 2: check whether those tokens are actually being usedStep 3: separate "expensive model on a cheap plan" from "unlimited"Step 4: reconcile the balance, not the dashboardStep 5: close the doors without breaking tenantsThe 503 trap that follows a config changeWhat a healthy gateway looks likeSelf-hosted LLM gateways — One API, New API, and their forks — are usually deployed for one reason: to put a single billing surface in front of many models and many users.
That design puts a quota field between your balance and everyone else. When a token's quota is set to
This is the practical audit: find the doors, prove whether anyone walked through, and close them without locking out the tenants who are supposed to have generous limits.
Why
In One API-style schemas, token quota is an integer where
- A provisioning script that writes
- A dashboard that shows remaining quota as a percentage will render
Combine that with the usual multi-tenant reality — one gateway, several products, a handful of internal scripts, and a few "test" tokens that were never deleted — and the blast radius is whoever finds the key.
Read-only, and safe to run against production:
Two columns matter and they are not the same thing.
Then sort the result by owner. An unlimited token owned by an admin account that half the team shares is a different risk from one owned by a customer who paid for a large plan.
An unlimited token with zero traffic is a latent bug. An unlimited token with heavy traffic is an incident.
The usage logs give you the truth:
Now cross-reference against the unlimited list. Anything in both sets deserves a name and an owner before the end of the day.
Three patterns are worth naming explicitly:
- The forgotten test token. Created during integration, still valid, quota
- The oversold plan. A customer on a "fair use" tier was given an unlimited token because the gateway had no better lever. Their legitimate usage looks like abuse in the logs.
- The leaked key. Volume spikes at odd hours, from a single ASN, with prompts unrelated to the product. This is the one that costs real money.
Unlimited quota is only half the exposure. The other half is model access: a token that can call your most expensive upstream model while paying for the cheapest tier.
The check is a join, not a guess:
If a token on the entry-level plan is spending most of its budget on a frontier model, either your pricing is wrong or your model allowlist is missing. Both are revenue problems.
Gateway dashboards show *aggregate* quota consumption. They do not show whether your upstream provider's invoice agrees.
The reconciliation is a three-way comparison:
| Source | What it tells you |
|---|---|
| Gateway
| Upstream provider invoice | What you actually paid |
| Payment records / order table | What customers actually paid you |
A gap between the first two means your price table or token accounting is off. A gap between the last two means someone is consuming without a matching order — which is exactly what an unlimited token produces.
Run this monthly. It is the only audit that catches abuse that looks like normal traffic.
Deleting unlimited tokens during business hours is how you take down a paying customer's integration at 2pm.
Safer sequence:
Snapshot first. Dump the token table before touching it. You will want the old values when someone asks why their script stopped. Convert, do not delete. Replace Rotate the leaked ones. For anything with unexplained traffic, disable the token rather than adjusting it, then issue a new key through the normal channel. Make
After the change, watch two numbers for 48 hours: 429 rates per token (did you cap someone who legitimately needed headroom?) and spend per token (did the leak stop?).
One more discipline, because it turns a quota fix into an outage: gateways cache a channel-to-model routing table (
Before any channel change:
After the change, refresh it through the admin UI's channel update (which regenerates the table), then verify with one real request per model. If routing is broken, restore the snapshot rather than debugging live.
The end state is boring, which is the point:
- Every token has a finite quota or a documented, owned exception.
- Every unlimited exception has a name, a reason, and a review date.
- Model allowlists match plan tiers.
- Monthly reconciliation closes to within a known tolerance.
- The
None of this requires new infrastructure. It requires reading four tables with intent, once a quarter — and treating
---
*Running a gateway and want the text side handled too? The free [Lint tools](https://tools.aicreditsapi.com/tools/) cover grammar, paraphrase, and code explanation without a subscription. For stable API access, see [AiCredits](https://aicreditsapi.com).*
That design puts a quota field between your balance and everyone else. When a token's quota is set to
-1, the field means unlimited. Somebody has to remember that. Nobody does.This is the practical audit: find the doors, prove whether anyone walked through, and close them without locking out the tenants who are supposed to have generous limits.
Why -1 is the most expensive number in the config
In One API-style schemas, token quota is an integer where
-1 means *unlimited* and 0 means *exhausted*. Two consequences follow immediately:- A provisioning script that writes
-1 "temporarily" leaves a permanent door. There is no expiry on intent.- A dashboard that shows remaining quota as a percentage will render
-1 as something like -1% or ∞ — either way, it does not look like an alarm.Combine that with the usual multi-tenant reality — one gateway, several products, a handful of internal scripts, and a few "test" tokens that were never deleted — and the blast radius is whoever finds the key.
Step 1: enumerate every token with unlimited quota
Read-only, and safe to run against production:
-- Tokens that can spend without a cap
SELECT id, name, user_id, quota, unlimited_quota, status, created_time
FROM tokens
WHERE quota = -1 OR unlimited_quota = 1
ORDER BY created_time;Two columns matter and they are not the same thing.
quota = -1 is the value; unlimited_quota is the flag the UI may or may not set alongside it. If your fork only uses one of them, check which — reading the schema beats guessing:SHOW COLUMNS FROM tokens LIKE '%quota%';Then sort the result by owner. An unlimited token owned by an admin account that half the team shares is a different risk from one owned by a customer who paid for a large plan.
Step 2: check whether those tokens are actually being used
An unlimited token with zero traffic is a latent bug. An unlimited token with heavy traffic is an incident.
The usage logs give you the truth:
-- Request volume and spend, per token, last 7 days
SELECT token_id, COUNT(*) AS requests,
SUM(prompt_tokens + completion_tokens) AS tokens_used
FROM logs
WHERE created_at > UNIX_TIMESTAMP() - 7 * 86400
GROUP BY token_id
ORDER BY tokens_used DESC
LIMIT 50;Now cross-reference against the unlimited list. Anything in both sets deserves a name and an owner before the end of the day.
Three patterns are worth naming explicitly:
- The forgotten test token. Created during integration, still valid, quota
-1, occasionally used by an old script. Low volume, high embarrassment.- The oversold plan. A customer on a "fair use" tier was given an unlimited token because the gateway had no better lever. Their legitimate usage looks like abuse in the logs.
- The leaked key. Volume spikes at odd hours, from a single ASN, with prompts unrelated to the product. This is the one that costs real money.
Step 3: separate "expensive model on a cheap plan" from "unlimited"
Unlimited quota is only half the exposure. The other half is model access: a token that can call your most expensive upstream model while paying for the cheapest tier.
The check is a join, not a guess:
-- Per token: which models, and what did they cost
SELECT l.token_id, l.model_name, COUNT(*) AS calls, SUM(l.quota) AS spent
FROM logs l
WHERE l.created_at > UNIX_TIMESTAMP() - 30 * 86400
GROUP BY l.token_id, l.model_name
ORDER BY spent DESC
LIMIT 100;If a token on the entry-level plan is spending most of its budget on a frontier model, either your pricing is wrong or your model allowlist is missing. Both are revenue problems.
Step 4: reconcile the balance, not the dashboard
Gateway dashboards show *aggregate* quota consumption. They do not show whether your upstream provider's invoice agrees.
The reconciliation is a three-way comparison:
| Source | What it tells you |
|---|---|
| Gateway
logs.quota sum | What you think you sold || Upstream provider invoice | What you actually paid |
| Payment records / order table | What customers actually paid you |
A gap between the first two means your price table or token accounting is off. A gap between the last two means someone is consuming without a matching order — which is exactly what an unlimited token produces.
Run this monthly. It is the only audit that catches abuse that looks like normal traffic.
Step 5: close the doors without breaking tenants
Deleting unlimited tokens during business hours is how you take down a paying customer's integration at 2pm.
Safer sequence:
-1 with a large finite quota (for example, the customer's monthly contract in gateway units). Behaviour is identical until the cap, and the cap now exists.-1 unreachable going forward. If your provisioning code can write unlimited, it will. Add a check at the admin API level, not in the docs.After the change, watch two numbers for 48 hours: 429 rates per token (did you cap someone who legitimately needed headroom?) and spend per token (did the leak stop?).
The 503 trap that follows a config change
One more discipline, because it turns a quota fix into an outage: gateways cache a channel-to-model routing table (
abilities). Editing channels without refreshing that table can leave the gateway routing to a model that no longer exists — every request 503s, and the config looks correct.Before any channel change:
-- Snapshot the routing table
SELECT * FROM abilities ORDER BY model, channel_id;After the change, refresh it through the admin UI's channel update (which regenerates the table), then verify with one real request per model. If routing is broken, restore the snapshot rather than debugging live.
What a healthy gateway looks like
The end state is boring, which is the point:
- Every token has a finite quota or a documented, owned exception.
- Every unlimited exception has a name, a reason, and a review date.
- Model allowlists match plan tiers.
- Monthly reconciliation closes to within a known tolerance.
- The
abilities table is snapshotted before every channel change.None of this requires new infrastructure. It requires reading four tables with intent, once a quarter — and treating
-1 as a decision instead of a default.---
*Running a gateway and want the text side handled too? The free [Lint tools](https://tools.aicreditsapi.com/tools/) cover grammar, paraphrase, and code explanation without a subscription. For stable API access, see [AiCredits](https://aicreditsapi.com).*
📌 Prices and tool count in this article may be outdated. Lint now ships 16 tools with Pro at $12/mo, or $60/year. See the current pricing page.
Stop letting Grammarly break your code
16 AI tools built for developers. Code-aware parsing.
Or upgrade to Pro for 500 checks a day · All tools · No ads