x402_url; Coinbase hosts that x402 payment endpoint, captures the funds, and notifies you when the payment settles. An AI agent can then pay for your API programmatically — no hosted page, wallet pop-up, or human in the loop.
This guide builds a minimal paid endpoint: an agent calls it, your server responds 402 Payment Required with a checkout’s x402_url, the agent pays that URL, and your server returns the resource once Coinbase confirms settlement.
Coinbase hosts the x402 payment endpoint (
x402_url) and verifies the payment. Your service orchestrates the flow — it creates checkouts and confirms settlement through webhooks — but never verifies a payment signature itself. Treat the checkout reaching COMPLETED as the source of truth for payment, not the HTTP response an agent sees.How it works
- An agent requests your paid endpoint without proof of payment.
- Your server creates a checkout with the Create Checkout endpoint and returns
402with the checkout’sx402_urlandid. - The agent pays the
x402_urlwith an x402 client that supports theauth-capturescheme. - Coinbase captures and settles the payment; the checkout moves
ACTIVE → PROCESSING → COMPLETEDand acheckout.payment.successwebhook fires. - Your server marks that checkout paid and serves the resource when the agent retries.
Prerequisites
- A Coinbase Business account with a CDP API key, enabled for agentic checkouts. See Authentication. A checkout is agent-payable only when its create response includes an
x402_url— if that field is absent, your account is not routed to agentic checkouts yet. - A public HTTPS endpoint that can receive webhooks.
- Node.js 22.18 or later and npm for the examples.
- On the paying (agent) side: a CDP Secret API Key (
CDP_API_KEY_ID,CDP_API_KEY_SECRET), a Wallet Secret (CDP_WALLET_SECRET), and a wallet funded with USDC on Base.
1. Return a 402 from your endpoint
Installexpress (npm install express), then create the endpoint. On an unpaid request it creates a checkout and returns the x402_url. Authenticate the Create Checkout call with a JWT Bearer token signed with your CDP API key secret (the rat#view scope is required). Require a UUID v4 X-Idempotency-Key on the request and forward it to Create Checkout, so a retried or duplicated request reuses the same checkout rather than minting a new one.
server.ts
node server.ts on Node.js 22.18 or later, and add "type": "module" to its package.json so the import statements resolve.
Keep the
x402_url from the create response. Only single-checkout responses carry it — List Checkouts does not — so re-fetch the checkout by id if you need it again. The x402_url stops accepting payment 24 hours after the checkout is created, regardless of any expiresAt you set.2. Pay the endpoint as an agent
The agent calls your endpoint, reads thex402_url from the 402 body, pays it, then retries your endpoint referencing the checkout it paid.
Checkouts advertise the auth-capture scheme, which matches the authorize-then-capture flow. Register AuthCaptureEvmScheme from @x402/evm on your client — a client that handles only the exact scheme cannot pay a checkout.
1
Install the client packages
"type": "module" to your package.json so the snippet’s import and top-level await run under node.2
Create and fund the payer account
This creates a CDP-managed EVM account and prints its address. Send it USDC on Base before paying — an underfunded payer is rejected with another
402 that names the insufficient balance.getOrCreateAccount returns an EOA server account, the simplest signer to use here. Smart-contract wallets also work: the endpoint verifies auth-capture signatures with ecrecover for EOAs and falls back to on-chain EIP-1271/ERC-6492 verification for contract signers, which must be deployed on-chain (funded with a little ETH on Base) before they can pay.3
Pay and retrieve the resource
applySpendControls caps every payment the client will sign — set it to a ceiling that suits your agent before pointing it at mainnet.A
200 from the x402_url means the payment was authorized, not yet settled. Your endpoint returns the resource only after it records the checkout.payment.success webhook, so the agent polls (and gets 202 until then). The loop in step 3 is bounded rather than waiting indefinitely.3. Confirm settlement and fulfill
Subscribe your webhook endpoint to the checkout event types and verify every delivery, then mark the checkout paid when it settles. Follow Webhooks to create a subscription forcheckout.payment.success (and the other checkout events) and to verify the X-Hook0-Signature header. Verify the signature before trusting any payload — an unverified webhook can be forged.
id is the checkout id — the value this guide correlates on. metadata echoes any fields you set at creation, so you can attach your own order reference and match on that instead. Handle deliveries in an idempotent way: webhooks can arrive more than once, and a checkout is single-use.
If you cannot receive webhooks, poll the Get Checkout endpoint until status reaches a terminal value (COMPLETED, FAILED, EXPIRED, or DEACTIVATED) instead. Ordinary payment rejections — bad signature, wrong amount, insufficient balance, expired window — come back to the agent as another 402 and leave the checkout ACTIVE, so they are safe to retry; a checkout that has reached FAILED is terminal, so create a new one. A COMPLETED checkout can still move to PARTIALLY_REFUNDED or REFUNDED later if you refund it (see Refunds).
Test with a small amount
Test the end-to-end flow with a checkout for a small amount (for example,
0.01 USDC), and only fund the payer with the amount you intend to pay.network field: it reports base in every environment. The client registers both Base mainnet (eip155:8453) and Base Sepolia (eip155:84532), and AuthCaptureEvmScheme picks the network from the challenge.
Refunds
ACOMPLETED checkout can be refunded in full or in part with the Refund Checkout endpoint. Refunds are funded from your own Coinbase Business USDC balance rather than from the buyer’s payment, settle asynchronously, and emit a checkout.refund.success webhook. Poll the refund’s own status to catch the failure case. See Accept Agentic Payments with x402 for details.
What to read next
Accept Agentic Payments with x402
The end-to-end reference for paying a checkout’s x402_url.
Webhooks
Subscribe to checkout events and verify signatures.
x402 overview
How the x402 payment protocol works.
Checkouts API reference
Full endpoint documentation.