How can an AI agent pay for an API on its own, with no account?
With x402, an agent pays per call in USDC on Base — no signup, no card, no human in the loop. The server says how much; the agent signs a stablecoin payment and retries; a facilitator settles it on-chain. Here is exactly how the loop works.
x402 · USDC · Base mainnet
TL;DR — With x402, an agent pays per call in USDC on Base — no signup, no human in the loop. The server replies 402 with payment requirements; the agent signs a USDC payment (EIP-3009) and retries with an X-PAYMENT header; a facilitator settles it on-chain and the call goes through. patternfetch implements this on Base mainnet with real USDC.
The flow, step by step
x402 takes the long-dormant HTTP 402 Payment Required status code and turns it into a real, machine-to-machine handshake. The whole exchange happens inside one ordinary HTTP round trip the agent already knows how to make:
- The agent calls the endpoint and gets a 402. The server answers with HTTP 402 and an x402 body describing the payment requirements — asset = USDC, the amount, the payTo address, and network = base.
- The agent signs the USDC transfer authorization. Using its own wallet, the agent signs an EIP-3009 transferWithAuthorization — a gasless, off-chain signature that authorizes exactly the required amount of USDC to the payTo address. No on-chain action yet, just a signed message.
- The agent retries the request with an X-PAYMENT header. It re-sends the identical request, now carrying the signed payment payload in the X-PAYMENT header.
- A facilitator verifies and settles on-chain. The server hands the payment to an x402 facilitator, which verifies the signature and submits the USDC transfer on Base. This is where the money actually moves.
- The server credits and returns the result. Once settlement confirms, the server fulfills the original request and returns the data — often with an X-PAYMENT-RESPONSE header confirming what settled.
This is the same model the "x402 Bazaar" indexes — a directory of x402-payable endpoints that agents can discover and pay automatically. patternfetch advertises its own x402 endpoint for discovery at /.well-known/x402.json.
Why it matters for agents
Traditional API access assumes a human: someone signs up, gets an API key, enters a credit card, and clicks through a billing portal. None of that is something an autonomous agent can do mid-loop. x402 removes every one of those steps:
An agent can discover an endpoint, pay for it, and use it in a single loop — pricing comes from the 402 response, payment comes from its own wallet, and the result comes back in the same exchange. Pair x402 with MCP + one-click OAuth and onboarding drops to zero friction: an agent connects, and if it ever needs more than the free tier, it just pays.
How patternfetch implements it
patternfetch is an agent-first crypto market-data API and MCP server, and it is payable two ways:
- Agents — x402: top up credit via POST /v1/topup with USDC on Base mainnet. No signup, no human.
- Humans — Stripe: top up credit with a card via POST /v1/checkout.
1 USDC = $1 of credit. Once you hold credit, calls are metered — a market-state brief is $0.01. And you do not have to pay to find out whether it is useful:
There is a free no-signup demo (POST /v1/demo returns a real brief with no key) and a free key with starter credit (POST /v1/keys, no card). So an agent can prove the data is worth paying for before it ever signs a USDC payment. See pricing →
What the 402 challenge looks like
When a paid endpoint needs payment, the server returns HTTP 402 with a body roughly like this — the agent reads it, picks an entry it can satisfy, and signs:
Server → 402 (payment required)
HTTP/1.1 402 Payment Required
Content-Type: application/json
{
"x402Version": 1,
"accepts": [
{
"scheme": "exact",
"network": "base",
"asset": "<USDC contract on Base>",
"payTo": "0xPatternfetchReceivingAddress",
"maxAmountRequired": "10000",
"resource": "https://patternfetch.com/v1/topup",
"description": "Top up patternfetch credit (USDC)"
}
]
}
Agent → retry with payment
POST /v1/topup HTTP/1.1
Host: patternfetch.com
X-PAYMENT: <base64 signed USDC
authorization (EIP-3009)>
# Client libs like x402-fetch build the
# X-PAYMENT header for you: they read the
# 402, sign the USDC transfer with your
# wallet, and re-send the request — no
# manual signing, no account, no human.
# → 200 OK
# X-PAYMENT-RESPONSE: <settlement proof>
maxAmountRequired is in USDC base units (6 decimals), so 10000 = 0.01 USDC. Libraries such as x402-fetch (or x402-axios) wrap your normal HTTP client: you make the request as usual, and on a 402 they handle reading the requirements, signing with your wallet, and retrying — transparently.
Honesty about what this is
A few things worth stating plainly:
- Payments are real and irreversible. patternfetch's x402 settles real USDC on Base mainnet. An on-chain transfer is final — there is no chargeback. Budget your agent accordingly; spend caps and a dedicated wallet are sensible.
- Crypto is volatile. USDC is a dollar stablecoin, but the assets patternfetch reports on are highly volatile.
- patternfetch returns impersonal market data, not advice. The briefs are algorithmic signals for informational purposes only — not personalized, not a recommendation to buy, sell or hold anything.
FAQ
What is x402?
Does the agent need an account?
What network and asset?
Can humans pay another way?
Next
More: Pricing · Docs · How-to · Try it live · discovery at /.well-known/x402.json