Skip to content

402 Payment Required — Meaning, Common Causes & How to Fix

402 4xx Client Error RFC 9110 §15.5.3

402 Payment Required means: Reserved for future use as a payment-related error: the request cannot proceed until payment is made. RFC 9110 keeps it reserved; some payment and API-monetization platforms use it experimentally for unpaid invoices or exhausted credits. Client-error 4xx codes mean the request itself is the problem: malformed syntax, missing credentials, forbidden access, a nonexistent resource or a violated precondition. The server is telling the client what to change; retrying the identical request without a fix will reproduce the same error. In practice you will meet 402 when an api monetization layer blocks calls after credits run out; a saas account has an unpaid invoice and the provider enforces a paywall; experimental x402-style payment-required flows on the open web. On the client side, check billing status, settle the invoice or top up credits, then retry; read the body for payment instructions if the provider defines them. On the server side, if you adopt 402, document the payment flow precisely and include machine-readable details; do not use it for generic quota problems (429 fits better).

Advertisement
Ad slot · ref-top

When 402 happens

  • An API monetization layer blocks calls after credits run out
  • A SaaS account has an unpaid invoice and the provider enforces a paywall
  • Experimental x402-style payment-required flows on the open web

How to fix it

On the client

Check billing status, settle the invoice or top up credits, then retry; read the body for payment instructions if the provider defines them.

On the server

If you adopt 402, document the payment flow precisely and include machine-readable details; do not use it for generic quota problems (429 fits better).

Should you retry?

Not retryable as-is: change the request (credentials, payload, URL) first.

Debugging steps

When 402 appears unexpectedly, start by capturing the full exchange: 'curl -i' or the browser DevTools Network tab shows the exact status line and response headers, which often carry the real explanation. Read the error body first — well-designed APIs name the offending field or missing credential. Then diff your actual request, headers included, against the documented contract. For this code specifically, check whether the most common trigger applies to your situation: an api monetization layer blocks calls after credits run out. Compare your exchange against the raw HTTP example above. If you operate the server, correlate the timestamp with application and proxy logs using the request id; if you are the client, verify the request shape against the API documentation before changing anything or retrying.

Notes & gotchas

Because 402 has no standard semantics, every vendor defines its own payment flow; never assume interoperability, and always read the provider's documentation and response body before building retry logic.

Examples

Raw HTTP
HTTP/1.1 402 Payment Required
Content-Type: application/json
Content-Length: 110

{
  "error": "payment_required",
  "message": "An API monetization layer blocks calls after credits run out"
}
curl
curl -i https://api.example.com/v1/resource   # observe the 402 response and its headers
JavaScript (fetch)
const res = await fetch("https://api.example.com/v1/resource");
if (res.status === 402) {
  const problem = await res.json(); // read field-level details
  // fix the request (credentials, payload, URL) — identical retries keep failing
  throw new RequestError(problem);
}
Python (requests)
import requests

res = requests.get("https://api.example.com/v1/resource", timeout=10)
if res.status_code == 402:
    problem = res.json()  # field-level error details
    # correct the request before retrying — identical retries keep failing
    raise RequestProblem(problem)

Frequently asked questions

Is 402 an official part of HTTP?

It is reserved in RFC 9110 'for future use' — no standard semantics are defined yet, so implementations vary by vendor.

Why do some APIs return 402 for rate limits?

They conflate payment with quota. Standard practice: 429 for rate limits, 402 (experimental) or 403 for billing enforcement.

Are 4xx errors always the client's fault?

By contract yes — the server asserts the request must change. In practice servers sometimes misuse 4xx for their own problems (e.g. 400 for internal validation bugs), so read the error body before blaming your client code.

Should I retry 4xx responses automatically?

Generally no: the server says the request must change. Exceptions are 408 (fresh connection), 425 (after handshake) and 429 (after Retry-After). Blind retries of 400/401/403/404 just burn quota.

Advertisement
Ad slot · ref-in-article

Try the JSON Validator

Check JSON syntax and locate errors by line and column.

Open tool →