Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.prudra.dev/llms.txt

Use this file to discover all available pages before exploring further.

Add x402 to an endpoint

payMiddleware accepts x402 by default as part of its dual-protocol behaviour. The standard configuration works with all x402-compatible agents without any additional options.
Dashboard support for managing paid endpoints is coming soon. Use the SDK to configure x402 on your routes.

What the 402 response looks like

When a request arrives without payment, payMiddleware returns:
HTTP/1.1 402 Payment Required
PAYMENT-REQUIRED: eyJwcmljZSI6IjAuMDUiLCJjdXJyZW5jeSI6IlVTREMi...
WWW-Authenticate: Payment id="ch_abc123", realm="your-api.com", ...
Cache-Control: no-store
Content-Type: application/problem+json

{
  "type": "https://api.prudra.dev/problems/payment-required",
  "title": "Payment Required",
  "status": 402,
  "detail": "See WWW-Authenticate (MPP) or PAYMENT-REQUIRED (x402)."
}
The PAYMENT-REQUIRED header is the x402 challenge. An x402 agent decodes it, signs an ERC-3009 authorization, and resubmits with PAYMENT-SIGNATURE.

What the 200 response includes

After successful x402 payment:
{
  "vaultId": "vlt_clx1abc123",
  "result": "...",
  "payment": {
    "protocol": "x402",
    "amount": "0.05",
    "txHash": "0xabc..."
  }
}
The response also includes the PAYMENT-RESPONSE header with settlement details — see Handle the payment response.

payMiddleware options

ParameterTypeRequiredDescription
pricestringYesPayment amount in USD. e.g. "0.05"
descriptionstringNoHuman-readable description of the endpoint
acceptSessionsbooleanNoEnable session payments (MPP only). Default: false

Error handling

ErrorStatusCause
payment-verification-failed402Invalid signature or expired credential
duplicate-payment409Same nonce used twice (replay attack blocked)
challenge-rate-limit429More than 20 challenge requests/IP/60s

Next steps