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
Agent sends a request to a resource server
Server returns HTTP 402 with payment details (amount, recipient, asset)
Agent constructs and signs an Algorand USDC transaction
Agent retries the request with the transaction proof
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.