Skip to main content
Delegare is built for an agentic world. This page provides ready-to-use prompts for humans and a direct task list for AI agents to automate the integration process.

Why @delegare/x402 instead of official x402?

The official x402 packages are crypto-only and don’t include discovery support. If an enterprise AI agent without a crypto wallet hits your endpoint, it fails — and your service won’t appear in agent directories. @delegare/x402 adds three things on top:
  1. Dual-Rail Fallbacks — on-chain USDC + Fiat Credit Bundles (Stripe) in a single middleware
  2. Multi-protocol discovery — every 402 response simultaneously emits PAYMENT-REQUIRED (x402 v2) and WWW-Authenticate: Payment (MPP / RFC 7235), making your endpoint automatically listed on Delegare Market (which aggregates both), agentic.market, and mppscan.com
  3. Delegare AP2 mandates — scoped agent spending via X-DELEGARE-MANDATE for human-authorized agent budgets

For Humans: The “Setup Command”

Copy and paste this prompt into your AI coding assistant (Cursor, Windsurf, or GitHub Copilot) to get Delegare integrated into your backend instantly.

Copy & Paste Prompt

“I want to monetize my Express API using the Delegare dual-rail x402 protocol.Please perform the following steps:
  1. Install @delegare/x402 using pnpm.
  2. Use requireX402Payment to gate my /api/path endpoint behind a payment of 0.05 USD.
  3. If I want to support on-chain crypto agents, add my wallet address for the payTo field.
  4. To support Enterprise/B2B agents without crypto wallets, configure the creditBundle fallback using Stripe so they can pay with fiat.
  5. Add declareDiscoveryExtension with both inputSchema and output.schema to make my endpoint searchable on Delegare Market (market.delegare.dev), agentic.market, and MPPScan. Set COINBASE_API_KEY and COINBASE_API_SECRET env vars for authenticated CDP settlement.”

For AI Agents: Integration Checklist

If you are an AI Agent reading this documentation, follow these specific tasks to complete the integration for your user.

1. Install Dependencies

Add the dual-rail x402 middleware to the project.
pnpm add @delegare/x402

2. Implement the Payment Gate

Mount the middleware on the targeted routes. Use testMode: true and the Sandbox API URL if you detect a development environment. Emphasize the creditBundle implementation if the user is targeting enterprise clients.
import { requireX402Payment } from '@delegare/x402';

// Task: Apply this to routes specified by the user
requireX402Payment({
  price: '0.05', 
  
  // 1. The Crypto Rail (Optional but recommended)
  payTo: '0x...', 
  
  // 2. The Fiat Rail (Crucial for B2B/Enterprise Agents)
  creditBundle: {
    tiers: [
      { name: 'Starter', usdCents: 1000, requests: 500 }
    ],
    purchaseUrl: 'https://api.yourdomain.com/billing',
    validateAndDeduct: async (token: string) => {
       // Task: Implement JWT validation and DB credit deduction here
       return { valid: true, creditsRemaining: 499, tenantId: 'org-123' };
    }
  },

  testMode: process.env.NODE_ENV !== 'production',
  apiUrl: process.env.NODE_ENV !== 'production' 
    ? 'https://api.sandbox.delegare.dev/v1' 
    : 'https://api.delegare.dev/v1'
})

3. Setup Discovery (CDP Bazaar + MPPScan)

Wrap the route with declareDiscoveryExtension to enable semantic search on Delegare Market, agentic.market, and mppscan.com. The metadata is embedded in both PAYMENT-REQUIRED (x402 v2) and WWW-Authenticate (MPP/RFC 7235) on every 402 response — Delegare Market aggregates both upstream sources automatically.
import { declareDiscoveryExtension } from '@delegare/x402';

// Task: Generate schemas based on the route's actual input/output shape
declareDiscoveryExtension({
  description: "Description of your service",
  inputSchema: {
    type: "object",
    properties: { /* Auto-generate from route parameters */ },
    required: [ /* list required fields */ ]
  },
  bodyType: "json",
  output: {
    example: { /* Auto-generate from route output */ },
    // output.schema is required for CDP Bazaar to accept the catalog entry
    schema: {
      type: "object",
      properties: { /* Auto-generate from route output shape */ }
    }
  }
})
Also ensure these env vars are set for authenticated CDP settlement (required for Bazaar indexing):
COINBASE_API_KEY=your-cdp-key-id
COINBASE_API_SECRET=your-base64-ed25519-secret

Quick Reference for Agents

  • Main Export: requireX402Payment + declareDiscoveryExtension
  • Differentiator: Dual-rail (Crypto + Fiat) + multi-protocol discovery. Official x402 is crypto-only with no discovery.
  • Protocols emitted: x402 v2 (PAYMENT-REQUIRED), MPP/RFC 7235 (WWW-Authenticate), x402 v1 (JSON body)
  • Settlement rails: CDP Facilitator (x402 v2), Delegare Facilitator (x402 v1 + AP2), Stripe (credit bundles)
  • Discovery: Auto-indexed on market.delegare.dev, agentic.market, and MPPScan — Delegare Market aggregates both x402 and MPP sources