Skip to main content

HTTP 402 Paywall

Amrood supports an x402-style payment protocol over HTTP — any API can charge per-call in INR, and AI agents with Amrood wallets can pay automatically. This brings the machine-to-machine payment model of x402 to fiat currency.

How It Works

Step by step

  1. Agent makes a normal HTTP request to an API endpoint
  2. Server returns HTTP 402 Payment Required with an X-AMROOD-PAY header containing payment instructions (amount, payee, nonce)
  3. Agent pays the specified payee via Amrood’s POST /v1/agents/{id}/pay endpoint, using the nonce as the payment reference
  4. Amrood returns a transaction ID
  5. Agent retries the original request with an X-AMROOD-PAYMENT header containing the transaction proof
  6. Server verifies the payment via Amrood’s verification endpoint
  7. Amrood confirms the payment is valid
  8. Server returns the requested resource

For API Developers (Server Side)

Install the amrood-paywall package:
Add a one-line decorator to any FastAPI endpoint:
Set the AMROOD_AGENT_KEY environment variable to your agent’s API key so the server can verify incoming payments.

How the decorator works

  1. On first request (no payment proof), returns HTTP 402 with:
  2. On retry with X-AMROOD-PAYMENT header, verifies the payment via GET /v1/transactions/{txn_id}/verify
  3. If verified, passes the request through to your endpoint
  4. Nonces are tracked to prevent replay attacks (one payment = one access)

Configuration

For AI Agents (Client Side)

Using the MCP tool

The amrood_http_pay tool handles the entire 402 flow automatically:

Using the API directly

If you’re building a custom client:

Transaction Verification API

The verification endpoint allows API servers to confirm that a payment was made:
Headers:
Response:
The calling agent must be the payee (recipient) of the transaction. This prevents unauthorized balance snooping.

Verification checks

Protocol Headers

X-AMROOD-PAY (Server → Client)

Sent with HTTP 402 responses. Base64-encoded JSON:

X-AMROOD-PAYMENT (Client → Server)

Sent on retry after payment. Base64-encoded JSON:

Security

  • Nonce replay protection — each nonce can only be used once. The server tracks used nonces with a TTL.
  • Payee-only verification — only the payee can call the verify endpoint, preventing unauthorized transaction lookups.
  • Amount validation — the verify endpoint checks that the paid amount meets or exceeds the expected amount.
  • Standard Amrood policies apply — spend limits, allowed payees, and all other guardrails are enforced on the underlying payment.