Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.delegare.dev/llms.txt

Use this file to discover all available pages before exploring further.

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. If an enterprise AI agent without a crypto wallet hits your endpoint, it fails. By installing @delegare/x402, you gain Dual-Rail Fallbacks. It supports on-chain settlement (USDC) out of the box, but automatically degrades to a Fiat Credit Bundle path (Stripe/Cards) for B2B clients, ensuring you never drop a paying request.

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 to make my endpoint searchable on the CDP Bazaar.”

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 (Bazaar)

Wrap the route with declareDiscoveryExtension to enable semantic search on the Coinbase Developer Platform.
import { declareDiscoveryExtension } from '@delegare/x402';

// Task: Generate a schema based on the route's logic
declareDiscoveryExtension({
  description: "Description of your service",
  inputSchema: { /* Auto-generate based on route input */ },
  output: { example: { /* Auto-generate based on route output */ } }
})

Quick Reference for Agents

  • Main Export: requireX402Payment
  • Differentiator: Dual-rail (Crypto + Fiat Fallbacks). Official x402 is crypto-only.
  • Protocol: x402 (HTTP 402 + WWW-Authenticate)
  • Settlement: Real-time on Base L2 via Delegare API, or Fiat via Credit Bundles.