400 Bad Request means: The server cannot or will not process the request because it appears malformed or invalid: bad syntax, invalid framing, deceptive routing, or a payload that fails validation. It is the generic client-error answer when no more specific 4xx fits. 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 400 when malformed json or a missing required field in the request body; invalid query parameters, headers or url encoding; a request that violates api validation rules (types, ranges, formats). On the client side, inspect the error body for field-level details, fix the payload or parameters, and retry only after correcting the request — blind retries will keep failing. On the server side, return structured error details (field, reason, expected format) instead of a bare 400; reserve it for genuine request problems, not server bugs.
When 400 happens
- Malformed JSON or a missing required field in the request body
- Invalid query parameters, headers or URL encoding
- A request that violates API validation rules (types, ranges, formats)
How to fix it
On the client
Inspect the error body for field-level details, fix the payload or parameters, and retry only after correcting the request — blind retries will keep failing.
On the server
Return structured error details (field, reason, expected format) instead of a bare 400; reserve it for genuine request problems, not server bugs.
Should you retry?
Not retryable as-is: change the request (credentials, payload, URL) first.
Debugging steps
When 400 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: malformed json or a missing required field in the request body. 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
A bare 400 with no error body is a debugging dead end: structured field-level details turn a generic rejection into an actionable fix, and distinguish syntax errors from semantic ones (422).
Examples
HTTP/1.1 400 Bad Request
Content-Type: application/json
Content-Length: 107
{
"error": "bad_request",
"message": "Malformed JSON or a missing required field in the request body"
} curl -i https://api.example.com/v1/resource # observe the 400 response and its headers const res = await fetch("https://api.example.com/v1/resource");
if (res.status === 400) {
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 == 400:
problem = res.json() # field-level error details
# correct the request before retrying — identical retries keep failing
raise RequestProblem(problem) Frequently asked questions
400 vs 422: which should my API use?
400 for syntactically invalid requests (bad JSON, missing fields); 422 for well-formed requests whose semantics fail validation. Many frameworks default everything to 400 — either is defensible if consistent.
Why do I get 400 with no error message?
Some servers (and proxies) emit bare 400s for header/frame problems before your application code runs. Check raw request framing, Content-Length, and header validity.
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.