Skip to content

By the Octri team · Updated

400 Bad Request

Share

A 400 means the server couldn’t or wouldn’t process the request because something about it is wrong. The response body is where your API says what, and a 400 without one leaves the developer guessing.

All HTTP status codes

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.

APIOperationsDeclare 400How errors are described
Asana302301Per status code
OpenAI406290Per status code
GitHub1,288124Per status code
Box297100Per status code, plus a default
Adyen Checkout2820Per status code
Swagger Petstore1915Per status code, plus a default
SendGrid Mail33Per status code
Plaid3511One default error response
Stripe6120One default error response
Twilio1970No error responses
Slack1740One 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.

yaml
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: string

What 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.

typescript
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.

Share