Skip to main content

Your first payment in 5 minutes

This guide walks you through adding a payment-gated endpoint to an Express server using Prudra. By the end, you’ll have a working endpoint that returns HTTP 402 when called without payment, accepts payment via either x402 or MPP, creates a vault, and returns the vault ID in the response. You’ll use stub mode for testing — no real wallet or crypto needed.
Dashboard support for creating paid endpoints is coming soon. Follow the API/SDK steps to get started.

Test the endpoint

Without payment — expect HTTP 402:
Response:
Both challenge headers are present. A calling agent uses one of them to pay. With stub payment — bypass real crypto for testing:
Response:
The vaultId is the ID of the vault that was created for this payment. Your agent can use it to retrieve the result later via GET https://api.prudra.dev/vaults/<vaultId>.
Stub mode (X-PAYMENT: stub_payment_accepted) only works when PAYMENT_STUB_MODE=true is set on the server. This is the default in development. Never enable stub mode in production.

What happened

  1. The walletMiddleware attached your wallet to the request context — payment goes to that wallet
  2. The payMiddleware checked for a payment credential
  3. Without one, it generated both an x402 and MPP challenge and returned 402
  4. With the stub payment, it skipped real verification and proceeded
  5. The vaultMiddleware created a new vault and attached it to req.vault
  6. Your handler ran, wrote a document to the vault, sealed it, and returned the vault ID

Error handling

Next steps