Overview
x402 is an open protocol that uses the HTTP402 Payment Required status to ask a client for a payment. The client signs a USDC transfer authorization, retries the request with it, and a facilitator settles it on chain. No signup, no card, no checkout page. That is why agents use it.
Lago connects to the Coinbase Developer Platform (CDP) facilitator and handles the billing side of each payment:
- Credit purchases. An agent tops up a prepaid wallet in USDC, then spends the credits call by call. This is the main flow, driven by the
lago-x402middleware in front of your API. - Invoice payments. A finalized invoice gets an x402 payment URL. The buyer pays the amount due by signing against it, with no payment method on file.
Premium feature, on request. x402 payments need a premium license and the
x402_payments feature flag on your organization. Contact us to enable it.Why it is not a regular payment provider
Every other payment provider in Lago is pull-based: Lago stores a payment method and charges it when an invoice is due. x402 is push-based. Nothing can collect from an agent address without a fresh signature from its key, per payment. So an x402 connection has no stored payment method, no automatic collection, no dunning and no payment retries. The buyer pays because it signed. Lago records the result.Prerequisites
- Premium license with the
x402_paymentsfeature flag. - Events targeting wallets, the premium integration that lets a usage event name the wallet it draws from. x402 gates read one wallet, so the usage must drain that same wallet. Without it, gate checks answer
charge_not_targeted. - A Redis cache on self-hosted Lago. Set
LAGO_REDIS_CACHE_URLand leaveLAGO_DISABLE_WALLET_REFRESHunset. Memcached runs the wallet balance refresh, but x402 needs Redis for two things:- Turning
x402_enabledon for a wallet. Without a Redis cache, it fails withwallet_refresh_unavailable, memcached or not. - The per-wallet reservation counter behind the gate check. Without a Redis cache store, or with Redis unreachable, the gate falls back to a floor: it passes only when the balance minus usage covers 1,000 times
estimatedCallCostCents. In practice, almost every call is challenged.
- Turning
- A CDP project with a Secret API key and payout accounts created in that project (CDP Server Wallet accounts).
Connect Coinbase
In the app, go to Settings > Integrations > Coinbase and click Add a connection. You can also usePOST /api/v1/x402_connections.

