When an agent pays for API calls on its own, the questions come later. Which rules was it running under? What did it check before it paid? What exactly did it pay, to whom, and did the seller deliver what it says it delivered?

A payment log answers part of that, but only if you trust whoever wrote the log. This post shows one way to keep a single JSON file per payment that anyone can check again, without trusting the agent that wrote it.

I maintain the open-source tool used here (@agent402-dev/pay-mcp, Apache-2.0, version 0.16.1 or later). Building and checking a bundle signs nothing and pays nothing.

The idea in one table

A "proof bundle" is one JSON object per payment:

Field What it holds
policyHash SHA-256 of the spending rules (allowed hosts, trusted recipients, limits) as sorted JSON. Same rules, same hash.
agent (optional) The buyer's 8004 agent identity, if it has one
preflight (optional) What was checked before paying: the URL, how many things needed fixing (0 = clean) and their codes
payment Resource URL, network, asset, amount in smallest units, recipient, transaction, time
receipt (optional) The seller's signed X-Agent402-Receipt header, when the seller sends one

The hash ties the payment to the rules that were in force. The receipt ties the payment to what the seller says it returned. The transaction ties both to the chain.

Step 1: pay as usual

The agent pays through the x402_fetch tool under your rules: X402_ALLOWED_DOMAINS, X402_TRUSTED_PAY_TO and the per-payment and daily limits. (If you have not set those up yet, the earlier post on spending caps walks through them.)

The tool's result carries the payment (network, mint, amount, payTo, settlementTx) and, when the seller signs receipts, receipt.token. The same payment is also in payment_history.

Step 2: build the bundle

import { buildProofBundle } from '@agent402-dev/pay-mcp/proof-bundle'; import { policyFromEnv } from '@agent402-dev/pay-mcp/policy'; const bundle = await buildProofBundle({ policy: policyFromEnv(process.env), // the same X402_* rules the agent ran with payment: { resource, network, asset: mint, amount, // integer string, smallest units payTo, transaction: settlementTx, at: new Date().toISOString(), }, receipt: receiptToken, // optional }); 

A malformed amount or at is refused when the bundle is built, so a bad record fails early instead of at audit time. Start-up warnings are not part of the rules and do not change the hash.

Write bundle to a file next to whatever the agent produced with the paid response.

Step 3: check it, now or months later

npx -y @agent402-dev/pay-mcp verify-proof --bundle proof.json --rules-from-env 

It prints each check and exits 0 when all pass, 1 when one fails and 2 when the file cannot be read, so it drops into CI or a cron job. What it checks:

  • the bundle's format;
  • with --rules-from-env: the rules hash matches the X402_* rules in this environment, and the resource host and recipient were allowed by them;
  • preflight reported nothing to fix, when it is present;
  • the receipt signature, and that the receipt's payment fields equal the bundle's;
  • the payment on chain (Solana), through the receipt. --rpc <url> picks the RPC; --no-chain skips this step.

The part I care most about: anything it could not check is listed under notChecked instead of being counted as a pass. No rules given, no receipt in the bundle, and so on. A green result never hides a step that did not run.

What it does not prove

  • It records what your side did. It does not prove the response was good, only what the receipt binds: the request, a hash of the response body, and the payment.
  • There is no user signature over the rules. The hash shows which rules were in place, not who approved them.
  • A receipt shows which key signed it. Whether that key belongs to the seller is for the seller to publish.
  • x402_fetch does not build bundles for you; you build them from its result.

Why bother

If agents end up making many small payments without a person watching each one, "the agent's log says so" will not be enough for whoever reviews the spending. A file that can be re-checked against the rules, the seller's signature and the chain is a small step toward payments you can check rather than trust.

The full guide, with the same steps, is in the repository: https://github.com/agent402-dev/agent402-toolkit/blob/main/docs/guides/payment-proof-bundle.md

Internal review only, not independently audited.