Skip to content

Per-key usage caps for APIs and agents

Ordainer puts your plan in front of each tool call. Before your handler does any work, it asks one question, POST /v1/decide: may this caller make this call? We check the caller’s agent key against the plan it’s bound to, answer allow or deny, and count it in the same step. Every answer writes one audit row. Each agent key has its own usage cap, so you can stop an agent burning a customer’s API allowance without cutting off that customer’s other keys. Cap usage for an MCP server per client or per agent the same way: call POST /v1/decide from the tool handler with that caller’s key.

Sign up with your work email, copy the pilot test key, and run one paste: six calls, and the sixth answers deny. It uses a free test key, needs no install, and shows the deny in a few minutes. The docs have examples in curl, PowerShell, Node.js, Python, Ruby and Java.

The Node SDK’s middleware asks before your handler runs. On a deny, your handler doesn’t run: a used-up plan answers your caller 429 (or 402, if you choose), and a tool the plan doesn’t cover answers 403. Install it with npm install ordainer; the Node / Express quickstart below walks through it.

On Rails, the Ruby gem’s guard does the same. In Python, check with client.decide() before your tool runs (package 0.4.0, from PyPI).

Keep the gateway you already run. Ordainer Cap isn’t in front of your traffic, so nothing is rerouted. Your handler makes the decide() call. If you’d rather check at the edge, the docs have an example NGINX recipe that you run yourself. It isn’t an Ordainer product.

Plans you add in the console start in shadow mode, where plan and test-limit denies are logged as would-deny and the call still runs. The two sandbox plans you get at sign-up start in enforce. When the would-denies look right, switch the plan to enforce in the console, with no deploy unless your code pins mode. The one rule for your code: run the tool if decision is allow or mode is shadow.

A deny is an answer, not an error: allow and every deny come back as HTTP 200, so check decision, not the status code. Send an idempotency key, so a retry gets the original answer and isn’t counted twice. Errors are non-200 responses with one shape; branch on error.code, and quote the X-Request-Id when you write to us.