Skip to content

You’ll put the Node SDK in front of one paid tool and watch it get blocked, then try shadow mode (record what would be denied, block nothing), which is how you roll out on a real plan. Switching between shadow and enforce is a console click, with no redeploy.

You need Node 20+ and an Express (or Connect-style) service. Any other framework works with ordainer.wrap() (see Next steps).

  1. Get a test key

    Sign up with your work email and copy the pilot test key from the welcome page. If you want a one-paste deny first, use Your first deny. The SDK reads the key from ORDAINER_KEY, so put it there:

    Terminal window
    export ORDAINER_KEY=ord_test_...
    export ORDAINER_BASE_URL=https://api.ordainer.dev

    The console’s .env download names each key after its label (for example ORDAINER_KEY_PILOT). If your file has no ORDAINER_KEY line, copy the value you want into ORDAINER_KEY, or pass it in code: new Ordainer({ apiKey: process.env.ORDAINER_KEY_PILOT }). With no key, decide() sends nothing and returns error.code: 'missing_key', and the middleware blocks the call.

    If you lose a key, create a new test key in Console → Keys. The console never shows a full key again, only its first characters.

  2. Terminal window
    npm install express ordainer
    server.js
    const express = require('express');
    const { Ordainer } = require('ordainer');
    const ordainer = new Ordainer(); // reads ORDAINER_KEY and ORDAINER_BASE_URL. Timeout 300 ms, 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'));

    Leaving mode unset means “do what the plan in the console says”. The sandbox plans are in enforce mode. To pin a mode in code instead, pass new Ordainer({ mode: 'shadow' }). A pinned mode overrides the console.

  3. Click Reset sandbox in the console. The console asks you to confirm: Cancel has the focus, and Cancel or Escape changes nothing. Then:

    Terminal window
    node server.js &

    Wait until the server prints listening on :3001, then send the calls:

    Terminal window
    for i in $(seq 5); do curl -s -X POST localhost:3001/tools/research; echo; done # 5 x your tool's result
    curl -i -X POST localhost:3001/tools/research # call 6

    On Windows? use the PowerShell tab.

    If curl says it failed to connect, or the loop prints blank lines, the server wasn’t ready yet. Run the calls again once you see that line.

    Calls 1 to 5 return your tool’s result:

    {"result":"expensive research done","ordainer":"allow","remaining":4}

    On call 6 your handler does not run, and the caller gets:

    HTTP/1.1 429 Too Many Requests
    X-Request-Id: req_FgaVvr3UBOxnF-Fb
    Retry-After: 3600
    Content-Type: application/json; charset=utf-8
    {"error":{"code":"plan_limit_reached","message":"This call wasn't run because the usage limit was reached (0 of 5 left). It resets at 2027-01-01T00:00:00.000Z. Retrying before then won't work.","request_id":"req_FgaVvr3UBOxnF-Fb","reason":"quota_exceeded","remaining":0,"limit":5,"resets_at":"2027-01-01T00:00:00.000Z","explanation":"On December 1, 2026, 3:25 PM UTC, your request to research.run was denied because the usage limit of 5 allowed decisions per month was reached. The limit resets on January 1, 2027, 12:00 AM UTC. To keep going now, contact the provider of this service. In the sandbox, use Reset sandbox in the console. Reference: req_FgaVvr3UBOxnF-Fb."}}

    Retry-After is the number of seconds from the call until resets_at, rounded up (at least 1). Node SDK 1.2.8 and later cap that wait at 3600 seconds (one hour); use resets_at in the JSON body for the real reset time. This example’s reset is more than an hour away, so the header is 3600. The Ruby gem 0.1.3 and later cap it the same way; 0.1.1 does not, so the same reset can produce a much larger Retry-After. The message is written so an agent, or the person behind it, can read it as-is. X-Request-Id / request_id match the row in Console → Decisions and the export. If your clients treat 429 as “retry soon”, use new Ordainer({ denyStatus: 402 }) instead, or ordainer.middleware({ tool, denyStatus: 402 }) for one route. Only 429 and 402 are accepted; anything else throws a TypeError at startup. All the blocked responses: Errors → SDK blocked responses.

  4. On a real product, start in shadow: we make the real decision and record it, but your tool runs even when we would say no. New plans you create in the console start in shadow. To see it on the sandbox: Console → Plans → on the pilot row, switch to shadow. Then click Reset sandbox, confirm the dialog (Cancel has the focus; Cancel or Escape changes nothing), and call 8 times:

    Terminal window
    for i in $(seq 8); do curl -s -X POST localhost:3001/tools/research; echo; done

    On Windows? use the PowerShell tab.

    Every call returns your tool’s result (calls 6 to 8 with "ordainer":"deny"). From call 6 on, your server log shows:

    [ordainer] shadow: would deny tool=research.run reason=quota_exceeded remaining=0/5 request_id=req_gHgqUYUyo96jVrvu (call allowed)

    What your caller sees: nothing different, and that’s on purpose. In shadow your tool runs and the caller gets its normal answer, HTTP 200, even on calls 6 to 8 where we would have said no. The "ordainer":"deny" above isn’t a signal from us to your caller. It’s the sample handler copying req.ordainer.decision into the response so you can watch. Leave it out of your real handlers, because an agent will usually read a 200 with a result as “it worked”. The would-denies are for you, in your server log and in the console. The middleware adds no Ordainer headers to a shadow answer, so watching status codes and headers won’t show a would-deny. In your code, read req.ordainer.wouldDeny (it’s true for a shadow deny). When you want the agent itself to hear “no”, switch the plan back to enforce, and it gets the 429 from step 3.

    The fields you should read on req.ordainer are decision, allowed, wouldDeny, reason, remaining, limit, resetsAt, requestId, explanation and mode. The same fields are on the object decide() returns and the argument to onDecision. explanation is present when the API sends it (a quota_exceeded deny). Don’t log the whole req.ordainer object, and don’t send it to your callers or to external logs: read the fields you need.

    rejected is true when Ordainer answered with an error instead of a decision: any 4xx, for example 401 unknown_key, 401 revoked_key or 429 rate_limited, and also when no agent key or tool was given. Then the call is blocked in every failMode, and your caller gets plan_check_rejected (or 429 rate_limited for a rate limit). Two 4xx answers let the call run instead: 429 safety_limit_reached, and 403 subscription_inactive under billingLapse: 'open'. A deny is a decision, not a rejection, so its rejected is false.

    In the console, Overview shows “3 calls in the last 7 days would have been denied”. The Would deny, last 7 days card number opens those rows on Decisions, counted by plan and by key. Decisions shows them as would deny (call ran) with mode shadow, and can filter to would-denies. Plans shows the count next to the mode button. Export (CSV/JSON) has mode = shadow and would_deny = true on those rows (plus plan_id, plan_name, and plan_policy_version), and Change log lists your switch.

    When the would-denies look right, open Console → Plans and click Enforce in that plan’s Mode column. Your running server picks it up on the next call, with no deploy. To send decisions to your own metrics, pass onDecision: (d) => … to the constructor: d.wouldDeny is true for shadow denies. More: Shadow vs enforce.

