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.

Accept a payment

The core Prudra integration is three middleware functions chained together on any Express route. walletMiddleware identifies which wallet receives payment. payMiddleware handles the 402 challenge and verification. vaultMiddleware creates the vault where your handler stores its output.
Dashboard support for managing paid endpoints is coming soon. Use the SDK or cURL to set up payment-gated routes.

Middleware parameters

walletMiddleware

ParameterTypeRequiredDescription
walletIdstringYesThe ID of the wallet that receives payment. BYO wallets: byw_.... Managed wallets: mwt_....
You can mount walletMiddleware globally (for all routes) or per-route. If mounted globally, it runs once for all routes. If mounted per-route, you can use different wallets for different endpoints.

payMiddleware

ParameterTypeRequiredDescription
pricestringYesThe payment amount in USD. e.g. "0.01" for $0.01.
descriptionstringNoHuman-readable description shown in payment UIs.
acceptSessionsbooleanNoEnable session payments. Requires Pro plan. Default: false.

vaultMiddleware

No required parameters. The vault is created automatically and attached to req.vault.

What gets set on req

After the middleware chain runs, your handler has access to:
PropertyTypeDescription
req.paymentobjectPayment details: protocol, amount, txHash, vaultId, paymentId, sessionId
req.vaultVaultThe vault instance. Call .addDocument(), .addFile(), .emit(), .seal(), .persist()
req.walletobjectThe wallet that received payment: id, address, chain
req.sessionIdstring | undefinedSet when the request is part of a session

The vault in your handler

The vault attached to req.vault is ready to use immediately. Common operations:
// Add a structured JSON document
await req.vault!.addDocument(
  { result: 'some data', processedAt: new Date() },
  'Document name'
);

// Upload a binary file
await req.vault!.addFile(
  fileBuffer,
  'output.pdf',
  'application/pdf'
);

// Emit a real-time event (subscribers see this via SSE)
await req.vault!.emit('progress', { percent: 50, message: 'Halfway done' });

// Seal the vault (read-only permanently)
await req.vault!.seal('Work complete');

// Get the full manifest (all documents + files with URLs)
const manifest = await req.vault!.getManifest();

Error handling

ErrorHTTP statusCauseResolution
payment-required402No payment credential in requestExpected — agent must pay
payment-verification-failed402Invalid payment credentialAgent’s signature or tx invalid
duplicate-payment409Same txHash used twiceReplay attack prevented
vault-quota-exceeded429Active vault limit reachedSeal existing vaults or upgrade
challenge-rate-limit429Too many challenges from this IPWait 60 seconds

Next steps