Ask whether one tool call may run, before your handler does any work. We check the caller’s agent key against the plan it is bound to and answer allow or deny. Every answer writes one audit row.
At a glance
Section titled “At a glance”- A deny is an answer, not an error.
allowand every deny return HTTP 200. Checkdecision, not the status code. - Every response carries an
X-Request-Idheader. On a decision it equalsrequest_idin the body, which is also the audit row’s id. - Always send an idempotency key. A retry with the same key gets the original answer back and is not counted twice.
- Errors always use one shape:
{"error":{"code","message","request_id"}}. - Within
/v1we only add things. Ignore fields you don’t know. See Versioning. - Each agent key gets about 100 requests a second, each server counts separately, and 4 requests in flight at once by default on our hosted service. Up to 20 more wait about 200 ms for a slot. If the line is full you get
429 concurrency_limited; if a waiting call’s time runs out you get503 decide_timeout(retry with the same idempotency key). That wait is part of the server’s deadline for each decide, not added to it, so some time is always left for the decision itself: see how the server deadline and your timeout fit together.
Authentication
Section titled “Authentication”Send the agent key as a Bearer token:
Authorization: Bearer ord_test_...- Keys look like
ord_test_orord_live_followed by 32 random characters. - Each key is bound to one customer and one plan. The key alone decides whose counter is used; there is no customer or plan parameter.
- Keys are shown once when created. We store only a SHA-256 hash, so a lost key can’t be recovered: create a new one in Console → Keys.
- Live keys are not available yet. Live keys open when paid plans launch. Your test keys cover everything in your beta.
Request
Section titled “Request”Headers
Section titled “Headers”| Header | Required | Description |
|---|---|---|
Authorization |
Yes | Bearer <agent key>. |
Content-Type |
Recommended | application/json. |
Idempotency-Key |
No (strongly recommended) | 1 to 255 characters. Same meaning as the body field idempotency_key; used only when that field is absent or null. |
Body parameters
Section titled “Body parameters”A JSON object, up to 16,384 bytes. Unknown fields, such as units, quantity, cost or customer_id, are ignored. Every allowed call counts as 1. There is no field for counting a call as more than one.
toolstring, 1–200 charsRequiredThe tool being called, for example research.run. Spaces around it are trimmed; after that it’s compared exactly and case-sensitively. A plan covers one tool, or every tool (*), never a list.
idempotency_keystring, 1–255 charsOptionalMakes retries safe. Scoped to the agent key. If present and not null, it is used and the Idempotency-Key header is ignored.
mode"enforce" | "shadow"OptionalOverrides the plan’s mode for this call. Leave it out to use the plan’s mode (Console → Plans). It never changes the decision; it only changes the mode echoed back.
leaseobject, optionalAsk for a session lease on this allow: {"ttl_s": 120}, or {} for the default. The session limit applies only when this field is sent. Without lease, the call is decided as before and is never denied for the session limit. On a key with no session limit, lease is ignored and no lease is stored. ttl_s is optional: a whole number of seconds from 1 to 3600 (default 120). Anything else, or a lease that isn’t an object, is 400 invalid_request. The Node SDK (1.4.0 and later), the Python package (0.4.0 and later) and the Java SDK (0.1.0 and later) send it from decide()’s lease option. The Ruby gem (0.1.3) doesn’t send it. See Session leases.
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.
{ "tool": "research.run", "idempotency_key": "job-42-step-3"}Response
Section titled “Response”200 OK for allow and for every deny.
decision"allow" | "deny"The answer.
reasonstringok on allow; quota_exceeded, tool_not_in_plan, test_limit_reached or concurrency_exhausted on deny. More may be added: treat an unknown reason on a deny as a deny.
remaininginteger ≥ 0 | nullAllows left on this key’s plan in the current period, after this decision. Never negative. null on a plan with no cap: check for null before doing arithmetic. On test_limit_reached it’s 0 and never null (see test_limit_reached).
limitinteger ≥ 0 | nullThe cap of the key’s plan when this decision was made: max allows per period for this key. null on a plan with no cap. On test_limit_reached it’s your organization’s monthly test-decision limit instead, not the plan’s cap, and never null, even on a key with no plan cap.
resets_atISO 8601 timestampWhen this answer can change: the start of the plan’s next period. That’s 00:00 UTC on the 1st for a month plan, 00:00 UTC for a day plan, or the next minute (UTC) for a minute plan. On test_limit_reached, it’s the 1st of next month (UTC).
mode"enforce" | "shadow"The effective mode: the request’s mode if you sent one, otherwise the plan’s (on test_limit_reached too).
request_idstringreq_ + 16 URL-safe characters. Same value as the X-Request-Id header and the audit row.
messagestring, optionalOnly on an enforce test_limit_reached: a plain-language explanation. Don’t parse it.
explanationstring, optionalOnly on a quota_exceeded or concurrency_exhausted deny, in enforce and in shadow: one plain-language sentence about the deny that you can show a person. It includes the time, the tool and the request_id, plus the plan’s limit and period on quota_exceeded, or the key’s session limit on concurrency_exhausted. Its wording can change, so don’t parse it. Branch on reason instead. It can be missing even on a quota_exceeded or concurrency_exhausted deny, so don’t require it.
leaseobject, optionalPresent when this call took a session lease: id (a UUID), expires_at, running (this key’s running leases, including this one) and limit (the key’s session limit, not the plan’s limit). Absent when you didn’t send lease, the key has no session limit, or the call was a deny, except a shadow concurrency_exhausted would-deny, which still takes and returns the lease.
tool_in_planfalse, optionalOnly on a tool_not_in_plan deny, in enforce and in shadow: always false, so you can tell the tool isn’t in the key’s plan without matching on reason. Absent on every other answer. remaining and limit don’t change: they describe the key’s plan for its own tool, not the tool that was denied.
Field names in the Node SDK. The raw API uses snake_case. The Node SDK’s decide() result uses camelCase: resets_at is resetsAt and request_id is requestId. decision, reason, remaining, limit, mode and explanation keep their names. The SDK result has no message or tool_in_plan; check reason instead. From Node SDK 1.4.0, decide({ lease }) sends lease and the result’s lease is camelCase too: expires_at is expiresAt, and id, running and limit keep their names. The Python package (0.4.0 and later) keeps the API’s names (decision.lease.expires_at). See Session leases. The error body your caller gets from the SDK middleware uses the API’s snake_case (error.request_id).
Reasons
Section titled “Reasons”| reason | decision | Counted? | What it means | What to do |
|---|---|---|---|---|
| ok | allow | Yes | Under the cap. | Run the tool. |
| quota_exceeded | deny | No. Denies don’t count. | This key’s cap for the period is used up. | Don’t run the tool (in enforce). Retrying before resets_at gets the same answer. |
| tool_not_in_plan | deny | No. Denies don’t count. | The key’s plan is bound to a different tool. | Don’t run the tool. Waiting won’t help: change the plan’s tool or move the key to a plan that covers it. |
| test_limit_reached | deny | No. In shadow it counts only toward the safety ceiling. | Test keys only. Your organization used its free test-key decisions for this UTC month. | Enforce: don’t run the tool. Shadow: run it, like any would-deny, up to the safety ceiling. It’s our sandbox limit, not your customer’s plan. Live keys are not affected. |
| concurrency_exhausted | deny | No. Denies don’t count. One decision row, like any deny. | This key already has its session limit of running leases (only on a decide that sent lease). Checked after the plan cap, tool and test limit. A cap deny takes no lease. |
Enforce: don’t start the session. Shadow: the answer is a would-deny and the lease is still taken. Release a lease, extend one, or wait for the TTL. remaining and limit are the plan’s, so null on a plan with no cap. |
What mode means for your code
Section titled “What mode means for your code”mode doesn’t change the decision. It tells you what to do with a deny: in enforce, don’t run the tool; in shadow, run it anyway, and the deny is recorded as “would deny”.
decision is allow or mode is shadow.Response examples
Section titled “Response examples”HTTP/1.1 200 OKX-Request-Id: req_bUyY8o6enyPzZvELContent-Type: application/json; charset=utf-8Cache-Control: no-store
{"decision":"allow","reason":"ok","remaining":4,"limit":5,"resets_at":"2027-01-01T00:00:00.000Z","mode":"enforce","request_id":"req_bUyY8o6enyPzZvEL"}HTTP/1.1 200 OKX-Request-Id: req_CuJXkng3xBlh4g3hContent-Type: application/json; charset=utf-8Cache-Control: no-store
{"decision":"deny","reason":"quota_exceeded","remaining":0,"limit":5,"resets_at":"2027-01-01T00:00:00.000Z","mode":"enforce","request_id":"req_CuJXkng3xBlh4g3h"}HTTP/1.1 200 OKX-Request-Id: req_jhLAkfS738jqQOSYContent-Type: application/json; charset=utf-8Cache-Control: no-store
{"decision":"deny","reason":"tool_not_in_plan","remaining":98,"limit":100,"resets_at":"2027-01-01T00:00:00.000Z","mode":"enforce","request_id":"req_jhLAkfS738jqQOSY","tool_in_plan":false}HTTP/1.1 200 OKX-Request-Id: req_42nKiByco0RKvQJYContent-Type: application/json; charset=utf-8Cache-Control: no-store
{"decision":"deny","reason":"quota_exceeded","remaining":0,"limit":1,"resets_at":"2027-01-01T00:00:00.000Z","mode":"shadow","request_id":"req_42nKiByco0RKvQJY"}The tool_not_in_plan example is a key whose plan is bound to web.search (cap 100, 2 used) asking for research.run. Denies never count toward the plan limit, so remaining is unchanged. tool_in_plan: false comes only with this reason.
Idempotency and retries
Section titled “Idempotency and retries”- Scope: per agent key. The same string on two different keys means two different requests.
- How long a key replays: 24 hours from the first call with it. A retry gets the stored answer (same body, same
request_id) andIdempotent-Replayed: true. No counter moves and no new audit row is written. - Same key, different
toolormode:409 idempotency_conflict. Use a new key for a different request. - Plan switched between shadow and enforce: a retry with the same key still gets the original answer, decided under the mode the plan had at the time. Use a new key to get a decision under the new mode.
- No key: every request is a new decision and is counted. The audit row’s
idempotency_keyis an empty string. It is not filled in with the request ID. Older rows may still show the request ID there. Only retry500 internal_errorif you sent a key.
Errors
Section titled “Errors”Errors are non-200 responses with this body. Requests that end in an error write no audit row and never move a counter. Branch on error.code; the message wording may change.
{ "error": { "code": "missing_key", "message": "Send your agent key as \"Authorization: Bearer ord_...\".", "request_id": "req_EWJ4qahPhrssV5a5" }}| HTTP | code | When | Retry? |
|---|---|---|---|
| 400 | invalid_request |
The body isn’t a JSON object, or tool or mode is missing or invalid. message names the field. |
After fixing |
| 400 | invalid_idempotency_key |
The idempotency key isn’t a string of 1–255 characters. | After fixing |
| 401 | missing_key |
No Authorization: Bearer … header. |
After fixing |
| 401 | unknown_key |
The key isn’t recognized. | No |
| 401 | revoked_key |
The key was revoked in the console. | No |
| 403 | subscription_required |
A live key of an organization with no paid subscription. Test keys still work. | No, subscribe first |
| 403 | subscription_inactive |
A live key whose organization’s subscription has ended. Test keys still work. | No: pay the open invoice by day 30 after the missed renewal (same keys back), else resubscribe |
| 409 | idempotency_conflict |
This idempotency key was already used, on this agent key, with a different tool or mode. |
No, use a new key |
| 429 | rate_limited |
About 100 requests a second, each server counts separately. limit_scope is per_key. |
Yes, after Retry-After, same idempotency key |
| 429 | concurrency_limited |
4 requests already in flight on this key (the default limit) on our hosted service, and the line of 20 waiting is full. limit_scope is per_key_concurrency. |
Yes, after Retry-After, fewer calls at once |
| 429 | safety_limit_reached |
A shadow call on a test key past 10 times your organization’s monthly test limit (Shadow mode at the test limit). limit_scope is org_safety. Not a deny: let the tool run (SDK 1.2.0 does). |
After resets_at (the start of next month, UTC) |
| 500 | internal_error |
A bug or database failure on our side. | Yes, same idempotency key |
| 503 | decide_timeout |
The decision didn’t finish within the server’s deadline (250 ms by default); rolled back, nothing counted, or it waited in this key’s line and ran out of time. | Yes, after Retry-After: 1, same idempotency key |
| 503 | db_unavailable |
Our database couldn’t be reached or cancelled this decision; no decision returned. | Yes, after Retry-After: 1, same idempotency key |
| 503 | db_timeout |
A database query on the decision path ran too long and was cancelled; nothing counted. | Yes, after Retry-After: 1, same idempotency key |
Every code, including invalid_json (400), old_key_format (401), too_many_failed_auth (429), payload_too_large (413, body over 16 KB) and db_timeout (503), has its own entry with a fix on Errors.
Limits and behavior worth knowing
Section titled “Limits and behavior worth knowing”- Counters are per agent key, not per customer or plan. Two keys on the same plan each get the full cap.
- The monthly test allowance is per organization. Test keys include 1,000 test decisions a month, shared by all the test keys in your organization, and only allowed decisions count. Past it, test keys answer deny
test_limit_reacheduntil the 1st (UTC). One busy customer’s allowed calls use up this shared allowance for every other customer in your organization, so give each customer its own key on a plan with a cap (plan caps count per key). - Every allowed call counts as 1. Extra fields such as
units,quantity,costorcustomer_idare ignored. Denies count 0. - A plan’s period is a month (UTC), a day (resets 00:00 UTC) or a minute (UTC). New plans default to Month. A month plan’s
resets_atis 00:00 UTC on the 1st, which is the evening before in North America (8 PM ET in summer, 7 PM ET in winter). The 1,000 test decisions always count by UTC month. - Caps can be 0: a plan with a cap of 0 denies every call with
quota_exceeded. - Plans and keys can change mid-period. See Plan changes during a period.
- Under parallel load the cap is exact: concurrent calls can never push a key past its cap. The same holds for the test-key limit.
- At most 4 requests in flight at once per agent key by default on our hosted service (per server, each server counts separately). Up to 20 more wait about 200 ms for a free slot. Past a full line you get
429 concurrency_limited("limit_scope": "per_key_concurrency",Retry-After: 1); a waiting call that runs out of time gets503 decide_timeout(Retry-After: 1), which the SDK retries once and then handles perfailMode. The hosted default is 4 in flight and 20 waiting. A key can have its own in-flight limit; the Keys page sets it. A key’s own limit wins over the server default. A test key can replace that for itself with the admin API: in-flight from 1 to 8, queued from 0 to 100, or null to keep this default. Each server still counts separately. Agents making parallel tool calls can hit it: cap how many tool calls run at once per agent key, or retry refused ones after 1 second with the same idempotency key. - Errors aren’t audited: 4xx/5xx requests write no audit row. Every 200 (allow or deny,
test_limit_reachedincluded) writes exactly one. Our server log keeps one line per 4xx (request ID, status, error code and organization, pluslimit_scopeon a 429; never your key, address, body, headers or query), so support can trace an errored request from itsX-Request-Id, and every 4xx and 5xx answer (plus idempotent replays) is counted per organization and day. - Server-to-server only. There is no CORS, on purpose: the API sends no CORS headers and answers
OPTIONSwith 405. Keep agent keys on your server, never in a web page. - Find a decision by its
request_id: Console → Decisions → paste it into Request ID. Exact match, your organization only, anywhere in your retention window. A request that got an error (any 4xx/5xx) wrote no row, so its ID is never found; the not-found message says so. Send that ID to support instead. Atest_limit_reachedrow shows0/1,000 (your monthly test limit, not the plan allowance), with your organization’s own limit in place of 1,000 if we’ve set one. Results come with a one-row CSV download. Export the log as CSV or JSON from the same page (console login; there is no API-key export endpoint in V0). The default range is the last 90 days, or your history if you keep less than that. The same page filters by decision, mode, would-deny (a deny whose mode is shadow; the call ran, including a call you sent withmode: "shadow"), key, tool, reason, plan, customer and date. The table is 50 rows at a time, newest first, with Older and Newer through the whole range. Would-denies in the range are counted by key and by plan. The Would deny, last 7 days card number on Overview opens that filtered list. The CSV and JSON download uses those filters. After the existing columns, each row addswould_deny(trueonly whendecisionisdenyandmodeisshadow; otherwisefalse),plan_id(the plan recorded on that decision, even if the key later moves),plan_name(that plan’s current name), andplan_policy_version(the version stored on the row, or empty when the row has none). plan_policy_versionis the plan’s policy version copied onto the decision when it is written, and that row keeps it; the plan’s version goes up by one only when the console saves a different limit or tool, when the mode actually switches between shadow and enforce, or when the admin API changes the plan’s name, limit, or tool, and the next decision stores the new number.- Rate limit. About 100 requests a second, each server counts separately. Over it:
429 rate_limitedwithRetry-After(whole seconds, at least 1); no decision, nothing counted, no audit row. The limit is counted on each of our servers separately, so the exact point where it starts is approximate: don’t design around a precise threshold, and treat any 429 as “waitRetry-After, then retry with the same idempotency key”. Well-formed unknown keys are limited too. The test-key limit above is a monthly quota, not a rate limit. - Limit on failed keys: 30 a minute per address. Requests with a missing, wrongly shaped or unknown key use up a per-address allowance of 30 (IPv4: per address; IPv6: per /64 block), refilling one every 2 seconds. When it’s empty, further requests with a missing, malformed or unknown key get
429 too_many_failed_auth("limit_scope": "per_address") withRetry-Afterinstead of their 401. A valid key is not refused by this limit, so services sharing an outgoing address (NAT gateway, proxy, cloud egress IP) aren’t blocked by one service’s bad key. The one exception: if the address is over budget and the server can’t check a key it doesn’t already know in time (overloaded, or the check timed out), that request gets a 429 whose message says the key couldn’t be checked and to retry afterRetry-After; these are recorded by request ID. Successful calls,revoked_keyand the exact old 32-charactersk_test_/sk_live_key (401 old_key_format) never use it up; othersk_test_/sk_live_values do. Fix the key; waiting alone won’t help. Counted on each server separately, like the per-key limit. - Latency and status: we don’t publish a speed target or an SLA, and there is no status page yet. Our API and console run on Render in Ohio, in the US East region. Our database is Neon Postgres in AWS US East 2, also in Ohio. Each
POST /v1/decideresponse includes aServer-Timingheader showing how long the check took on our side. Set your own client timeout (the Node SDK defaults to 300 ms). - How the server deadline and your timeout fit together. Our server gives each decide 250 ms to start deciding: waiting for a free slot, a database connection or a lock. A wait for a free slot on your key stops after about 200 ms, so part of the 250 ms is always left for the decision itself. If the 250 ms runs out, you get
503 decide_timeout, and nothing is counted. Once a decision is being saved, it always finishes and you get its answer, even if that takes longer than 250 ms. Our SDKs wait 300 ms per attempt (one retry, about 650 ms in all) and then followfailMode. So, rarely, a call can fail open on your side even though we counted it and wrote its audit row. A retry with the same idempotency key gets that original answer back and isn’t counted twice. - Reading
Server-Timing. The header hasdecide(our total time on the server for this request),db(time holding a database connection) andwait(time waiting to get a database connection), each in milliseconds. You may also seetrips. It’s an internal marker (2 or 4), not a time, so don’t size a timeout from it. Your own end-to-end time minusdecideis network and TLS between you and us. It’s on every decide answer, errors included. More in Choosing a timeout. - Cold starts and the first call. The first call from a new process, a cold JVM or a fresh serverless instance also has to open the connection, so it can take longer than the calls after it. Two things keep it inside your timeout: make one warm-up request at startup (
GET /livezon the API address; it needs no key, moves no usage counter and writes no audit row), and on a timeout retry once with the same idempotency key, so the retry is answered once and counted once. Our Node, Python and Ruby SDKs retry this way by default: 300 ms per attempt and one retry, 650 ms in all. They don’t send a warm-up request; add one yourself if your first call matters. The Java SDK (0.1.0) retries the same way, andwarmUp(true)on the builder (orordainer.warmUp()at start-up) sendsGET /livezon the client’s connection pool before the first decide.
Plan changes during a period
Section titled “Plan changes during a period”In the console you can edit a plan’s allowance and tool (Console → Plans → Save on the plan’s row), switch its mode, and move a key to another plan (Console → Keys → move to plan). None of this changes the request or the response format. What it changes is the values:
- From the next decision. A change applies to the next decision of every key on that plan. No deploy, and the key’s secret doesn’t change.
- The count carries over. The current period’s count belongs to the key, so it stays the same after a cap change or a move. Counts are kept per key, not per plan: a key moved to another plan with the same tool and period keeps what it has used this period, and the new plan’s cap applies from its next call. Lower the cap below what a key has used and its next calls get
deny/quota_exceededwithremaining: 0and the newlimit. Raise it, and they’re allowed again at once. - A tool change takes effect the same way: calls for a tool the plan no longer covers get
deny/tool_not_in_plan. A plan covers one tool or every tool (*), never a list. The console trims spaces from the tool name, and an empty tool means*. If at least one key on the plan is not revoked, the console asks you to confirm first, in shadow and in enforce. The page names that count and the old and new tool. Cancel leaves the cap and the tool as they were, even if the save changed both. A cap-only save does not ask, and neither does a tool change on a plan with no non-revoked key. Switching shadow to enforce stays one click; the Plans page shows one line next to Enforce that calls over the limit will be blocked from the next call.PATCH /v1/admin/plans/:idapplies a tool change immediately, with no confirm, and the change log records it. - No decision mixes old and new values. A change waits for decisions already in progress on that plan or key; decisions that start meanwhile wait for the change and then use the new values.
- Retries: a retry with the same idempotency key gets the stored answer, with the values that applied when it was first decided.
- The audit row of each decision records the cap that applied (
limit) and the plan the key was on at the time.
Example: a key on a plan with cap 5 had used 3 allows; the cap was then lowered to 2.
{ "decision": "deny", "reason": "quota_exceeded", "remaining": 0, "limit": 2, "resets_at": "2027-01-01T00:00:00.000Z", "mode": "enforce", "request_id": "req_Po6gTTFD76C9umPJ"}After raising the cap to 6, the same key’s next call:
{ "decision": "allow", "reason": "ok", "remaining": 2, "limit": 6, "resets_at": "2027-01-01T00:00:00.000Z", "mode": "enforce", "request_id": "req_0RVeCRAxh7GlhgUh"}Moves only go to a plan shared by all your customers or to a plan of the key’s own customer, with the same period. Console → Change log records plan and key changes made in the console: cap and tool edits, mode switches, key moves, and key creation and revocation. A change we make to your organization’s monthly test-key limit is not listed there. Each line shows who, when, and what changed (for example max_allows: 5 → 2). A key move also shows “used this period: N (carried over)”; key creation and revocation show the key’s prefix (never the secret), customer and plan. The sandbox keys made at sign-up are listed (created test key, prefix, customer and plan; never the secret). Adding a plan, and editing or deleting a customer you added, are listed too. Deleting a customer takes that customer off the list, revokes its keys, and leaves every decision row in place. The next call gets the usual revoked-key error. A call already in flight finishes. GET /v1/admin/changes lists the same visible rows, without the before and after values and without secrets. There is no full export of the change log.
See Errors → Console errors for what the console says when a change is refused.