What does status code 402 Payment Required mean?

Home - What does status code 402 Payment Required mean?

Status code 402 is a bit of the odd man out. It's in the official HTTP specification, but you rarely encounter it in practice. Yet the idea behind it is anything but irrelevant.

In theory, it is a clear message from the server: "this request cannot be executed until payment is made." No wrong method, no missing authentication, but simply: access against payment.

Why do you hardly ever see it?

When the HTTP protocol was designed, commercial applications were taken into account. The 402 status code was included as a kind of reserved space for paid content. Only: that future image came about, but the code itself remained in the closet.

In practice, payment blocks are usually handled with a 403 Forbidden, or via a 200-response in which the error message is simply in the JSON body. Not ideal, but widely supported.

Still, 402 is sometimes used, especially in APIs of platforms that use subscriptions or work with limits on requests. Think of responses like:

HTTP/1.1 402 Payment Required

For example, with a notification in the body that your daily quota has run out, or that your plan needs to be upgraded.

Is it wise to use 402?

402 Payment Required

It depends on the context. If you are sure that the clients calling your API can process this status code correctly, and if you include clear explanations in the response, then status code 402 is perfectly defensible.

But it's not a standard. And that means: some tooling will ignore it, or misinterpret it. So you have to take extra responsibility yourself in how you handle the error, and document it.

What does it say, technically?

A 402 status code means the request is valid, but the server won't execute it without payment. Unlike 401 (no authentication) or 403 (no permission), this is access that you get only if you first pay something, credits, a license, a subscription.

The standard itself says little about it. The implementation is up to you.

Final thought

Status code 402 is technically valid, but rarely prevalent. It exists, works, and has its place, but don't expect universal support for it. Think of it as an optional tool: one that can come in handy in specific situations, as long as you know what you're working with.

Do you have a system where payment makes the difference between access or blockage? Then 402 is a neat, correct way to signal that, as long as you make sure the rest of your infrastructure comes along.

Picture of David Ladiges
David Ladiges
Technical Lead
On this page

Share this article: