pip install pay402

The Python client that lets software pay for things.

An agent hits a priced URL and gets HTTP 402 back: a price, a wallet, a chain. pay402 signs a USDC payment under your spend cap and returns the goods plus a receipt. One function call. No account, no API key, no browser, no gas token.

pip install "pay402[evm]"

the first real sale, replayed
$ pip install "pay402[evm]"
$ export PAY402_KEY=0x…   # funded burner wallet; the agent never sees it
$ pay402 https://api.checkout402.com/c/chk_gitbuyer… --max-usd 1.00
paid $0.1105 on eip155:8453 (Base)
  tx      0x02f5002f64f18b…
  receipt api.checkout402.com/r/pay_oq1P-qF6PfRbDZzE
# goods: the purchased repo, as tar.gz, bought by an AI agent, end to end

In plain terms

pay402 is a Python library and command-line tool that pays for things on the web, by machine. When a URL costs money, the server answers 402 Payment Required with a price. pay402 reads that price, pays it in digital dollars (USDC) if it is under the limit you set, and hands back whatever you bought, with a receipt.

What people use it for: an AI agent that buys a dataset, an API call, a report or a private codebase on its own; a script that pays per use for data instead of holding a subscription and an API key; a developer buying from a terminal with no account, no checkout form and no browser. Anything sellable over a URL becomes buyable by software.

It speaks the open x402 protocol, not one company's checkout: any server answering a spec-correct 402 can be paid, whoever built it. Settlement today is USDC on two rails, Base and Solana, and the buyer needs no gas token on either.

01

Machines became buyers

Agents can already find, compare and decide. Paying was the missing step: cards want forms and 3-D Secure, API keys want signups. A 402 challenge is a price a program can read; pay402 is the program that pays it, in the language agents run.

02

402 waited thirty years

HTTP reserved 402 Payment Required in the 1990s for a payment web that never arrived. The x402 protocol finally uses it: any URL can quote a price, any buyer can settle it on-chain in seconds, for cents.

03

Paid only on delivery

Settlement runs after delivery: a failed delivery is never charged, by order of operations rather than by refund policy. Written down at /guarantees.

Two ways in, same loop

From Python

from pay402 import pay

out = pay(url, private_key=key, max_usd="1.00",
          refund_to=my_wallet)   # optional, on the receipt
out.goods      # what you bought
out.receipt    # proof, with the on-chain tx

From a shell (what agents run)

pay402 <url> --quote            # price only, signs nothing
pay402 <url> --max-usd 5        # key from $PAY402_KEY

The loop either way: read the 402, refuse if the total exceeds your cap, sign, retry with X-PAYMENT, hand back goods and receipt. The receipt URL prints on success, so the proof survives in the transcript of whatever ran the purchase.

It has actually moved money

Both rails settled on mainnet with this code, verified against the chain rather than against anyone's database. A $0.01 purchase, fee $0.01005, in atomic USDC units:

ChainBuyerSellerFee walletHeld in transit
Base−20,050+10,000+10,0500
Solana−20,050+10,000+10,0500

Base 0x292dcc2c…5b28f19  ·  Solana 46bzWMwk…Jir42Vj

And in the wild: the first marketplace purchase, an AI agent buying a repo on gitbuyer end to end for $0.1105: receipt  ·  0x02f5002f…3ca9c1a

Non-custodial on both rails: on Base an immutable splitter contract that keeps nothing, on Solana one transaction carrying both transfers. Nobody holds your money on the way through.

What stops it spending too much

The key never enters the conversation

The human sets $PAY402_KEY in the environment; the agent runs the command and never sees, reads or forwards the key. Signing happens in this process and policy is the flags. The reason is ordinary secret hygiene: transcripts and logs persist, and keys do not belong in them, the same rule that keeps secrets out of commit messages.

No wallet yet? The buying guide mints a throwaway one in the browser and funds it with a single purchase's worth. No ETH, no SOL, ever: the facilitator pays gas on Base, a relayer pays fees on Solana.

Install

pip install "pay402[evm]"       # Base
pip install "pay402[solana]"    # Solana
pip install "pay402[all]"       # both

The bare install is httpx and nothing else, so an agent sandbox will accept it. Chain SDKs are extras: a buyer paying on Base has no reason to carry a Solana library.

Python only, deliberately; this is where the agents are. The name pay402 on npm belongs to an unrelated author: whatever that package does, it is not this.