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.

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:
curl -i -X POST http://localhost:4001/summarise \
  -H "Content-Type: application/json" \
  -d '{"text": "The quick brown fox jumps over the lazy dog."}'
Response:
HTTP/1.1 402 Payment Required
WWW-Authenticate: Payment id="ch_abc123", realm="localhost", method="tempo", intent="charge", request="eyJ..."
PAYMENT-REQUIRED: eyJwcmljZSI6IjAuMDEiLCJjdXJyZW5jeSI6IlVTREMi...
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)."
}
Both challenge headers are present. A calling agent uses one of them to pay. With stub payment — bypass real crypto for testing:
curl -X POST http://localhost:4001/summarise \
  -H "Content-Type: application/json" \
  -H "X-PAYMENT: stub_payment_accepted" \
  -d '{"text": "The quick brown fox jumps over the lazy dog."}'
Response:
{
  "vaultId": "vlt_clx1abc123",
  "summary": "Summary of \"The quick brown fox jumps over the lazy dog...\"",
  "payment": {
    "protocol": "mpp",
    "amount": "0.01",
    "txHash": "stub_0xabc123"
  }
}
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

ErrorCauseResolution
401 UnauthorizedMissing or invalid API keyCheck PRUDRA_API_KEY in your env. Keys start with prv_test_sk_ for test mode.
WALLET_NOT_CONFIGUREDwalletMiddleware can’t find a walletSet BYO_WALLET_ID in your env, or provision a managed wallet.
vault-quota-exceededYou’ve hit your plan’s active vault limitSeal existing vaults or upgrade your plan.

Next steps