Two HTTP payment rails, one API: how I charge agents per call with x402 and L402
Last week I shipped AtlasData , a pay-per-call crypto data API where the buyer is usually not a human — it is an agent that holds a wallet. Getting paid per request without accounts, API keys, or invoices meant implementing both of the protocols that actually work today: x402 (USDC on Base) and L402 (Lightning sats). Here is what I learned running both on the same FastAPI app. The shape of both…
Last week, I released AtlasData, a pay-per-call cryptocurrency data API designed for agents (rather than humans) that hold crypto wallets. To achieve this without needing accounts, API keys, or invoices, I had to implement two protocols: x402 (USDC on Base) and L402 (Lightning sats). Here's what I discovered while running both payment rails simultaneously on the same FastAPI application.
Both x402 and L402 protocols conform to the HTTP 402 Payment Required status code. For x402, a client receives a JSON object containing the maximum amount required (1000), the asset (USDC), and the network (eip155:8453). For L402, the response includes a challenge in the form of a MACAROON and invoice for the client to solve. The key difference between the two protocols lies in their authentication methods and proof mechanisms.
x402 requires the client to sign an EIP-3009 transferWithAuthorization, which is then settled on-chain through a facilitator. In contrast, L402 utilizes a macaroon paired with a BOLT11 invoice. Upon payment, the client retries the request with an Authorization header containing the preimage. Verification is achieved by checking if sha256(preimage) equals the payment_hash.
While x402 buyers are primarily EVM-native agents, L402 buyers are Lightning-native users. The advantages of each protocol vary depending on the buyer's preferences, with x402 being more suitable for EVM-native agents and L402 being ideal for Lightning-native users who value instant finality and low fees.
The discovery process for agents plays a significant role in utilizing these payment rails. Agents rely on /.well-known/x402 for information, OpenAPI documentation with x-payment-info hints, and /llms.txt for critical details. Crawlers, rather than humans, are responsible for discovering these routes and accessing the API. Providing clear error messages and ensuring that machines can parse the 402 payload is essential to maintaining a smooth experience for agents.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.