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.

Vaults overview

A vault is a scoped container attached to a single payment. When vaultMiddleware runs on a request with a valid payment, it creates a vault and attaches it to req.vault. Your handler writes results into the vault and seals it when done. The caller retrieves results by reading vault contents.

Vault states

StateWrites allowedTTL countdownCaller reads
activeYesRunningYes
sealedNoRunningYes
persistedNoPausedYes
expiredNoNo

Using vaultMiddleware

vaultMiddleware creates the vault automatically. Add it after payMiddleware in your middleware chain:
import { initialise } from '@prudra/core';
import { walletMiddleware, payMiddleware, vaultMiddleware } from '@prudra/express';

initialise({ apiKey: process.env.PRUDRA_API_KEY! });

app.post(
  '/analyse',
  walletMiddleware({ walletId: 'mwt_clx1abc123' }),
  payMiddleware({ price: '0.10', description: 'Analysis' }),
  vaultMiddleware(),
  async (req, res) => {
    const vault = req.vault!;

    // Write results
    await vault.addDocument({ result: 'analysis complete' }, 'Analysis result');
    await vault.seal('Analysis finished');

    res.json({ vaultId: vault.id });
  }
);

Vault object methods

MethodDescription
vault.idVault ID (vlt_...)
vault.addDocument(data, label)Store a JSON document
vault.addFile(buffer, name, mimeType)Store a binary file
vault.emit(type, payload)Emit a real-time SSE event
vault.seal(summary)Close the vault for writes
vault.persist()Extend vault beyond its TTL
vault.getManifest()Retrieve all documents and file URLs

Sub-pages

Create a vault

Vault creation options and manual creation without middleware.

Access control

Vault access tokens for sharing read access.

Seal a vault

Mark work complete and close a vault for writes.

Persist a vault

Extend vault lifetime beyond its TTL.

Query vaults

List and filter vault records.

TTL and expiry

How TTL works and how to extend it.

Delete a vault

Explicitly delete a vault and free quota.

Vault quota

Monitor active and persisted vault counts against plan limits.