Client Error · 4xx

412 Precondition Failed

A precondition header on the request did not match the server's state.

What 412 Precondition Failed means

412 Precondition Failed is the response when an If-Match, If-None-Match, If-Unmodified-Since, or other conditional header does not match the resource's current state. The most common case: optimistic concurrency control. The client GETs a resource with ETag "v1", modifies it, and sends PUT with If-Match: "v1". If another client updated the resource in between (current ETag is "v2"), the server returns 412 instead of overwriting.

When servers should return it: Return 412 when a request includes an If-Match or If-Unmodified-Since header and the precondition does not match. This protects against lost updates.

Common causes

How to fix 412 Precondition Failed

Example response

curl -i -X PUT -H 'If-Match: "v1"' \
  -d '{"name":"Ada"}' https://api.example.com/users/42

HTTP/2 412
etag: "v3"
content-type: application/json
{"error":"precondition failed","current_etag":"v3"}

Related status codes

Frequently Asked Questions

412 vs 409?
412 is specifically about precondition headers (If-Match, etc.). 409 is the broader conflict code and applies to any state conflict, with or without preconditions.
Defined in: RFC 9110 · Class: 4xx Client Error

More references

For a one-page reference of all HTTP status codes, see the HTTP cheat sheet. For testing API responses, try the API Tester tool. For inspecting responses on the command line, the curl cheat sheet covers the most common flags.