CryptoPatrick / code

Code · Developer tools

cargo-x402

Scaffold Rust projects for x402, the HTTP-native payment protocol, from community templates.

What it is

x402 revives HTTP status code 402 Payment Required: a server can ask for a small payment before serving a request, and a client (or an AI agent) can pay and retry automatically. It makes pay-per-request APIs possible without accounts or subscriptions.

cargo-x402 is a cargo subcommand that starts a new x402 project from a template. It finds templates in GitHub repositories tagged x402-template, lets you pick one interactively, and fills in the project name and options. I wrote five templates for it: a basic API, a CLI, a full-stack app, an observability setup and a starter kit.

Using it

cargo install cargo-x402     # once
cargo x402                   # browse templates, pick one, name the project

Ideas for using it

  • A paid API in an afternoon: start from the basic-API template and put one endpoint behind a payment.
  • Agents that pay for data: an agent calls a priced endpoint, pays, and gets the result, with no human in the loop.
  • Team conventions: publish your own x402-template repository so every new service starts with the same logging and observability.

Status

Beta; the test suite has 149 test functions.