- Class
- 4xx client error
- Defined in
- RFC 9110, section 15.5.1
- Retry
- No, fix the request
- Body
- Say what’s wrong
- Cacheable by default
- No
When your API should return 400
Return 400 when the request is malformed, like JSON that doesn’t parse, a missing required field, a query parameter of the wrong type or a header in the wrong format. Point at the field in the body, using a format like RFC 9457 problem details, so the developer can fix it without opening a support ticket.
Some APIs keep 400 for requests they can’t parse and use 422 when the request parses and the data breaks a rule, like an end date before a start date. Others use 400 for both. Either works if you pick one and document it. Missing or bad credentials are a 401, and an unsupported Content-Type is a 415.
How public APIs declare 400 in their OpenAPI specs
Eight of the eleven public specs we score declare a 400, as they were on 4 December 2026. Asana declares it on all but one of its 302 operations, and OpenAI on 290 of 406.
GitHub declares 400 on 124 operations and 422 on 381, so most of its validation errors come back as a 422. Stripe, Slack and Twilio don’t name 400 at all.
| API | Operations | Declare 400 | How errors are described |
|---|---|---|---|
| Asana | 302 | 301 | Per status code |
| OpenAI | 406 | 290 | Per status code |
| GitHub | 1,288 | 124 | Per status code |
| Box | 297 | 100 | Per status code, plus a default |
| Adyen Checkout | 28 | 20 | Per status code |
| Swagger Petstore | 19 | 15 | Per status code, plus a default |
| SendGrid Mail | 3 | 3 | Per status code |
| Plaid | 351 | 1 | One default error response |
| Stripe | 612 | 0 | One default error response |
| Twilio | 197 | 0 | No error responses |
| Slack | 174 | 0 | One default error response |
Counted per operation from each vendor’s public OpenAPI document on 4 December 2026.
Declare 400 in your OpenAPI spec
Declare 400 once under components with a named error schema, and reference it from each operation. A named schema is what lets a generated SDK hand the caller a typed error body.
paths:
/invoices:
post:
operationId: createInvoice
responses:
"201":
$ref: "#/components/responses/InvoiceCreated"
"400":
$ref: "#/components/responses/BadRequest"
components:
responses:
BadRequest:
description: The request is malformed. The body says which field.
content:
application/json:
schema:
$ref: "#/components/schemas/Problem"
schemas:
Problem:
type: object
required: [type, title, status]
properties:
type:
type: string
format: uri
title:
type: string
status:
type: integer
detail:
type: string
errors:
type: array
items:
type: object
properties:
field:
type: string
message:
type: stringWhat an Octri SDK does with a 400
An Octri SDK doesn’t retry a 400, since the same request will fail the same way. The caller gets an SdkBadRequestError with the status, the headers, the body and the request ID, in TypeScript, Python, Java, Kotlin, PHP and Ruby.
In TypeScript and Python, the error’s data holds the body decoded into the model your spec declares for 400. Without one the SDK falls back to a 4XX model, then to default, so a single named error schema covers every code.
import { Acme, SdkBadRequestError } from "acme-sdk";
const acme = new Acme({ apiKey: process.env.ACME_API_KEY });
try {
await acme.invoices.create({ customerId: "cus_123", amount: -5 });
} catch (err) {
if (err instanceof SdkBadRequestError) {
// Decoded into the Problem schema your spec declares for 400.
console.log(err.data, err.requestId);
}
throw err;
}More on retries and typed errors in SDK error handling.
HTTP 400 questions
Is a 400 always the client’s fault?
Partly. It says the request was wrong, but a bug in your API’s validation, like rejecting a valid date format, shows up as a 400 too. If 400s jump after a release, check your side first.
Should a 400 list every invalid field?
Yes, when you can. A developer who fixes one field and then gets a new 400 for the next one makes several round trips to fix a single form.
Is there a standard format for 400 bodies?
Yes. RFC 9457 problem details defines type, title, status, detail and instance, served as application/problem+json, and you can add your own fields like a list of errors.