← Blog
API Fundamentals

400 vs 422 vs 409: Choosing the Right API Error Status Code

400 vs 422 vs 409: Choosing the Right API Error Status Code

Status code 422 means the server understood the request and its syntax was valid, but it could not process the semantic content inside it, most often because a field value failed validation. Status code 400 means the request itself was malformed or unparseable. Status code 409 means the request was fine, but it conflicts with the current state of a resource on the server. Apidoke's built-in live try-it console makes it easy to fire real requests and inspect exactly which of these codes your API returns.

  • Use 400 when the request body or URL cannot be parsed at all, for example missing required JSON structure or an invalid query parameter type.
  • Use 422 when the request is syntactically valid but a field fails a business rule, such as a negative quantity or an email that doesn't match a regex.
  • Use 409 when the operation would create a duplicate or violate a resource-state constraint, such as registering an email address that already exists.
  • All three are 4xx codes, so the client is responsible for fixing the problem before retrying.

Why these three codes get confused

HTTP defines status codes in ranges. The 4xx range signals client errors, meaning the problem is on the caller's side, not the server's. Within that range, 400, 409, and 422 all describe scenarios where the server refuses to complete the request, but for different reasons. Because all three can be triggered by an improperly formed POST body, teams often pick one and use it for everything. That shortcut frustrates API consumers: a client that receives a 400 doesn't know whether to fix the JSON structure or change a field value, and a client that always gets 400 for a duplicate-email attempt has to guess at the semantics.

The confusion is compounded by the fact that 422 was originally part of RFC 4918 (WebDAV) before being adopted as a general REST convention, and was formally incorporated into the core HTTP semantics specification RFC 9110 in 2022. Some older teams still treat it as "WebDAV only" and fall back to 400 out of habit.

400 Bad Request: when the server can't even parse what you sent

A 400 (Bad Request) response means the server detected a problem with the request itself before it got to business logic. Think of it as failing at the envelope level, not the letter inside.

Common triggers:

  • Malformed JSON (missing closing brace, trailing comma).
  • A required URL path segment is missing or the wrong type, for example /users/abc where the route expects an integer ID.
  • A required query parameter is absent entirely.
  • The Content-Type header says application/json but the body is not valid JSON.

Example: sending a broken JSON body to a user creation endpoint.

POST /users HTTP/1.1
Content-Type: application/json

{ "name": "Priya", "email": }

Response:

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "error": "bad_request",
  "message": "Request body is not valid JSON."
}

There is nothing semantic to validate here. The server can't even deserialize the payload, so 400 is the right call.

Status code 422 Unprocessable Content: when the data is well-formed but wrong

A 422 (Unprocessable Content) response means the server parsed the request successfully, understood its structure, and then found that one or more values violate a validation rule. The structure was fine; the values were not.

Common triggers:

  • A required field is present but empty or null.
  • A numeric field is out of range (for example, "quantity": -5 when only positive integers are accepted).
  • An email field is present but fails regex validation.
  • A date string is formatted correctly but represents an impossible date, such as February 30.
  • A field value references a foreign key that does not exist in the database.

Example: sending valid JSON but with invalid field values.

POST /orders HTTP/1.1
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzI1NiJ9...

{
  "product_id": 42,
  "quantity": -3,
  "email": "not-an-email"
}

Response:

HTTP/1.1 422 Unprocessable Content
Content-Type: application/json

{
  "error": "validation_failed",
  "details": [
    { "field": "quantity", "message": "Must be greater than 0." },
    { "field": "email", "message": "Must be a valid email address." }
  ]
}

Notice the response body returns a list of field-level errors. That granularity is what makes 422 worth using: it tells the client exactly which fields to fix, reducing round trips and support tickets. If you flattened all of this to a 400, the client would know something was wrong but not which fields were affected.

When you document your API, the error body schema for 422 responses is as important as the success schema. The API Blueprint response codes guide shows how to define multiple response bodies per action in a Blueprint document, which is exactly where you'd capture both a 200 OK and a 422 Unprocessable Content schema side by side.

409 Conflict: when the request is valid but clashes with resource state

A 409 (Conflict) response means everything about the request was correct syntactically and semantically, but executing it would put the server's data into a contradictory or inconsistent state. The request is refused not because of anything wrong with the data itself, but because of what already exists on the server.

Common triggers:

  • Attempting to register an account with an email address that is already taken.
  • Trying to create a resource with a unique identifier that already exists.
  • Submitting an update with an outdated version identifier (optimistic locking).
  • Trying to transition a resource to a state that doesn't follow allowed state-machine transitions, for example cancelling an order that is already shipped.

Example: creating a user with a duplicate email.

POST /users HTTP/1.1
Content-Type: application/json

{
  "name": "Priya Patel",
  "email": "priya@example.com"
}

Response (email already registered):

HTTP/1.1 409 Conflict
Content-Type: application/json

{
  "error": "conflict",
  "message": "An account with this email address already exists.",
  "conflicting_resource": "/users/1091"
}

Including a conflicting_resource field pointing to the existing resource URL is a nice touch: it lets the client decide whether to redirect the user to a login flow instead of a registration retry.

409 is also the standard choice for optimistic concurrency control. If a client sends a PUT with an If-Match header containing a stale ETag, the server can return 409 (or 412 Precondition Failed, which is another valid choice) to tell the client its copy is out of date.

Side-by-side comparison

