Skip to content

431 Request Header Fields Too Large — Meaning, Common Causes & How to Fix

431 4xx Client Error RFC 6585

431 Request Header Fields Too Large means: The request's header fields are too large — either one header or the total — for the server to process. Common with bloated cookies, huge Authorization tokens, or tracing headers accumulated across proxies. 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 431 when cookie accumulation past the server's header buffer (nginx default 8 kb); oversized jwts or many forwarded headers (x-forwarded-*, trace context); a redirect loop appending headers until buffers overflow. On the client side, trim cookies, shorten tokens, remove redundant headers; check every proxy hop's header size limits, not just the origin's. On the server side, tune header buffer sizes (nginx large_client_header_buffers) to your auth scheme; return 431 rather than a generic 400 so clients know to shrink headers.

Advertisement
Ad slot · ref-top

When 431 happens

  • Cookie accumulation past the server's header buffer (nginx default 8 KB)
  • Oversized JWTs or many forwarded headers (X-Forwarded-*, trace context)
  • A redirect loop appending headers until buffers overflow

How to fix it

On the client

Trim cookies, shorten tokens, remove redundant headers; check every proxy hop's header size limits, not just the origin's.

On the server

Tune header buffer sizes (nginx large_client_header_buffers) to your auth scheme; return 431 rather than a generic 400 so clients know to shrink headers.

Should you retry?

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

Debugging steps

When 431 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: cookie accumulation past the server's header buffer (nginx default 8 kb). 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

Header size limits are per-hop: cookies and tokens that fit your local server can overflow an edge proxy's buffers in production, so audit the whole chain, not just the origin.

Examples

Raw HTTP
HTTP/1.1 431 Request Header Fields Too Large
Content-Type: application/json
Content-Length: 137

{
  "error": "request_header_fields_too_large",
  "message": "Cookie accumulation past the server's header buffer (nginx default 8 KB)"
}
curl
curl -i https://api.example.com/v1/resource   # observe the 431 response and its headers
JavaScript (fetch)
const res = await fetch("https://api.example.com/v1/resource");
if (res.status === 431) {
  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 == 431:
    problem = res.json()  # field-level error details
    # correct the request before retrying — identical retries keep failing
    raise RequestProblem(problem)

Frequently asked questions

431 vs 414: both are 'too big'?

414 is the URI (request line) being too long; 431 is the header fields being too large. Different buffers, different fixes.

Why do I get 431 only in production?

Proxies and SSO add headers and cookies that your local environment never sees; the cumulative size crosses the edge buffer limit only in the full chain.

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 →