This project is not covered by Drupal’s security advisory policy.

x402 Pay lets Drupal sell content and API calls to AI agents, and to people with a wallet, for USDC on Arc and Solana. It implements x402, the open protocol that puts the long-unused HTTP status 402 Payment Required to work: the site answers with a price, the client signs a payment, the site delivers. No accounts, no checkout, no card fees, payments of a fraction of a cent.

AI crawlers and agents already read your site. With x402 Pay they can pay for it.

Features

  • A price field for any entity. Add x402 price to nodes, products or any fieldable entity. Each field sells one view mode (the full text, a summary…) at a price, with per-entity overrides and a price per translation.
  • Agents pay, people browse. On the entity's own URL, agents get a 402 with the price while browsers still see the page. Every product also has its own URL, announced to agents with Link headers. Buyers get clean Markdown of what the view mode shows.
  • Markdown for agents, sold or free. Any page plus .md (/node/1.md, /es/terms.md) or Accept: text/markdown returns it as Markdown: free pages for free, sold ones charged. A block links each page's Markdown for people and agents.
  • What is sold is never given away. One gate, by entity, on every route that shows it: its page, .md, ?_format=, JSON:API, REST, Markdownify. Only an HTML page is free for people; JSON:API lists and includes omit sold entities and refuse filters that would leak them; sold pages are kept out of the page cache. Drupal's access checks are never bypassed: paying grants nothing beyond view access.
  • Paid APIs. The payment gate service charges any controller per request, and settles only when the response is successful: a failed call is never charged. An optional deadline means a sale the buyer left is not charged either.
  • Discovery for agents. /x402/discovery lists everything for sale in the format of Circle's Discovery API. For people, a Views filter and a price formatter.
  • Your rules at the time of sale. A PriceEvent lets code change the price, make it free, deny the sale or pick the seller's wallet; a DeliveryEvent lets it answer with anything, e.g. the result of a paid service; a PaymentEvent reports every outcome.
  • Settle your way, per network. Through Circle's facilitator (keyless trial or API key), the site's own facilitator (Drupal sends the buyer's signed transfer on chain itself, from a gas wallet that pays only the gas), or any other x402 facilitator by URL, which is how Solana settles. Sales always go from the buyer straight to the seller.
  • Money off the server. Sellers can be cold-wallet addresses with no key on the site, or seller keys can be swept to a cold wallet on cron.
  • A buyer too. The Buyer service and drush x402:buy <url> pay a 402 from PHP, on Arc or Solana, with a budget.
  • An audit trail. Every payment is logged with the entity sold, route, amount, payer and transaction hash, and the log is available in Views.
  • No Node.js, no npm. Everything is signed in PHP and tested byte for byte against reference vectors: no dependency tree we did not read gets near a wallet key.

Use cases

  • Charge AI crawlers and answer engines for articles, research or data, while humans keep reading for free.
  • Sell API calls (fact-checking, analysis, generation) to other agents, paid per call.
  • Build a marketplace where each listing pays its own seller.

Post-installation

  1. Store your keys with the Key module using the Environment provider (never Configuration: it ends up in config exports).
  2. Go to Configuration → Web services → x402 Pay and choose how each network settles: Circle (trial or API key), your own facilitator with a gas wallet, or another x402 facilitator by URL (Solana).
  3. Add an x402 price field to an entity type: set the price, network, seller (a key or an address) and the view mode it sells.
  4. Try it: BUYER_PRIVATE_KEY=0x… drush x402:buy https://your-site/node/1 --max=0.05 pays the 402 and prints what it bought.

Additional requirements

  • Drupal 11.1+ or 12, PHP 8.3+ with the gmp and sodium extensions.
  • Key.
  • Composer libraries: kornrunner/keccak, kornrunner/secp256k1, league/html-to-markdown.
  • USDC on Arc or Solana for buyers; for the own facilitator, a gas wallet with a little USDC on Arc.
  • Wallet Auth: sign in with an Ethereum (SIWE) or Solana (SIWS) wallet, for people and agents, so purchases and prices can attach to an account.

Similar projects

We know of no other x402 module for Drupal. Payment gateways for Drupal Commerce charge people through a checkout; x402 Pay charges per request, without accounts, and works for agents. Markdownify also serves Markdown and can be enabled alongside: x402 Pay charges what is sold through its routes too.

Known limits

  • A Views REST export lists sold entities for free: do not build one over what you sell.
  • A file's bytes are served by its URL, sold or not.
  • Pages showing what is sold are not cached until there is a cache that varies by payment.

Why, and what was chosen instead: DECISIONS.md.

Roadmap

  • Drupal Commerce gateway: check out in USDC (x402_pay_commerce).
  • ECA integration for the price rules (x402_pay_eca).
  • A page cache that varies by payment.
  • More networks: other EVM chains.
  • Smart-contract wallet signatures (ERC-1271) in the own facilitator.

Background

Built for Ombú, an open-source marketplace on Drupal where AI agents sell to people and to other agents. Development happens on GitHub; issues are welcome here on drupal.org.

Supporting organizations: 

Project information

Releases