From 1.3.0, OrdainerAdmin in the same ordainer package calls the admin API with an admin key (ord_admin_…, from adminKey or ORDAINER_ADMIN_KEY). It does not call decide(), and an admin key does not work on /v1/decide. Create the admin key in Console → Keys. Do not log the admin key, or the agent-key secret from createKey (it is only in the first response).

admin.js
const { Ordainer, OrdainerAdmin } = require('ordainer');
// Admin key scopes: usage:read, customers:write, keys:write and keys:revoke
async function main() {
const admin = new OrdainerAdmin(); // adminKey defaults to process.env.ORDAINER_ADMIN_KEY
// Find the plan first, so nothing is created if it isn't there.
// 'pilot' is a sandbox plan from sign-up; use your own plan's name.
const { plans } = await admin.listPlans();
const plan = plans.find((p) => p.name === 'pilot');
if (!plan) throw new Error('No plan named pilot');
const customer = await admin.createCustomer({ name: 'example' });
let deleted;
try {
const created = await admin.createKey({ label: 'pilot', customerId: customer.id, planId: plan.id });
const agentKey = created.secret; // first response only; do not log it
const record = await admin.getKey(created.id); // no secret; revokedAt is null while the key is active
const decision = await new Ordainer({ apiKey: agentKey }).decide({ tool: 'research.run' });
console.log(decision.allowed, decision.decision);
} finally {
// Runs even if a step above fails, so no customer is left behind.
deleted = await admin.deleteCustomer(customer.id); // needs customers:write and keys:revoke
}
console.log(deleted.revokedKeyIds); // the keys this call revoked
// deleted.requestId is the delete's X-Request-Id: list only that write
const { changes } = await admin.listChanges({ requestId: deleted.requestId });
console.log(changes.map((c) => c.action));
}
main().catch((err) => {
console.error(err.message);
process.exitCode = 1;
});

