Errors and decline reasons
The error format, every error type, and the decline and hold reason codes with their stages.
ndStill tells you two different things when something doesn't go through: that a request failed (an error, with an HTTP status of 400 or above), or that a payment was decided against (a decision with reasons). This page covers both, so your agent can tell "fix the request" apart from "the policy said no" and "a person has to look at this".
The error format#
Every error response has the same JSON body, whatever the endpoint:
{
"object": "error",
"type": "invalid_request",
"code": "invalid_request",
"message": "Pick at least one scope.",
"fields": { "scopes": "Required" },
"docs_url": "https://docs.ndstill.com/api/errors#invalid_request",
"request_id": "req_4c1e0b9a77d2f3a51e08"
}| Field | Always there | What it is |
|---|---|---|
object | Yes | Always "error". |
type | Yes | The broad class. It decides the HTTP status and whether a retry can help. Branch on this first. |
code | Yes | A specific machine code within the type, such as not_found, idempotency_key_reused or payment_declined. New codes can appear in any version. |
message | Yes | What happened and what to do next, written for a person. Show it, but don't parse it. |
decline_reasons | On declined | The reasons a payment was declined, in the same shape as a decision's reasons. |
fields | On some invalid_request | Field errors keyed by path, such as "amount.amount": "Must be positive". |
docs_url | Usually | A link to the part of these docs that explains the error. |
request_id | Yes | The same value as the x-request-id header. Quote it to support. |
Error types and HTTP status#
The type field maps to one HTTP status. Your retry logic only needs the type.
| type | HTTP | Meaning |
|---|---|---|
invalid_request | 400 | The request is malformed or a field is invalid. fields maps each bad field to a message. |
authentication | 401 | The key or token is missing, expired or revoked. |
permission | 403 | The key, token or role isn't allowed to do this. Agents can never change their own policy, limits or freeze state. |
not_found | 404 | No object with that ID in this org. |
conflict | 409 | The object changed, already exists, or an Idempotency-Key was reused with a different body. |
declined | 402 | The payment was declined. decline_reasons[] says why, stage by stage. |
step_up_required | 400 | A person must confirm with a passkey first (org-wide freeze, policy activation, reveals). Retry with the assertion. |
rate_limited | 429 | Too many requests. Wait for the Retry-After header. |
upstream | 502 | A provider (card processor, bank, wallet) failed. Safe to retry with the same Idempotency-Key. |
timeout | 504 | A provider didn't answer in time. Safe to retry with the same Idempotency-Key. |
internal | 500 | Something failed inside ndStill. Quote the request ID. |
A few notes on the types people ask about most:
step_up_requiredmeans a person has to confirm with a passkey before the action runs: activating a policy, an org-wide freeze, revealing a card, approving above a policy's assurance line. Agents never get this far, because agent credentials can't perform these actions at all. In the console or your own admin tool, prompt for the passkey and send the assertion instep_up(orpasskey_assertionon approvals).conflictcovers state that changed under you (approving a payment someone already rejected), saving a policy version that changes nothing, and reusing anIdempotency-Keywith a different body (idempotency_key_reused).upstreamandtimeoutcome from a provider behind a connection, such as a card processor or a bank API. ndStill has already applied your policy by then, and the request is safe to retry with the same idempotency key.
Declined, held and approved#
A payment request has three outcomes, and only one of them is an error.
| Outcome | HTTP status | What you get | What the agent should do |
|---|---|---|---|
| Approved | 200 | A payment intent with status approved (then authorized, settled) | Use the credential or wait for the receipt. |
| Held | 200 | A payment intent with status held, an approval_id and reasons[] | Wait for the approval, or tell its user it's waiting on a person. |
| Declined | 402 | An error with type declined, code payment_declined and decline_reasons[] | Don't retry the same payment. Read the reasons and change course. |
A hold is the pipeline working as designed: something in the policy, the mandate or the risk checks wants a person to decide. The approval resolves later, and you hear about it from the approval.decided webhook, an MCP progress notification, or approvals.wait() in an SDK. See Approvals.
Decisions that you read later, with GET/decisions/{id}, carry the same reasons in reasons[], plus the full eleven-stage trace. The 402 error's decline_reasons[] is that list, returned inline so the agent doesn't need a second call.
{
"object": "error",
"type": "declined",
"code": "payment_declined",
"message": "Over Travel desk's weekly budget by $112.00.",
"decline_reasons": [
{
"code": "over_budget",
"stage": "budget",
"effect": "decline",
"params": {
"scope_name": "Travel desk",
"window": "week",
"over_by": { "amount": 11200, "asset": "USD" },
"limit": { "amount": 150000, "asset": "USD" }
}
}
],
"request_id": "req_91aa30c2e5b7d84f10c3"
}Reason codes#
Each reason has a code, the stage of the decision pipeline that produced it, an effect (hold or decline) and params that fill the plain-language sentence. All hold reasons are reported, not only the first, so a payment that is both over the per-payment limit and to a new seller lists both.
| Code | Stage | Example message |
|---|---|---|
agent_unknown | 1 Identity | This agent isn't registered in the org. |
key_revoked | 1 Identity | The agent used a key that has been revoked. |
passport_invalid | 1 Identity | The agent's request signature didn't match its passport. |
plan_limit | 2 Plan and go-live | The org's plan limit for this has been reached. |
verification_required | 2 Plan and go-live | The org must finish verification before live payments. |
sandbox_only | 2 Plan and go-live | This agent can only make test payments. |
agent_frozen | 3 Freeze check | Travel desk is frozen. |
tree_frozen | 3 Freeze check | The agent tree under Travel desk is frozen. |
team_frozen | 3 Freeze check | Travel desk is frozen. |
org_frozen | 3 Freeze check | Every agent in the org is frozen. |
credential_frozen | 3 Freeze check | The credential used for this payment is frozen. |
funding_frozen | 3 Freeze check | The funding source Travel desk is frozen. |
no_funding_access | 4 Funding source | Travel desk isn't allowed to use Travel desk. |
funding_insufficient | 4 Funding source | Travel desk doesn't have enough available for $612.00. |
mandate_missing | 6 Mandate match | No signed mandate covers this payment. |
mandate_amount_mismatch | 6 Mandate match | $612.00 is above the mandate's limit of $600.00. |
mandate_counterparty_mismatch | 6 Mandate match | The mandate is for Delta Air Lines, but the agent is paying Acme Air. |
mandate_expired | 6 Mandate match | The mandate covering this payment has expired. |
mandate_uses_exhausted | 6 Mandate match | The mandate has already been used as many times as allowed. |
over_per_payment_limit | 7 Policy rules | $612.00 is over the $500.00 limit per payment. |
blocked_counterparty | 7 Policy rules | Acme Air is on the block list. |
blocked_category | 7 Policy rules | Gambling purchases are blocked by policy. |
outside_time_window | 7 Policy rules | Payments aren't allowed at this time of day by policy. |
first_time_counterparty | 7 Policy rules | First payment to Acme Air; policy holds new sellers. |
confidence_below_floor | 7 Policy rules | The agent's confidence was below the policy's floor. |
velocity | 8 Risk | 9 payments in 10 minutes is faster than usual for Travel desk. |
spend_spike | 8 Risk | $612.00 is far above Travel desk's usual payment. |
loop_detected | 8 Risk | The agent sent the same request repeatedly; this looks like a loop. |
off_hours | 8 Risk | The payment came outside this agent's usual hours. |
price_drift | 8 Risk | The price drifted from what the mandate expected ($600.00). |
stolen_key_signal | 8 Risk | The agent's key was used from an unfamiliar place. |
sanctions_hit | 8 Risk | Acme Air matched a sanctions list. |
over_budget | 9 Budget | Over Travel desk's weekly budget by $112.00. |
budget_nearly_exhausted | 9 Budget | This would use the last of Travel desk's weekly budget. |
approval_required_amount | 10 Approval threshold | $612.00 is above the $250.00 approval line. |
approval_required_counterparty | 10 Approval threshold | Payments to Acme Air always need approval. |
approval_required_policy | 10 Approval threshold | Policy requires a person to approve this payment. |
rejected_by_person | After the decision | Rejected by Priya Shah: Not this vendor. |
approval_expired | After the decision | Nobody approved this in time, so it expired. |
rail_error | After the decision | The Not this vendor returned an error; no money moved. |
Three codes come from after the decision rather than from a stage: rejected_by_person (an approver said no, with their note in params.note), approval_expired (nobody decided before the approval's timeout and the policy said reject) and rail_error (the rail failed after approval; the reservation is released).
Handling errors in code#
The SDKs turn error bodies into typed exceptions. DeclinedError is a subclass of ApiError, so you can catch the specific case first.
import { NdStill, ApiError, DeclinedError } from "@ndstill/sdk";
const ndstill = new NdStill({ apiKey: process.env.NDSTILL_API_KEY });
try {
const payment = await ndstill.pay({
agent: "agt_01JC…",
amount: { amount: 4200, asset: "USD" },
counterparty: "Delta Air Lines",
purpose: "Flight SFO to JFK for the offsite",
});
if (payment.status === "held") {
await ndstill.approvals.wait(payment.approval_id, { timeoutMs: 10 * 60_000 });
}
} catch (err) {
if (err instanceof DeclinedError) {
// Plain sentences the agent can act on, plus codes for your logic.
console.log(err.declineReasons.map((r) => `${r.code}: ${r.message}`));
} else if (err instanceof ApiError) {
console.error(err.type, err.code, err.message, err.requestId);
} else {
throw err;
}
}For an agent talking over MCP, the pay tool returns declines and holds as structured tool results, not protocol errors, so the model sees the reasons as text it can reason about. See MCP server and tools.
When to retry#
| Type | Retry? | How |
|---|---|---|
rate_limited | Yes | After the Retry-After header, with the same Idempotency-Key. |
upstream, timeout, internal | Yes | Exponential backoff with jitter (for example 0.5 s, 1 s, 2 s, up to 5 tries), same Idempotency-Key. |
conflict | Sometimes | Re-read the object and decide again. Never retry idempotency_key_reused with the same key. |
declined | No | The decision is final for that request. A new request is a new payment and runs the pipeline again. |
invalid_request, not_found, permission, authentication | No | Fix the request, the ID or the credential first. |
step_up_required | After a person confirms | Send the passkey assertion with the same request. |
The SDKs retry the retryable types for you (two retries by default) and always reuse the idempotency key, so a retried pay() can never pay twice. Network errors with no response are treated like timeout.
Getting help with an error#
Include the request_id when you contact support or open an issue. It is enough to find the request, the decision trace and any connector calls behind it. In the console, Developers, Request logs searches by request ID and shows the request and response bodies for 30 days.