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
- Agent makes a normal HTTP request to an API endpoint
- Server returns HTTP 402 Payment Required with an
X-AMROOD-PAYheader containing payment instructions (amount, payee, nonce) - Agent pays the specified payee via Amrood’s
POST /v1/agents/{id}/payendpoint, using the nonce as the payment reference - Amrood returns a transaction ID
- Agent retries the original request with an
X-AMROOD-PAYMENTheader containing the transaction proof - Server verifies the payment via Amrood’s verification endpoint
- Amrood confirms the payment is valid
- Server returns the requested resource
For API Developers (Server Side)
Install theamrood-paywall package:
AMROOD_AGENT_KEY environment variable to your agent’s API key so the server can verify incoming payments.
How the decorator works
- On first request (no payment proof), returns HTTP 402 with:
- On retry with
X-AMROOD-PAYMENTheader, verifies the payment viaGET /v1/transactions/{txn_id}/verify - If verified, passes the request through to your endpoint
- Nonces are tracked to prevent replay attacks (one payment = one access)
Configuration
For AI Agents (Client Side)
Using the MCP tool
Theamrood_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: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.