ScenarioRight codeWhy
Body is not valid JSON400Server cannot parse the request at all
Required header is missing400Structural problem with the request
Field value fails a regex rule422JSON parsed fine; value is semantically invalid
Numeric field is out of allowed range422Validation rule failure, not a parse failure
Referenced foreign key doesn't exist422Semantic constraint violation on a valid structure
Duplicate unique identifier on create409Request is valid, conflicts with existing state
Stale ETag on update409 or 412Concurrency conflict, not a validation failure
Illegal state transition409Resource state machine won't allow the operation
Missing or invalid auth token401Authentication failure, separate concern entirely

How to document all three in API Blueprint

Documenting error responses is as important as documenting the happy path. In API Blueprint, each action can carry multiple + Response blocks. Here is a complete example for a POST endpoint that could return all three codes:

# Group Users

## User Collection [/users]

### Create a User [POST]

Create a new user account.

+ Request (application/json)

    + Body

            {
                "name": "Priya Patel",
                "email": "priya@example.com"
            }

+ Response 201 (application/json)

    + Body

            {
                "id": 1092,
                "name": "Priya Patel",
                "email": "priya@example.com"
            }

+ Response 400 (application/json)

    + Body

            {
                "error": "bad_request",
                "message": "Request body is not valid JSON."
            }

+ Response 409 (application/json)

    + Body

            {
                "error": "conflict",
                "message": "An account with this email address already exists.",
                "conflicting_resource": "/users/1091"
            }

+ Response 422 (application/json)

    + Body

            {
                "error": "validation_failed",
                "details": [
                    { "field": "email", "message": "Must be a valid email address." }
                ]
            }

Apidoke renders each of those + Response blocks as a tab in the three-column viewer, so a reader can click through 201, 400, 409, and 422 without leaving the page. When you open the live try-it console and fire a real POST, the actual HTTP status code the server returns is highlighted, which makes it immediately obvious which branch your implementation is hitting. Auth tokens you enter in the console stay in the browser and are never sent to Apidoke's servers.

Three-column API documentation viewer showing a POST /users action with four response tabs: 201, 400, 409, and 422, each displaying a JSON error body

If you want to go deeper on structuring error bodies and status code documentation across a full blueprint, the API Fundamentals category covers related concepts like authentication status codes and rate limiting in the same pragmatic style.

Common mistakes and how to avoid them

Returning 400 for everything

This is the most widespread habit. It collapses three distinct problems into one code, forcing clients to parse your error message text to understand what happened. That text is fragile: it can change without a versioned signal, and non-English clients may not be able to parse it reliably. Use 400 strictly for parse-level failures and let 422 and 409 carry the semantic weight.

Returning 500 for a duplicate-key database error

When a database unique constraint fires and the application doesn't catch it, many frameworks return a 500 Internal Server Error. The request wasn't a server fault at all, it was a 409 Conflict. Catch unique-constraint exceptions at the service layer and map them to 409 before the response goes out.

Returning 422 without a field-level error body

A 422 response with only a generic message like "Validation failed" wastes the precision the status code promises. Always include which field failed and why. JSON arrays of field-error objects, as shown in the example above, are the most broadly compatible pattern.

Using 409 for validation failures

Some teams return 409 when a field value is invalid, reasoning that the value "conflicts" with their schema. That's a semantic stretch. Conflict should be reserved for state-level collisions with existing resources, not for field value validation.

A note on retry behavior

All three codes signal that the client must change something before retrying. But the nature of that change differs:

  • After a 400, fix the request structure before resending.
  • After a 422, fix the invalid field values before resending.
  • After a 409, resolve the state conflict first, possibly by fetching the current resource state, then decide whether to retry at all.

None of these codes is retryable as-is. That's what separates them from 503 Service Unavailable, which signals a temporary server-side problem where a retry after a delay may succeed.

This retry distinction matters for automated clients and SDK error handling. When you document your API, spelling out the retry semantics for each error code in plain language is as valuable as the status code number itself. The guide on API documentation best practices goes into depth on how to write error response documentation that developers can act on without reading your source code.

Try it live: open the httpbin demo on Apidoke and send real requests that echo your headers and parameters and return any status code, including 401, 405 and 429 from your browser. Nothing passes through Apidoke; the request goes straight from your browser to the API.

Frequently asked questions

What is the difference between 400 and 422?

A 400 Bad Request means the server could not parse or understand the request at the structural level, for example because the JSON is malformed. A 422 Unprocessable Content means the request was parsed successfully but the data inside it failed validation rules, such as a field being out of range or in the wrong format.

When should I use status code 409 instead of 422?

Use 409 Conflict when the request is fully valid on its own but cannot be completed because it clashes with existing resource state, such as a duplicate unique key or a forbidden state transition. Use 422 when the submitted data fails a validation rule that is independent of what the server already holds.

Is 422 an official HTTP status code?

Yes. Status code 422 was originally defined in RFC 4918 for WebDAV and was formally brought into core HTTP semantics by RFC 9110, published in June 2022. It is safe to use in any REST API today.

Should I include error details in the response body for 422?

Yes, always. A 422 without field-level detail forces the client to guess which value was rejected. Return an array of objects identifying the failing field and a human-readable reason, ideally with a machine-readable error code as well. This reduces support load and speeds up integration.

Can I return 409 for optimistic concurrency failures?

Yes, 409 Conflict is a valid choice when a client tries to update a resource using a stale version identifier or ETag. The alternative is 412 Precondition Failed if you are using the standard If-Match header mechanism defined in RFC 9110. Both are acceptable; pick one and document it consistently.


Ready to document your API error responses properly? Publish clean, three-column API docs with a live try-it console at no cost. Sign in to Apidoke and start your first project today.

Related reading: Idempotency Keys: How to Make API Retries Safe

Related reading: What Is CORS? Why Browser API Calls Fail and How to Fix It

Technically reviewed by the Apidoke engineering team.