Examples
Working examples grouped by evaluator outcome. Each is self-contained and runnable from the examples/ directory. See Start Here to find the right path for your use case.
Find the right example
HTTP 402 Payment Flow
A Node.js server that returns HTTP 402 Payment Required, accepts payment via x402, and issues Ed25519-signed PEAC receipts. Demonstrates the full Declare-Negotiate-Verify cycle.
- HTTP 402 response with payment details
- x402 payment verification
- Ed25519 receipt signing
- Receipt header in response
Pay-per-Inference
Shows how an AI agent handles 402 responses, obtains payment receipts, and retries requests with the PEAC-Receipt header. Includes retry logic and error handling.
- Agent-side 402 handling
- Receipt acquisition flow
- Retry with receipt header
- toCoreClaims() normalization
Pay-per-Crawl
Demonstrates how AI crawlers can evaluate publisher policies, respect access terms, and obtain receipts. Useful for compliance evidence and audit trails.
- Policy evaluation
- Purpose-based access control
- Receipt for audit trails
- Evidence generation for audit workflows
RSL Collective Licensing
Maps RSL (Robots Specification Language) tokens to PEAC ControlPurpose values. Shows how to integrate with collective licensing organizations.
- RSL token parsing
- ControlPurpose mapping
- Collective license integration
- Usage rights verification
MCP Paid Tools
Implements paid MCP tools with per-call and daily budget limits. Uses bigint minor units for precise currency handling.
- MCP tool integration
- Per-call pricing
- Budget enforcement
- Bigint minor units
OpenTelemetry Integration
Connects PEAC receipt issuance and verification to OpenTelemetry for observability. Supports privacy modes: strict, balanced, and custom attribute filtering.
- W3C Trace Context
- Privacy-preserving spans
- Metrics emission
- Custom attribute filtering
OpenClaw Interaction Evidence
Capture OpenClaw agent tool calls as signed PEAC interaction evidence receipts. Uses activate() for one-call setup with FileSpoolStore for durable storage.
- activate() one-call setup
- Two-stage pipeline
- FileSpoolStore durability
- Tamper-evident chain
MCP Server for AI Agents
Run the PEAC MCP server in Claude Desktop or Cursor to verify, inspect, decode, issue, and bundle receipts directly from AI agent conversations.
- peac_verify tool
- peac_inspect tool
- peac_issue (privileged)
- peac_create_bundle (privileged)
Paymentauth Evidence
Parse HTTP 402 challenges and receipts from the Payment authentication scheme. Demonstrates envelope-first parsing, raw artifact preservation, and coexistence with the PEAC-Receipt header.
- Challenge + Credential + Receipt parsing
- Raw + normalized dual representation
- Carrier coexistence with PEAC-Receipt
- receipt_ref via sha256(raw_header_value)
Paymentauth JSON-RPC
Demonstrates structured error handling for paymentauth in JSON-RPC transports including MCP. Uses error codes -32042 (payment required) and -32043 (payment failed).
- JSON-RPC error code -32042
- JSON-RPC error code -32043
- MCP extraction functions
- Structured error responses
ACP Session Lifecycle
Demonstrates the strict two-function boundary in ACP evidence: fromACPSessionLifecycleEvent for access evidence, fromACPPaymentObservation for commerce evidence with explicit observed_payment_state.
- Session lifecycle evidence
- Payment observation boundary
- Explicit observed_payment_state
- Commerce event only from payment artifacts
Stripe SPT Delegation
Shows how Stripe Payment Token delegation events (granted, presented, deactivated) are recorded separately from payment intent observations. Only fromStripePaymentIntentObservation produces commerce events.
- SPT delegation lifecycle
- Payment intent observation
- Explicit payment state requirement
- Settlement vs authorization mapping
Commerce Evidence Bundle
Bundle commerce evidence from multiple rails into a portable audit archive. Uses the experimental peac.commerce-bundle/0.1-experimental format with recursive stable serialization.
- Cross-rail evidence bundling
- Portable audit archive
- Deterministic serialization
- Offline verification
x402 Dual-Header Read
Demonstrates extractReceiptArtifactFromHeaders reading PEAC-Receipt, PAYMENT-RESPONSE (v2), and X-PAYMENT-RESPONSE (v1) headers with upstream artifact separation.
- v1/v2 header priority
- Upstream artifact separation
- receipt_jws vs upstreamArtifact
- isPeacReceipt discriminator
x402 Paid Resource Records
Observes a settled x402 offer/receipt pair (the Signed Offers and Receipts extension) and issues a signed org.peacprotocol/payment record that a customer, auditor, or dispute system can verify offline with only the issuer public key. Works behind any gateway or CDN that fronts x402. PEAC records and verifies; it does not settle, price, or gate access.
- Signed org.peacprotocol/payment record
- Offline verification from the issuer public key
- Reuses adapter-x402 offer/receipt verification
- Signature-tamper and settlement-digest-mismatch beats
MCP Paid Tool Records
Binds an MCP tool call (its name, a digest of its arguments, and a digest of its result) to the x402 settlement that paid for it, in a signed org.peacprotocol/payment record carried in the tool result _meta and verified offline. Only digests are recorded, never the raw arguments or results.
- Tool call bound to its settlement
- Argument and result digests only, no raw payloads
- Record carried in MCP _meta
- Offline verification from the carrier
Counterparty Acknowledgment Records
A payer signs a payment record; a provider signs its own record that acknowledges it by the full identity triple (issuer, jti, receipt_ref). Each record has exactly one issuer signature; this is not a countersignature envelope. PEAC does not countersign, arbitrate, or establish agreement; an acknowledgment reports only what the acknowledging party asserts.
- Two single-issuer signed records
- Linked by (iss, jti, receipt_ref)
- Correlation via parent_jti and depends_on
- Offline pair verification
Agent Run Lineage Records
Exports selected reported events from an agent run, plus a run-finalization record carrying signed coverage metadata, as offline-verifiable PEAC records, and checks them against an issuer-supplied run manifest. PEAC records what the runtime reports; raw prompts, model outputs, and tool inputs and outputs never appear in the manifest, records, or logs.
- Run events as agent-action records
- Signed run-finalization coverage metadata
- Consistency check against a run manifest
- No raw prompts, outputs, or credentials
Action Approval Records
Verifies that an issuer-reported invocation is linked to an approval (or denial) observation for the same action intent, with the reported approval time no later than the invocation time. PEAC records what an external system reported about approval, denial, and invocation; it does not request approval, determine authority, apply policy, or block execution.
- Approval, denial, and invocation observations
- Bound to a shared action-intent digest
- Temporal ordering check
- Records observations, does not gate execution
Clone the repository and run any example with a few commands:
# Clone the repository git clone https://github.com/peacprotocol/peac.git cd peac # Install dependencies pnpm install # Run an example cd examples/x402-node-server pnpm tsx demo.ts