An x402 connection to Coinbase in Settings > Integrations
What Lago checks on save
A bad connection fails when you save it, not when an agent tries to pay. On create and update, Lago:- Validates the shape: every selected network’s family has a payout address, EVM addresses pass the EIP-55 checksum (an all-lowercase address is accepted and stored checksummed; a mixed-case one must match), Solana addresses decode as base58, and all networks belong to one environment.
- Calls the facilitator with your credentials. A wrong key or secret fails the save, and every selected network must be supported.
- Looks each payout address up in your CDP project. An address outside the project fails with
not_in_cdp_projecton that family.
Testnet first
New organizations run on testnet: Base Sepolia and Solana devnet. Lago switches an organization to mainnet on request. A connection whose networks belong to the other environment is refused withenvironment_not_enabled, at save and on every gate check, credit purchase or invoice payment. Test the full flow on testnet with faucet USDC, then ask for mainnet.
Only one environment is enabled at a time. Once an organization is on mainnet, its testnet connections are refused too, with environment_not_enabled on gate checks and invoice payment URLs. A connection saved on mainnet networks can’t be moved back to testnet networks (mainnet_not_downgradable): create a new one.
Credit purchases
A credit purchase turns one settled USDC payment into prepaid credits. Thelago-x402 middleware drives it from your API, in settle mode: Lago settles the payment itself. On each purchase, Lago:
- Verifies the signed payment with the facilitator, and checks it against your connection: network, asset, payout address and amount.
- Records a pending settlement, then settles through the facilitator.
- Creates what the agent needs, on its first purchase only: a customer keyed on the paying address, a subscription to the route’s plan and the route’s wallet.
- Grants the credits on the wallet. They are spendable as soon as the response returns.
- Issues the fiscal trail asynchronously, within seconds: a credit invoice and an x402 payment, plus a receipt when your organization issues receipts.
Record mode
If you run your own x402 gate and settle through the facilitator yourself,POST /api/v1/x402/credit_purchases also accepts mode: "record" with the facilitator’s settle_response, an idempotency_key, and optionally its verify_response. The idempotency_key is required in record mode, optional in settle mode. Lago makes no facilitator call. It checks the settle response it is given, records the settlement as settled by you, and runs steps 3 to 5. The same payment sent again under another idempotency_key gets payment_already_settled.
Record mode is available through the API only. The lago-x402 middleware always uses settle mode, and invoice payments always settle through Lago.
From then on the agent is a regular prepaid-credit customer. Usage events draw its wallet down at your plan’s price, and its invoices, wallet transactions and payments show in the app, the API and your webhooks like any other customer’s.
Credit math
USDC is booked 1:1 to USD. Credits follow the wallet’s rate, as for any wallet top-up:
Top-up limits on the wallet apply in part. Lago enforces the maximum before it settles, so a payment above it is refused and no money moves. It waives the minimum: settling a few cents of USDC costs a fraction of a card fee, which is what minimums exist to absorb.
Identity
The paying address is the identity: one address, one customer, whichever network of its family it pays on. An agent that pays from an EVM address and a Solana address becomes two customers.Invoice payments
Any finalized USD invoice of a customer with an x402-enabled wallet can be paid over x402. Typical case: an agent’s usage outran its credits during the period, and the invoice carries the remainder.Get the payment URL
422 with the rule that failed.
How the buyer pays
The payment URL is a standard x402 resource:- The buyer requests it without a payment. Lago answers
402with aPAYMENT-REQUIREDheader: one payment requirement per network of the connection, for the invoice’s full amount due. - The buyer signs and posts the payment in a
PAYMENT-SIGNATUREheader, withPOST. - Lago verifies, settles and records it: an x402 payment on the invoice,
payment_statusset tosucceeded, a receipt when your organization issues receipts, and the existing invoice and payment webhooks. The answer is200with aPAYMENT-RESPONSEheader carrying the transaction hash.
The payment must equal the amount due. Partial payments are not supported.
Reading a payment in Lago
x402 payments show in Payments with the method Coinbase x402. The detail view adds an x402 settlement section: kind (credit purchase or invoice payment), agent address, payout address, network, asset, settled amount, settlement status and the credits granted.Pending settlements
A settlement broadcasts a transaction. When the facilitator does not confirm it in time, or the connection drops, Lago cannot tell a failure from a success. It never guesses:- The settlement stays pending, and Lago tells the caller to retry later. The middleware answers the agent
503 payment_pendingwith aRetry-After. - A reconciliation job reads the chain once the authorization window has closed, then settles or fails the row for good. Lago reads the chain rather than resending the settle call, because a resend can broadcast a second transaction.
- While a payer or an invoice has a pending settlement, Lago issues no new challenge for it. A second authorization on top of one that may have landed is what would double-charge.
Refunds
There is no refund endpoint and no on-chain void. A settle is final, and returning funds would require holding your payout keys. Chargebacks don’t exist on this rail. To give money back:- Issue a credit note in Lago. For a credit purchase, void the unused credits on the wallet first. Lago fires the credit-note webhook. It enqueues no refund job for an x402 payment.
- Send the USDC back to the agent address, from your own treasury. The address is on the payment record.
Limits
- USDC only, USD only. Wallets, plans and invoices paid over x402 must be in USD. Non-USD merchants run a parallel USD wallet and plan for agent traffic.
- Base and Solana only, mainnet and testnet. One facilitator: Coinbase CDP.
- x402 v2 only. v1
X-PAYMENTheaders are not accepted. - The middleware lets Lago settle every payment. Recording a payment your own gate settled is available through the API only, in record mode. Invoice payments always settle through Lago.
- No partial invoice payments. A payment must equal the amount due.
- No refunds through Lago. See Refunds.
- Terminating an agent’s wallet forfeits its balance. Lago neither moves nor refunds it, and usage already prepaid but not yet invoiced is billed at period close. The next payment creates a fresh wallet with the same code.
- The Bazaar lists the top-up, not the call price. See Bazaar discovery.