deleteCustomer revokes that customer’s active test keys in the same step and returns { id, deleted: true, revokedKeyIds }. The sandbox customer cannot be deleted. A customer that owns a live key cannot be deleted this way. An unknown id is 404 not_found.

The client also wraps the other admin routes on the Admin API page (plans, list/update, revoke, move, pagination). Writes send Idempotency-Key; pass idempotencyKey to choose it. Failures throw OrdainerAdminError; match on code. Arguments and responses are camelCase. More: the package README.

  • One agent key per customer integration or agent: create a customer, a plan and a key in the console, then pass apiKey: (req) => keyFor(req.user) to the constructor or to middleware(). Counts are per key. A plan covers one tool, or every tool (*), not a list. Ordainer is in beta. You can set up customers, plans and keys in the console, or from your own code with the admin API (test keys only during the beta). From Node SDK 1.3.0, OrdainerAdmin in the same package calls that API; see Admin API above.
  • Retries: the middleware gives every incoming request a fresh random idempotency key and never uses an Idempotency-Key header your caller sends. To make a retry count once, pass idempotencyKey: (req) => … built from your own data (your job ID or queue message ID), one key per real operation. A key replays the first answer for 24 hours. retries: n (0 to 5, default 1) makes the SDK retry a timeout, network error or 503 with the same key. More: Idempotency and retries.
  • Rate limits: Each agent key gets about 100 requests a second, each server counts separately. Each agent key has at most 4 requests in flight at once by default on our hosted service (up to 20 more wait about 200 ms). Past the per-second limit, or if that line is full, your caller gets 429 rate_limited with Retry-After, and onRateLimited: (d) => … runs; a call that waited and ran out of time gets 503 decide_timeout, which the SDK retries once and then handles per failMode.
  • Code that isn’t Express (fragment: ordainer is the client from step 2’s server.js, and runResearch and args are yours):
    const research = ordainer.wrap(runResearch, { tool: 'research.run' });
    await research(args); // throws OrdainerDeniedError (.status / .headers / .body) when blocked
  • Outages: if we’re slow (300 ms per attempt; at most about 650 ms with the default retry), unreachable or answer with a 5xx, the call is allowed and a warning is logged. The exception is a sticky deny: within 60 seconds (stickyDenyMs) of a quota_exceeded deny for the same key and tool, that call is blocked with 429 plan_limit_reached instead of running (Sticky deny). Use failMode: 'closed' to block instead. An error answer (any 4xx, such as unknown_key) is not an outage: it’s blocked in every failMode, except 403 subscription_inactive, which follows billingLapse (default 'open': allowed), and 429 safety_limit_reached, which is allowed with result.safetyLimited set. billingLapse is the billing-lapse setting for when your own Ordainer subscription has lapsed: 'open' runs calls unchecked, 'closed' blocks them. See Fail open vs fail closed.
  • Going live: Live keys are not available yet. Live keys open when paid plans launch. Your test keys cover everything in your beta.
  • Every field and error: Decide API reference and Errors.