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

x402 and USDC

Pay HTTP 402 challenges from an agent wallet, with a decision before the wallet signs.

x402 lets an HTTP server ask for payment with the status code it was always meant to use: 402 Payment Required. The server answers with a machine-readable challenge, the client pays in USDC and retries with proof of payment. It suits agents well, because paying for an API call becomes part of calling the API. It also removes the human from the loop entirely, which is exactly why ndStill puts a decision in front of the wallet's signature.

The flow in one picture#

An agent calls a paid API. Without ndStill, the wallet would sign whatever the challenge asks for. With ndStill, the SDK's x402 hook catches the challenge and asks for a decision first:

  1. The seller answers 402

    The API returns 402 Payment Required with a challenge: amount, asset, network, payTo address, resource and scheme.

  2. The hook asks ndStill

    The ndStill SDK reads the challenge and sends it for a decision with the agent's key. The pipeline runs: freeze, funding, counterparty (the payTo address and the API host resolve to a known seller where they can), mandate, policy, risk, budget and the approval line.

  3. ndStill returns a payment approval token

    If approved, ndStill reserves the amount in every budget in scope and returns a signed payment approval token. It is bound to the amount, the payTo address, the resource and a nonce, and is valid for 60 seconds.

  4. Only then does the wallet sign

    The hook releases the payment to the wallet. Your wallet (or the ndStill wallet, see below) signs the transfer and the client retries the request with the payment attached.

  5. The receipt closes the loop

    After the seller responds, the hook sends the response hash to ndStill. The reservation is posted at the final amount, a signed receipt is written, and the evidence record holds the challenge, the decision and the response.

  • Passed
  • Held here
  • Declined here
  • Not on this rail
  • Not reached
A $0.01 search call that passes every stage: below the line where the policy asks for a mandate, inside the per-call cap and the daily budget.

What a challenge looks like#

This is the x402 version 1 shape. A seller using ndStill Accept also adds a WWW-Authenticate: Payment header and an ndstill block that tells agents how the seller verifies them:

HTTP
HTTP/1.1 402 Payment Required
Content-Type: application/json
Cache-Control: no-store
WWW-Authenticate: Payment realm="api.example.com", methods="x402"

{
  "x402Version": 1,
  "error": "Payment required",
  "accepts": [
    {
      "scheme": "exact",
      "network": "base",
      "asset": "USDC",
      "maxAmountRequired": "10000",
      "payTo": "0x4b1f6c2e9a0d3b5f7e8c1a2d4f6b8e0c2a4d6f81",
      "resource": "https://api.example.com/v1/search",
      "description": "One search across the index",
      "mimeType": "application/json",
      "maxTimeoutSeconds": 60
    }
  ]
}

Amounts in x402 are atomic units of the asset. USDC has 6 decimals, so "10000" is 0.01 USDC. ndStill keeps the same convention: money is always an integer in the asset's minor units, so the decision sees { "amount": 10000, "asset": "USDC" }. Budgets in USD count USDC at par.

Build and inspect challenges, and see how an agent would decide on them, in the 402 challenge builder.

Adding the hook#

The SDKs wrap your HTTP client. The hook only acts on a 402 response; every other response passes through untouched.

import { NdStill } from "@ndstill/sdk";

const ndstill = new NdStill({ apiKey: process.env.NDSTILL_API_KEY });

// fetch that pays x402 challenges only after ndStill approves them
const paidFetch = ndstill.x402.wrapFetch(fetch, {
  agent: "agt_01JD8X4N2Q",
  wallet, // your wallet signer (Coinbase CDP, Privy, viem, ...)
});

const res = await paidFetch("https://api.example.com/v1/search?q=agent+payments");
if (res.status === 402) {
  // ndStill held or declined the payment; the reasons are attached
  const decision = ndstill.x402.decisionFrom(res);
  console.log(decision.status, decision.reasons.map((r) => r.message));
}

Over MCP, the same step is the pay_402 tool: the agent passes the challenge it received, and gets back an approval token or a held or declined result with reasons. See MCP tools.

Held and declined challenges#

A 402 that ndStill doesn't approve never reaches the wallet. The hook returns the original 402 to your code with the decision attached:

  • Declined: the reasons are written for people and carry machine codes, for example over_budget ("Over Research agent's daily budget by $0.40") or blocked_counterparty.
  • Held: a person must approve. The decision carries an approval_id. The challenge's own timeout (maxTimeoutSeconds) is usually shorter than a human takes, so a held 402 typically means retrying the call after approval rather than waiting inline.

Loops are a common x402 failure: an agent retries the same paid call again and again. The risk stage watches for repeated request hashes and holds the payment with loop_detected, so a bug costs cents, not a day's budget.

Policies for paid APIs#

Paid APIs are many small payments, so per-call caps and daily budgets matter more than approval lines:

YAML
version: "2026-11-01"
budgets:
  - { amount: { amount: 2000, asset: USD }, window: day }       # $20 a day
  - { amount: { amount: 30000, asset: USD }, window: month }    # $300 a month
limits:
  per_payment: { amount: 50, asset: USD }                        # $0.50 per call
rails:
  allow: [stablecoin]
risk:
  velocity_per_10m: 120
approvals:
  new_counterparty: true                                         # first payment to a new API waits for a person

The Policy cookbook has a full API-buying recipe, and you can run it against sample payments in the Policy playground.

Three ways to hold the wallet#

Wallet setups
SetupHow ndStill controls signingLevel
Your wallet, client-side hookThe SDK asks ndStill before the wallet signs. Strong in practice, but it runs in your process: code that bypasses the SDK can still sign.Authorize (client-side)
Your wallet, provider policy APIFor wallets with a policy engine (for example Coinbase CDP, Privy, Turnkey, Safe), ndStill writes limits into the wallet's own policy as a backstop.Authorize or Issue, per provider
ndStill walletA per-agent USDC wallet held with a regulated custodian (MPC or custodial). The custodian only signs with ndStill's co-signature, which ndStill gives only against an approved decision.Authorize (enforced by the custodian)

The Wallets API shows each wallet's policy_binding.mode (co_sign, policy_api or client_hook) and the rules the custodian enforces natively.

On the seller's side#

If you sell an API to agents, ndStill Accept issues the 402 challenge, verifies the agent's passport signature, checks the idempotency key and returns a signed receipt. Settlement goes through an x402 facilitator into your own wallet; ndStill never holds the funds. See Verify for sellers and the Prices API.