How to enforce plan limits without an API gateway
The situation
You sell an API or an MCP tool, and your plans say how much each customer gets: so many calls a month on one plan, more on another. Then a customer's script or AI agent runs past it.
The usual advice is to put an API gateway in front of everything and set quotas there. That works for many teams. It also means adopting a gateway, moving your traffic through it, and learning its configuration. If you don't run one today, that is a lot to take on for one job.
You can enforce plan limits another way: one check inside the handler you already have.
What enforcing a plan limit takes
Whatever you build or buy, five things have to happen:
- Know who is calling. Each customer integration or AI agent needs its own key, tied to one customer and one plan.
- Know what the plan allows. A count of calls for a period, for one tool or for every tool.
- Check before the work runs. The check has to come first, and it has to count the call in the same step. Otherwise two calls at once can both slip under the line.
- Say no clearly. A caller that is over its cap needs a plain reason and a reset time, so an agent can stop retrying.
- Keep a record. You need to show a customer what was allowed, what was denied and why.
A gateway can do most of that, from the edge. Ordainer does it from inside your handler, or from an edge proxy you run yourself: our docs have an example NGINX recipe.
The no gateway way: one call in your handler
At the top of your handler, send the caller's agent key and the tool name to decide(). Ordainer checks that key's plan, answers allow or deny, counts an allowed call in the same step, and writes one audit row. In enforce mode, on a deny, you skip the work and send the caller the reason and the reset time. Your request payloads stay on your servers.
From any language, it's one HTTPS request. This is the call from our docs:
curl -s -X POST https://api.ordainer.dev/v1/decide \
-H "Authorization: Bearer $ORDAINER_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: job-42-step-3" \
-d '{"tool":"research.run"}'On Windows? use the PowerShell tab.
A deny is an answer, not an error. It comes back as HTTP 200 with "decision":"deny", a reason such as quota_exceeded, and the time the allowance resets.
In Node with Express, the SDK does the same thing as middleware (npm install express ordainer). This is the sample from our Node quickstart:
const express = require('express');
const { Ordainer } = require('ordainer');
const ordainer = new Ordainer(); // reads ORDAINER_KEY and ORDAINER_BASE_URL. Fails open on timeouts and outages.
const app = express();
app.post('/tools/research', ordainer.middleware({ tool: 'research.run' }), (req, res) => {
// "ordainer" and "remaining" are only here so you can watch our decision while you try this. Leave them out of real handlers.
res.json({ result: 'expensive research done', ordainer: req.ordainer.decision, remaining: req.ordainer.remaining });
});
app.listen(3001, () => console.log('listening on :3001'));This sample uses one key from the environment so you can see a deny while you try it. In your own service, you look up the key for the customer integration or agent that's calling; the Node quickstart shows how. SDKs are available for Node (1.4.0), Python (0.4.0), Ruby (0.1.3) and Java (0.1.0). For MCP, put the call at the top of each tool handler. There is also a Python sample on the page about capping each API customer's usage.
Roll it out without blocking anyone
Plans you create in the console start in shadow mode. Shadow logs would-deny decisions and does not block: the calls run, and each would-deny shows up in the console. Watch what would have been stopped, fix the plans, then switch a plan to enforce from the Plans page. No deploy is needed. (The two sandbox plans you get at sign-up start in enforce, so you can see a deny in the sandbox.)
What you give up without a gateway
- Traffic protection. Ordainer doesn't proxy your traffic, shape bursts or sit in front of your servers. Keep your own rate limits for spikes. A usage cap is not a rate limiter. See usage caps vs rate limiting.
- A code change. The check lives in your handler, so you add a call to each tool you want to cap. If you would rather gate requests at the edge, our docs have an NGINX example recipe. It is an example to copy and adapt, not a plugin or a product.
- A hosted dependency. The check is a network call to Ordainer. If we can't answer, the SDKs let your tool run by default and log a warning. You can set a client, route or call to block instead. With plain HTTP, your handler decides.
When a gateway is the better fit
If you already run a gateway and its per consumer quotas fit your plans, use them. You don't need a second system for the same job. Ordainer is worth a look when you don't run a gateway, when your plans are per integration or per AI agent rather than per consumer, or when you want an audit row for each decision and a shadow mode before you enforce. For a closer look at Kong and Apigee, see Ordainer vs API gateway quotas.
What to know during the beta
- Ordainer is in beta. During the beta you use test keys. Live keys are not available yet.
- All test keys in your organization share one allowance of allowed test decisions each month: 1,000 on a standard sign-up.
- Ordainer counts calls, not dollars or tokens.
- Each key counts on its own. One cap covering all of a customer's keys together isn't available today.
- It doesn't send usage to a billing system. Your invoices go out as they do today.
Common questions
Do I need to change my architecture?
No new proxy or gateway. You add one call at the top of each handler you want to cap, from an SDK or plain HTTP. Your own rate limits stay where they are.
Does our traffic go through Ordainer?
No. The check sends the agent key, the tool name, an idempotency key (the SDKs generate one if you don't set it) and, if you set it, a mode. Your request payloads stay on your servers.
What happens if Ordainer can't answer?
By default, the Node, Python, Ruby and Java SDKs let your tool run and log a warning. Where an unchecked call is worse, you can set a client, route or call to block instead. With plain HTTP, your handler decides what to do.
Does this work for MCP tools and AI agents?
Yes. In each MCP tool handler, call decide() with the agent key of the client or agent that is calling, and the tool name. Give each agent its own key so a cap can stop one agent without touching the rest.
Can I use this next to a gateway?
Yes. A gateway can keep protecting your servers and routing traffic. Ordainer decides whether one key or agent has allowance left on its plan.
Try it
Ordainer is free during the beta: sign up for test keys with 1,000 decisions a month, no credit card needed.
Get test keys · Produce a deny in the live demo
Enforcing plan limits without a gateway today? We'd like to hear how you do it: support@ordainer.ai.