x402 HTTP Payments

Pay-per-request API access using the HTTP 402 protocol on Algorand.

What is x402?

x402 is an open protocol that uses the HTTP 402 "Payment Required" status code to enable machine-to-machine payments. When an agent hits a paywalled endpoint, the server responds with 402 and payment instructions. The agent pays on-chain and retries with proof of payment.

Flow

1

Agent sends a request to a resource server

2

Server returns HTTP 402 with payment details (amount, recipient, asset)

3

Agent constructs and signs an Algorand USDC transaction

4

Agent retries the request with the transaction proof

5

Server verifies payment on-chain and returns the resource

Client Usage (Python)

from algopay import AlgoPay

ap = AlgoPay()
response = ap.x402_fetch(
    url="https://api.example.com/premium-data",
    wallet_id="wallet_123",
    max_usdc=0.50,
)
print(response.json())

Custom x402 Endpoints

You can register custom x402 endpoints in the AlgoPay dashboard under APIs → Custom Endpoints. Your agent calls them via /api/x402/:slug and AlgoPay handles the 402 negotiation automatically.