This module enables your Drupal site to sell content and API calls using the x402 protocol, allowing AI agents and users with wallets to pay with USDC on Arc. It supports per-entity pricing, offers content in clean Markdown to buyers, and allows for paid APIs that only charge for successful responses.
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.
What's new in 1.0.0-beta5
- A stop switch pauses every payment at once.
drush x402:stop on "why", or the Pause payments tab of the settings: a paid request is answered503 payments_pausedbefore anything is verified, claimed or charged, and the site buys nothing. It has its own permission, Pause and resume x402 payments, so whoever is on call can stop the money without being able to change where it goes. - A malformed payment is refused, not an error. A payment whose
nonceor payer ended in a newline made a paid URL answer 500. Anybody could cause it, with no funds; nothing was charged or delivered. It is now a plain 402invalid_payload. - Runs on quebracho/x402 ^0.5.1 (MIT, from Packagist). Code written for 1.0.0-beta2 keeps working: the old classes stay as deprecated wrappers until 2.0.0.
- Updating: no database update in this release; run
drush cr. Grant Pause and resume x402 payments to whoever must be able to stop payments.
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
Linkheaders. 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) orAccept: text/markdownreturns 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/discoverylists 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
PriceEventlets code change the price, make it free, deny the sale or pick the seller's wallet; aDeliveryEventlets it answer with anything, e.g. the result of a paid service; aPaymentEventreports 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 library's
PayingHttpClientanddrush x402:buy <url>pay a 402 from PHP, on Arc or Solana, with a budget. - An audit trail you can verify. Every payment is logged with the entity sold, route, amount, payer (the signer) and transaction hash, and the log is available in Views. Cron and
drush x402:reconcilecheck it against the chain. - 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.
- Sanctions screening. Payers on OFAC's SDN list are refused before any money moves. The list is refreshed daily by cron.
- A stop switch. One command, or one tab with its own permission, pauses every sale and every purchase at once, for when something looks wrong and the money has to stop before you know why. Two switches, either of which pauses: a flag file that needs no database, and a value in the database that reaches every web server.
- The log is checked against the buyer's signature, not the facilitator's word. A sale counts as paid only when the token emitted
AuthorizationUsedfor that payer and nonce in the cited transaction. Gas per sale is capped, and refused payments are limited per visitor.
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
- Store your keys with the Key module using the Environment provider (never Configuration: it ends up in config exports).
- 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).
- 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.
- Try it:
BUYER_PRIVATE_KEY=0x… drush x402:buy https://your-site/node/1 --max=0.05pays the 402 and prints what it bought. - Decide who can stop payments: grant Pause and resume x402 payments, and try
drush x402:stop on "test",drush x402:stop status,drush x402:stop off. - Run cron as the same user as PHP-FPM, so it can write the sanctions list the site reads. Behind a proxy, trust only
X-Forwarded-*inreverse_proxy_trusted_headers.
Additional requirements
- Drupal 11.1+ or 12, PHP 8.3+ with the
gmpandsodiumextensions. - Key.
- Composer installs the libraries:
quebracho/x402(which bringskornrunner/keccakandkornrunner/secp256k1) andleague/html-to-markdown. - USDC on Arc or Solana for buyers; for the own facilitator, a gas wallet with a little USDC on Arc.
Recommended modules
- 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.
- An old revision is judged by its own price: whoever may view revisions reads one made before the price was set.
- 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.
Ask your assistant about x402 pay
Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works
Depends on
Dependencies of the latest stable release
No dependencies recorded for this project.
Required by
Tracked projects that depend on this one
No tracked projects depend on this one yet.
Activity
Release Timeline
Releases
| Version | Type | Core | PHP | Release date | |
|---|---|---|---|---|---|
| 1.0.0-beta5 | Pre-release | 11 | PHP ^8.3 | Nov 15, 2026 | |
| 1.0.0-beta4 | Pre-release | 11 | PHP ^8.3 | Nov 8, 2026 | |
| 1.0.0-beta3 | Pre-release | 11 | PHP ^8.3 | Nov 2, 2026 | |
| 1.0.0-beta2 | Pre-release | 11 | PHP ^8.3 | Oct 25, 2026 | |
| 1.0.x-dev | Dev | 11 | PHP ^8.3 | Oct 14, 2026 | |
| 1.0.0-beta1 | Pre-release | 11 | PHP ^8.3 | Oct 13, 2026 |