Skip to main content
The x402 protocol (an extension of the HTTP 402 Payment Required status) allows APIs to monetize individual endpoints by demanding a microtransaction before returning a resource. While x402 is powerful for agent-to-agent (A2A) commerce, existing implementations have two critical gaps:
  1. The wallet popup — every time an agent hits a paywall, the human user must manually confirm a transaction.
  2. Invisible to agents — endpoints using the official @x402 packages don’t appear in any agent directory until a human manually registers them.
@delegare/x402 solves both. It combines x402 with Intent Mandates for set-and-forget payments, and simultaneously emits discovery headers that make your endpoint automatically appear on Delegare Market (which aggregates across protocols), agentic.market (CDP Bazaar), and mppscan.com.

How It Works

1

Agent requests data

The agent calls POST /api/extract on the merchant’s server.
2

Merchant returns 402 challenge

The middleware responds with 402 Payment Required containing three parallel discovery payloads:
  • PAYMENT-REQUIRED header (base64 JSON) — x402 v2, read by CDP Bazaar and @x402/fetch clients
  • WWW-Authenticate: Payment ... header — MPP/RFC 7235, read by MPPScan and MPP-compatible wallets
  • JSON body — x402 v1, backward-compatible with older clients
3

SDK auto-pays via Delegare

@delegare/sdk intercepts the 402, verifies the amount is within the agent’s budget, and forwards the intent mandate to Delegare’s settlement infrastructure.
4

Settlement on Base

Delegare settles on Base L2 via the mandate’s session key and the DelegareRouter contract. USDC arrives directly in the merchant’s wallet. No popups.
5

Agent receives data

The agent retries with a payment credential. The middleware verifies it and returns the gated resource.
6

CDP Bazaar indexes the endpoint

On the first settlement via the CDP Facilitator (PAYMENT-SIGNATURE credential), CDP writes a catalog entry. The endpoint appears on agentic.market within ~10 minutes.

For Merchants: Monetizing APIs

Basic setup

Adding agent discovery

Use declareDiscoveryExtension before requireX402Payment to make your endpoint searchable on Delegare Market, agentic.market, and mppscan.com:

What the middleware handles

You never touch private keys or on-chain logic. USDC arrives directly in your wallet from the Base blockchain.

Required env vars for Bazaar indexing

When set, the middleware authenticates CDP settlement calls — required for the catalog write to succeed on first settlement.

Configuration reference

Accessing payment context

Read the x402 Middleware Documentation for the full configuration reference and fiat bundle setup.

For Agents: Seamlessly Paying Paywalls

Replace standard fetch calls with delegare.fetch. When the API returns a 402, the SDK resolves it automatically using the user’s intent mandate.

How the SDK resolves x402

  1. Makes the initial request.
  2. On 402, sends the intent mandate via X-DELEGARE-MANDATE.
  3. Merchant middleware forwards to Delegare for settlement.
  4. Delegare settles on-chain via the mandate’s KMS-encrypted session key.
  5. SDK returns the final response with the gated data.
The agent never holds private keys. The session key is scoped to the individual mandate — not accessible to the agent, merchant, or Delegare.

x402 v2 clients (@x402/fetch)

Agents using Coinbase’s @x402/fetch client send a PAYMENT-SIGNATURE credential. The middleware routes this to the CDP Facilitator, which also triggers Bazaar indexing on first settlement.

Model Context Protocol (MCP)

If your agent runs on MCP (Claude, ChatGPT, or any MCP-compatible client), the delegare_fetch tool handles x402 automatically:
No code required — the MCP server resolves the 402 challenge behind the scenes.

Discovery: How Agents Find Your API

declareDiscoveryExtension embeds metadata in every 402 response. Three directories index it: Delegare Market is the primary destination — it aggregates x402 and MPP endpoints from both upstream sources. Agents using the Delegare SDK or searching via Claude/ChatGPT tools query it in one request. All three read inputSchema and outputSchema from the metadata to show agents what parameters your endpoint accepts and what it returns.