406 Not Acceptable means: The server cannot produce any representation matching the client's Accept headers (content negotiation failed). The client asked for formats the resource does not have, and proactive negotiation found no acceptable variant. 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 406 when accept: application/xml sent to a json-only api; accept-language demanding a language the content does not exist in; a strict accept charset or encoding the server cannot satisfy. On the client side, relax or correct the Accept headers to formats the API actually offers (usually application/json); inspect the body for available alternatives. On the server side, document supported media types; either pick a sensible default instead of failing, or return 406 with a list of available representations.
When 406 happens
- Accept: application/xml sent to a JSON-only API
- Accept-Language demanding a language the content does not exist in
- A strict Accept charset or encoding the server cannot satisfy
How to fix it
On the client
Relax or correct the Accept headers to formats the API actually offers (usually application/json); inspect the body for available alternatives.
On the server
Document supported media types; either pick a sensible default instead of failing, or return 406 with a list of available representations.
Should you retry?
Not retryable as-is: change the request (credentials, payload, URL) first.
Debugging steps
When 406 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: accept: application/xml sent to a json-only api. 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
406 is about the response the client will accept (Accept), while 415 is about the request body the client sent (Content-Type) — mixing up these two headers is the classic cause of both errors.
Examples
HTTP/1.1 406 Not Acceptable
Content-Type: application/json
Content-Length: 95
{
"error": "not_acceptable",
"message": "Accept: application/xml sent to a JSON-only API"
} curl -i https://api.example.com/v1/resource # observe the 406 response and its headers const res = await fetch("https://api.example.com/v1/resource");
if (res.status === 406) {
const problem = await res.json(); // read field-level details
// fix the request (credentials, payload, URL) — identical retries keep failing
throw new RequestError(problem);
} import requests
res = requests.get("https://api.example.com/v1/resource", timeout=10)
if res.status_code == 406:
problem = res.json() # field-level error details
# correct the request before retrying — identical retries keep failing
raise RequestProblem(problem) Frequently asked questions
406 vs 415: what is the difference?
406 is about the response the client will accept (Accept header); 415 is about the request body the client sent (Content-Type header).
Why do browsers rarely hit 406?
Browsers send permissive Accept headers. 406 mostly appears in API clients with strict or mistaken Accept values.
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.
Try the JSON Validator
Check JSON syntax and locate errors by line and column.