Understanding HTTP 402 Payment Required: The Reserved Code That Finally Found a Job
402 Payment Required is the status code that spent its whole life waiting. It was reserved in 1997 for a web that would have payments built in, and the spec has said "reserved for future use" ever since. The common take is that 402 is therefore off-limits, and that anything payment-related should be a 403 with an explanatory message. That's still a safe default, but it's no longer the full story. Payment APIs have used 402 for years, and since 2025 two protocols aimed at AI agents and crawlers have been built directly on it. This post covers what the spec does (and doesn't) say, who uses 402 today, how to choose between 402, 401, 403 and 429 for billing problems, and what to put in the response when there's no standard to follow.
What Is a 402?
A 402 is a client error status code that HTTP has reserved but never defined. Here is the entire definition in the current spec:
The 402 (Payment Required) status code is reserved for future use. โ RFC 9110, Section 15.5.3
That one sentence is all there is. The spec doesn't say what a 402 means, which headers go with it, or what a client should do when it gets one.
In plain English: "Paying would get you this." That's the meaning everyone has informally agreed on. But because the spec never said so, every system that uses 402 invents its own body, its own headers and its own recovery flow. As MDN puts it, "No standard use convention exists."
Nearly Thirty Years in Reserve
402 was part of the plan from early on. An early W3C description of HTTP listed PaymentRequired 402 with a parameter describing "charging schemes acceptable" and a ChargeTo header the client could retry with. That design never shipped. HTTP/1.0 (RFC 1945, 1996) didn't define 402 at all. HTTP/1.1 (RFC 2068, January 1997) added it with the line "This code is reserved for future use", and every revision since has kept that wording, up to RFC 9110 in 2022.
The web got payments anyway, through checkout pages, card forms and payment processors, but none of it went through a status code. Browsers never gained any 402 behavior: per MDN, no browser supports it, and a 402 is displayed like any other 4xx error. So 402 stayed an empty slot for developers to fill however they liked.
How 402 Is Used Today
Payment and billing APIs
Some well-known APIs have used 402 for years:
- Stripe lists 402 in its HTTP status code summary as "Request Failed: The parameters were valid but the request failed." Stripe says its 4xx errors cover cases like a failed charge or a declined card. The error body carries a
type(such ascard_error), acode, adecline_codefor issuer declines, and amessageyou can show to users. - Shopify's response codes say a 402 means "The requested shop is currently frozen," and the owner has to pay the outstanding balance in the admin to unfreeze it.
- OpenRouter's error reference uses 402 when "Your account or API key has insufficient credits."
Notice that these mean three different things: a payment attempt failed, an account is unpaid, and a prepaid balance ran out. They're all "money is the problem", but a client can't tell which from the status code alone.
x402: payments for software clients
x402 is a payment protocol built on 402. Coinbase introduced it in May 2025, and the Linux Foundation announced an x402 Foundation to govern it in April 2026, with Coinbase contributing the protocol. The project calls itself "an open standard for internet native payments". That's the project's own description, and it isn't an IETF standard. The target audience is software rather than people: APIs, apps and AI agents that pay per request.
In version 2 of the HTTP transport spec, the flow uses three headers, each carrying base64-encoded JSON:
- The client requests a resource. The server answers
402 Payment Requiredwith aPAYMENT-REQUIREDheader listing what it accepts. - The client picks an option, signs a payment authorization, and retries with a
PAYMENT-SIGNATUREheader. - The server verifies and settles the payment (itself, or through a "facilitator" service), then returns
200 OKwith aPAYMENT-RESPONSEheader describing the settlement.
HTTP/1.1 402 Payment Required
Content-Type: application/json
PAYMENT-REQUIRED: eyJ4NDAyVmVyc2lvbiI6Miwi...
{}Decoded, the header looks like this (trimmed from the spec's example):
{
"x402Version": 2,
"resource": { "url": "https://api.example.com/premium-data" },
"accepts": [
{
"scheme": "exact",
"network": "eip155:84532",
"amount": "10000",
"asset": "0x036CbD53842c5426634e7929541eC2318f3dCF7e",
"payTo": "0x209693Bc6afc0C5328bA36FaF03C514EF312287C",
"maxTimeoutSeconds": 60
}
]
}The spec's example is a USDC stablecoin payment on a blockchain test network, and the project says it aims to support fiat as well. Two details are worth noting for API designers. The spec says the response body is up to the server, because all protocol data travels in headers. It also maps a malformed payment to 400, but a payment that fails verification or settlement gets another 402.
Cloudflare pay per crawl
Cloudflare launched pay per crawl in July 2025, describing it as a way to "dust off a mostly forgotten piece of the web." Site owners set a price, and AI crawlers either pay it or get turned away. Per the crawler documentation, an unpaid request gets a 402 with the price in a header:
HTTP/2 402
crawler-price: USD 0.01The crawler retries with crawler-exact-price: USD 0.01 (or sends crawler-max-price up front), and a successful request comes back 200 with crawler-charged: USD 0.01, the amount billed to the crawler's Cloudflare account. Crawlers have to sign their requests with Web Bot Auth so they can't be impersonated, and Cloudflare acts as the merchant of record. Cloudflare's docs list the feature as being in closed beta.
This is a separate scheme from x402, with its own headers. Cloudflare did co-found the x402 Foundation with Coinbase, and in its x402 announcement it said it planned to bring a proposed x402 deferred-payment scheme to pay per crawl. In the same post, Cloudflare says sites on its network already send "over a billion HTTP 402 response codes" a day to bots and crawlers, and it puts their limited effect down partly to "a lack of standardization."
402 vs 401 vs 403 vs 429
Billing problems tempt developers toward four different codes. The question that settles it is what would fix this request?
| Code | Meaning | Use when |
|---|---|---|
| 401 Unauthorized | Not authenticated | No API key, an invalid key, or an expired session. Logging in fixes it |
| 402 Payment Required | Payment would fix it | The subscription lapsed, the last invoice failed, or prepaid credits ran out |
| 403 Forbidden | Authenticated but not allowed | The user lacks permission, including "your plan doesn't include this feature" |
| 429 Too Many Requests | Too many requests for now | A rate limit or quota that resets on its own. Waiting fixes it |
The heuristics:
- 401 = "Log in." Check authentication first, before anything to do with billing. An anonymous request should never learn that some account's card bounced.
- 402 = "Pay." The user is identified and the request is valid, but money is blocking it.
- 403 = "You're not allowed." Your role or plan doesn't grant it.
- 429 = "Wait." Send
Retry-Afterand the client can back off and try again.
Here's how that works for the common cases:
- Subscription expired or payment failed: 402. Paying is the only fix, and it's the case closest to the code's name. Shopify's frozen shop is exactly this.
- Prepaid credits exhausted: 402, as OpenRouter does.
- Hard monthly cap that resets on the 1st: this one is a judgment call. If waiting until the reset is the realistic fix, use 429 with
Retry-Afterpointing at the reset. If buying more usage is the only option, use 402. See our 429 post for the headers. - Plan doesn't include the feature: 403 is the conventional answer, and it's what our 403 post recommends. Upgrading would fix it, so 402 is defensible too, but generic clients and monitoring understand 403 better. Pick one, document it, and stay consistent.
Even the spec authors reach for 403 here. The out-of-credit example in RFC 9457, the IETF's standard error-body format, returns 403 Forbidden with the account balance in the body. Either code can be correct. What matters is that clients can tell what to do next.
What to Put in a 402 Response
There's no WWW-Authenticate equivalent for 402, so the body has to do the work. Unless you're implementing x402 or pay per crawl, in which case follow that protocol's headers exactly, give clients:
- A stable, machine-readable reason.
subscription_past_due,insufficient_creditsandcard_declinedneed different handling. Stripe'scodeanddecline_codefields exist for this reason. - A human-readable message you'd be happy for the app to show to the end user.
- A way to fix it, such as a billing URL, a top-up endpoint, or the price and accepted payment methods.
- Context when it helps, like the current balance, the amount the request needed, or the plan required.
RFC 9457 Problem Details (application/problem+json) is a good wrapper. It's a published standard for error bodies, and it lets you add your own fields alongside type, title, status and detail.
Returning 402 Correctly
Express / Node.js
app.post("/api/reports/export", requireAuth, async (req, res) => {
const account = await getAccount(req.user.accountId);
if (account.subscription.status === "past_due") {
return res.status(402).json({
error: "subscription_past_due",
message: "Your last payment failed. Update your card to keep exporting reports.",
billingUrl: "https://example.com/settings/billing",
});
}
if (account.credits < EXPORT_COST) {
return res.status(402).json({
error: "insufficient_credits",
message: `This export costs ${EXPORT_COST} credits and you have ${account.credits}.`,
balance: account.credits,
required: EXPORT_COST,
topUpUrl: "https://example.com/settings/credits",
});
}
res.json(await startExport(account));
});requireAuth runs first, so an unauthenticated request gets a 401 before any billing state is checked.
Next.js App Router
// app/api/projects/[id]/export/route.ts
export async function POST(
request: Request,
{ params }: { params: Promise<{ id: string }> },
) {
const { id } = await params;
const session = await getSession(request);
if (!session) {
return Response.json(
{ error: "unauthenticated" },
{ status: 401, headers: { "WWW-Authenticate": 'Bearer realm="api"' } },
);
}
const account = await getAccount(session.accountId);
if (account.subscription.status !== "active") {
return Response.json(
{
type: "https://example.com/problems/subscription-inactive",
title: "Your subscription is not active.",
status: 402,
detail: "Renew your plan to export this project.",
billingUrl: "https://example.com/settings/billing",
},
{ status: 402, headers: { "Content-Type": "application/problem+json" } },
);
}
return Response.json(await startExport(id, account));
}In Next.js 15 and later, route handler params is a Promise, so await it before reading id. This example also uses the RFC 9457 shape, so the body carries its own status and a type URL that clients can branch on.
REST API JSON body
HTTP/1.1 402 Payment Required
Content-Type: application/problem+json
Cache-Control: no-store
{
"type": "https://api.example.com/problems/insufficient-credits",
"title": "Not enough credits.",
"status": 402,
"detail": "This request costs 50 credits and your balance is 30.",
"balance": 30,
"required": 50,
"topUpUrl": "https://example.com/settings/credits"
}RFC 9110 doesn't list 402 as heuristically cacheable, so caches won't store it unless something tells them to. Cache-Control: no-store makes that explicit, which matters because the answer changes the moment the user pays. You don't want a CDN rule serving a stale 402 to someone who just topped up.
If you add custom headers (a price, a quote ID) and browsers call your API from another origin, list them in Access-Control-Expose-Headers. Otherwise res.headers.get() returns null for them in the browser.
Handling 402 on the Client
Since there's no standard, branch on the body, not just the status:
const res = await fetch("/api/reports/export", { method: "POST" });
if (res.status === 402) {
const problem = await res.json();
if (problem.error === "insufficient_credits") return showTopUp(problem);
if (problem.error === "subscription_past_due") return showBillingPrompt(problem);
return showGenericPaymentError(problem.message);
}Don't auto-retry a 402. Unlike a 429 or a 503, it won't clear up on its own, and retrying a declined card can make things worse: Stripe has a card_decline_rate_limit_exceeded error code for cards declined too many times. The one exception is a protocol like x402, where paying and retrying is the designed flow, and even then the client should retry once with a payment attached, not loop.
402 and SEO
A 402 is a 4xx, so Google treats it like any other client error. Per Google's documentation, it doesn't index URLs that return a 4xx, and drops already-indexed URLs that start returning one. Only 429 is treated differently. A paywalled article that returns 402 to Googlebot will fall out of search.
If you want paid content to rank, serve the page with a 200, show a preview or the full text to crawlers, and mark the gated sections with Google's paywalled content structured data (isAccessibleForFree). That markup is how Google tells a legitimate paywall apart from cloaking. Use 402 for APIs and machine clients. Pay per crawl is a deliberate exception, because there the 402 is aimed at AI crawlers that are expected to pay rather than at search indexing.
Common Pitfalls
- Checking billing before authentication. Return 401 for missing or bad credentials first. Otherwise you leak account state to anonymous callers.
- A bare 402 with no body. With no standard semantics, a status code alone tells the client nothing actionable. Always include a reason code and a way to fix the problem.
- Using 402 for rate limits. If waiting fixes it, it's a 429 with
Retry-After. Retry logic depends on that distinction. - Mixing 402 and 403 for the same situation. If "plan doesn't include this" is a 403 on one endpoint and a 402 on another, clients can't build a single upgrade flow. Decide once and document it.
- Returning 402 on public HTML pages. Search engines treat it as a missing page. Gate the content inside a 200 response instead.
- Calling 402 standardized. Its meaning is a convention, x402 is a protocol with its own foundation, and pay per crawl is one vendor's product. None of them is an IETF definition of 402, so document exactly what your API means by it.
- Letting a 402 get cached. Payment state changes in seconds. Send
Cache-Control: no-store.
Wrapping Up
402 has gone from a placeholder to a code with real users, just not standardized ones. The rules of thumb:
- RFC 9110 still says only that 402 is reserved for future use, so its meaning is whatever your documentation says
- The working convention is "paying would fix this": lapsed subscriptions, failed payments, exhausted credits
- Choose by the fix: log in is 401, pay is 402, different permission is 403, wait is 429
- Plan-gated features are conventionally 403; 402 works if you're consistent about it
- Put a machine-readable reason and a way to pay in the body (RFC 9457 Problem Details fits well), and mark it
no-store - If you implement x402 or Cloudflare's pay per crawl, follow their headers exactly instead of inventing your own
- Don't serve 402 on pages you want indexed
For more, see our pages on 402 Payment Required, 401 Unauthorized, 403 Forbidden and 429 Too Many Requests. The authentication-versus-permission split is covered in understanding 401 Unauthorized and understanding 403 Forbidden, quota and backoff headers are in understanding 429 Too Many Requests, and you can compare 402 vs 403 side by side.
Related Status Codes
- 400Bad Request
- 401Unauthorized
- 402Payment Required
- 403Forbidden
- 404Not Found
- 405Method Not Allowed
- 406Not Acceptable
- 407Proxy Authentication Required
- 408Request Timeout
- 409Conflict
- 410Gone
- 411Length Required
- 412Precondition Failed
- 413Payload Too Large
- 414URI Too Long
- 415Unsupported Media Type
- 416Range Not Satisfiable
- 417Expectation Failed
- 418I'm a Teapot
- 421Misdirected Request
- 422Unprocessable Entity
- 423Locked
- 424Failed Dependency
- 425Too Early
- 426Upgrade Required
- 428Precondition Required
- 429Too Many Requests
- 431Request Header Fields Too Large
- 451Unavailable For Legal Reasons