Skip to main content
The @delegare/x402 package lets merchants monetize API endpoints using the x402 protocol while crucially implementing Google’s AP2 (Agentic Payment Protocol). This guarantees secure, autonomous transactions where the AI agent never holds private keys, credit card credentials, or raw funds. Instead, agents operate strictly via pre-authorized intent mandates (SD-JWT-VC). Beyond security, it handles the 402 challenge, payment verification, and settlement across multiple payment rails, and automatically embeds discovery metadata. This makes your endpoint seamlessly indexable on Delegare Market, agentic.market (CDP Bazaar), and mppscan.com (MPP) — one middleware, zero exposed credentials, three directories.

🔒 Secured by Google’s AP2 Protocol

Traditional agentic payments force developers to provision wallets with live funds or inject raw credit card details into the LLM context window—a massive security vulnerability. @delegare/x402 natively implements Google’s AP2 (Agentic Payment Protocol):
  1. No Keys in Context: Agents are issued an Intent Mandate (SD-JWT-VC) rather than returning raw card details or wallet seeds.
  2. Bounded Authority: Mandates define strict, server-side enforced spending limits and permitted rails.
  3. Zero-Trust Validation: The middleware cryptographically verifies the mandate before settling the payment on-chain or via fiat fallbacks.

Installation

Quick Start

Dual-Rail Payments (Fiat Fallback)

Not all agent developers have a crypto wallet. Configure a Credit Bundle Fallback to add a Stripe-backed fiat path alongside the crypto path.
Clients pay once via Stripe, receive a bundle token, and send it via X-Bundle-Token to bypass crypto.

Agent Discovery (Delegare Market, CDP Bazaar + MPPScan)

Use declareDiscoveryExtension to make your endpoint automatically discoverable on Delegare Market, agentic.market, and mppscan.com. Place it before requireX402Payment. The metadata is embedded in both the PAYMENT-REQUIRED header (x402 v2, read by CDP Bazaar) and the WWW-Authenticate header (MPP/RFC 7235, read by MPPScan) on every 402 response.
output.schema is required (not just example) for CDP Bazaar to accept the index entry. Without it, the validator will report “schema is invalid” even if all other checks pass.

How Bazaar Indexing Works

CDP Bazaar indexes your endpoint the first time a PAYMENT-SIGNATURE credential is settled through their facilitator. The middleware handles this automatically:
  1. An agent hits your endpoint with PAYMENT-SIGNATURE (x402 v2 credential from @x402/fetch)
  2. The middleware passes the full payment payload — including your declareDiscoveryExtension metadata — directly to CDP’s /settle endpoint
  3. CDP settles on-chain and writes the catalog entry
  4. Your endpoint appears on agentic.market within ~10 minutes
To trigger indexing for existing endpoints without waiting for organic traffic, use the @x402/fetch client with your own wallet to make one test payment per endpoint. See the CDP Bazaar docs for details.

Required Environment Variables for Bazaar

When set, the middleware automatically authenticates CDP settlement calls with a signed JWT — required for Bazaar catalog writes.

What the 402 Response Emits

Every unauthenticated request receives three parallel discovery headers: Plus a JSON body for backward-compatible x402 v1 clients.

Payment Rails (Priority Order)

The middleware accepts five types of payment credentials in this order:

Configuration

Accessing Payment Context

Testing with Sandbox