v0.9.236 examples

Examples

Working examples demonstrating common PEAC integration patterns. Each example is self-contained and runnable from the examples/ directory.

server

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
@peac/protocol@peac/rails-x402@peac/crypto
View on GitHub
agent

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
@peac/protocol@peac/mappings-mcp
View on GitHub
crawler

Pay-per-Crawl

Demonstrates how AI crawlers can evaluate publisher policies, respect access terms, and obtain receipts proving compliant access. Useful for EU AI Act compliance.

  • Policy evaluation
  • Purpose-based access control
  • Receipt for audit trails
  • Compliance proof generation
@peac/policy-kit@peac/protocol
View on GitHub
integration

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
@peac/mappings-rsl@peac/control
View on GitHub
agent

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
@peac/mappings-mcp@peac/protocol
View on GitHub
observability

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
@peac/telemetry-otel@peac/protocol
View on GitHub
Running the Examples

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