Overview
Any API protected by Meridian x402 can be consumed programmatically — no browser or manual wallet interaction required. Your client holds a funded wallet, and payments are authorized by signing an EIP-3009 message (a gasless signature, not a transaction). The flow is:- Call the endpoint normally.
- Receive
402 Payment Requiredwith a list of accepted payment options. - Sign a payment authorization with your wallet.
- Retry the request with the signed payment in the
X-PAYMENTheader.
Prerequisites
- A wallet private key with USDC on a supported network
- The URL of an x402-protected endpoint
Payments are authorized via signature only — your client never submits a
transaction and does not need native gas tokens. The facilitator settles
on-chain on your behalf.
Using fetch (x402-fetch)
Wrap the native fetch so 402 responses are paid and retried automatically:
maxValue, the wrapper throws instead of paying.
Using axios (x402-axios)
Manual flow (any language)
If an SDK is not available for your stack, implement the flow directly.1. Trigger the 402
2. Sign the payment authorization
Pick an entry fromaccepts and sign an EIP-712 TransferWithAuthorization (EIP-3009) message with your wallet:
- Domain:
nameandversionfromextra, the network’schainId, andassetasverifyingContract - Message:
from(your address),to(payTo),value(maxAmountRequired),validAfter(now − 600),validBefore(now +maxTimeoutSeconds), and a random 32-bytenonce
3. Retry with the X-PAYMENT header
Base64-encode the signed payload and retry:
X-PAYMENT-RESPONSE header with the settlement result (including the transaction hash).
AI agents
Because the whole flow is signature-based and non-interactive, x402 works well for autonomous agents: give the agent a funded wallet key, wrap its HTTP client withx402-fetch or x402-axios, and set a conservative maxValue as a spending guardrail per request.
Best practices
- Cap spend — always set
maxValueexplicitly rather than relying on defaults. - Protect keys — load private keys from environment variables or a secrets manager; never commit them.
- Use a dedicated wallet — fund a purpose-specific wallet with only the USDC your integration needs.
- Test first — develop against a testnet (e.g.
base-sepolia) before pointing at mainnet endpoints.
Next steps
Supported Networks
Networks and assets you can pay with
Sell API access
Protect your own endpoints with x402
API Keys
Authenticate facilitator API calls
Settle Payment
Facilitator settlement endpoint reference