Skip to content
ndStill is in development. These docs describe the v2 API as designed; the SDKs and the hosted MCP server are previews and not generally available.
Docs

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:

JSON
{
  "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"
}
FieldAlways thereWhat it is
objectYesAlways "error".
typeYesThe broad class. It decides the HTTP status and whether a retry can help. Branch on this first.
codeYesA specific machine code within the type, such as not_found, idempotency_key_reused or payment_declined. New codes can appear in any version.
messageYesWhat happened and what to do next, written for a person. Show it, but don't parse it.
decline_reasonsOn declinedThe reasons a payment was declined, in the same shape as a decision's reasons.
fieldsOn some invalid_requestField errors keyed by path, such as "amount.amount": "Must be positive".
docs_urlUsuallyA link to the part of these docs that explains the error.
request_idYesThe 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.

Error types
typeHTTPMeaning
invalid_request400The request is malformed or a field is invalid. fields maps each bad field to a message.
authentication401The key or token is missing, expired or revoked.
permission403The key, token or role isn't allowed to do this. Agents can never change their own policy, limits or freeze state.
not_found404No object with that ID in this org.
conflict409The object changed, already exists, or an Idempotency-Key was reused with a different body.
declined402The payment was declined. decline_reasons[] says why, stage by stage.
step_up_required400A person must confirm with a passkey first (org-wide freeze, policy activation, reveals). Retry with the assertion.
rate_limited429Too many requests. Wait for the Retry-After header.
upstream502A provider (card processor, bank, wallet) failed. Safe to retry with the same Idempotency-Key.
timeout504A provider didn't answer in time. Safe to retry with the same Idempotency-Key.
internal500Something failed inside ndStill. Quote the request ID.

A few notes on the types people ask about most:

  • step_up_required means 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 in step_up (or passkey_assertion on approvals).
  • conflict covers state that changed under you (approving a payment someone already rejected), saving a policy version that changes nothing, and reusing an Idempotency-Key with a different body (idempotency_key_reused).
  • upstream and timeout come 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.

OutcomeHTTP statusWhat you getWhat the agent should do
Approved200A payment intent with status approved (then authorized, settled)Use the credential or wait for the receipt.
Held200A payment intent with status held, an approval_id and reasons[]Wait for the approval, or tell its user it's waiting on a person.
Declined402An 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.

JSON
{
  "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.

Decline and hold reason codes
CodeStageExample message
agent_unknown1 IdentityThis agent isn't registered in the org.
key_revoked1 IdentityThe agent used a key that has been revoked.
passport_invalid1 IdentityThe agent's request signature didn't match its passport.
plan_limit2 Plan and go-liveThe org's plan limit for this has been reached.
verification_required2 Plan and go-liveThe org must finish verification before live payments.
sandbox_only2 Plan and go-liveThis agent can only make test payments.
agent_frozen3 Freeze checkTravel desk is frozen.
tree_frozen3 Freeze checkThe agent tree under Travel desk is frozen.
team_frozen3 Freeze checkTravel desk is frozen.
org_frozen3 Freeze checkEvery agent in the org is frozen.
credential_frozen3 Freeze checkThe credential used for this payment is frozen.
funding_frozen3 Freeze checkThe funding source Travel desk is frozen.
no_funding_access4 Funding sourceTravel desk isn't allowed to use Travel desk.
funding_insufficient4 Funding sourceTravel desk doesn't have enough available for $612.00.
mandate_missing6 Mandate matchNo signed mandate covers this payment.
mandate_amount_mismatch6 Mandate match$612.00 is above the mandate's limit of $600.00.
mandate_counterparty_mismatch6 Mandate matchThe mandate is for Delta Air Lines, but the agent is paying Acme Air.
mandate_expired6 Mandate matchThe mandate covering this payment has expired.
mandate_uses_exhausted6 Mandate matchThe mandate has already been used as many times as allowed.
over_per_payment_limit7 Policy rules$612.00 is over the $500.00 limit per payment.
blocked_counterparty7 Policy rulesAcme Air is on the block list.
blocked_category7 Policy rulesGambling purchases are blocked by policy.
outside_time_window7 Policy rulesPayments aren't allowed at this time of day by policy.
first_time_counterparty7 Policy rulesFirst payment to Acme Air; policy holds new sellers.
confidence_below_floor7 Policy rulesThe agent's confidence was below the policy's floor.
velocity8 Risk9 payments in 10 minutes is faster than usual for Travel desk.
spend_spike8 Risk$612.00 is far above Travel desk's usual payment.
loop_detected8 RiskThe agent sent the same request repeatedly; this looks like a loop.
off_hours8 RiskThe payment came outside this agent's usual hours.
price_drift8 RiskThe price drifted from what the mandate expected ($600.00).
stolen_key_signal8 RiskThe agent's key was used from an unfamiliar place.
sanctions_hit8 RiskAcme Air matched a sanctions list.
over_budget9 BudgetOver Travel desk's weekly budget by $112.00.
budget_nearly_exhausted9 BudgetThis would use the last of Travel desk's weekly budget.
approval_required_amount10 Approval threshold$612.00 is above the $250.00 approval line.
approval_required_counterparty10 Approval thresholdPayments to Acme Air always need approval.
approval_required_policy10 Approval thresholdPolicy requires a person to approve this payment.
rejected_by_personAfter the decisionRejected by Priya Shah: Not this vendor.
approval_expiredAfter the decisionNobody approved this in time, so it expired.
rail_errorAfter the decisionThe 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#

TypeRetry?How
rate_limitedYesAfter the Retry-After header, with the same Idempotency-Key.
upstream, timeout, internalYesExponential backoff with jitter (for example 0.5 s, 1 s, 2 s, up to 5 tries), same Idempotency-Key.
conflictSometimesRe-read the object and decide again. Never retry idempotency_key_reused with the same key.
declinedNoThe decision is final for that request. A new request is a new payment and runs the pipeline again.
invalid_request, not_found, permission, authenticationNoFix the request, the ID or the credential first.
step_up_requiredAfter a person confirmsSend 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.