Skip to content

By the Octri team · Updated

201 Created

Share

A 201 means the request worked and the server made something new because of it. The response should say where the new thing lives, in a Location header, and usually carries it in the body too.

All HTTP status codes

Class
2xx success
Defined in
RFC 9110, section 15.3.2
Retry
Not needed
Key header
Location
Cacheable by default
No

When your API should return 201

Return 201 from a POST, or from a PUT to a new URL, when the call creates a resource your clients can fetch afterwards. A 200 works too and many APIs use it, but 201 tells a client that something was created without reading the body, which helps retry logic and anyone reading logs.

If the work hasn’t finished when you respond, that’s a 202. If the resource was already there, return 200 with it, or a 409 if that’s a clash. Put the new resource’s URL in Location so a client can fetch it without building the URL itself.

How public APIs declare 201 in their OpenAPI specs

We counted every operation in the eleven public specs we score, as they were on 4 December 2026. GitHub declares 201 on 142 operations, the most of any spec, and Box and Asana on 49 each. Stripe, Slack and Petstore return 200 for everything they create.

Location is rarer still. GitHub documents it on 30 of its 142 and OpenAI on 1 of 17, and nobody else documents it at all, so a reader of those docs has to guess whether it’s sent.

APIOperationsDeclare 201With Location
GitHub1,28814230
Asana302490
Box297490
Twilio197300
OpenAI406171
Adyen Checkout2890
Plaid35110
SendGrid Mail310
Stripe61200
Slack17400
Swagger Petstore1900

Counted per operation from each vendor’s public OpenAPI document on 4 December 2026.

Declare 201 in your OpenAPI spec

Declare the 201 with the schema of what was created and a Location header. Spelling the header out puts it in your docs, where a developer looks for it first.

yaml
paths:
  /invoices:
    post:
      operationId: createInvoice
      responses:
        "201":
          description: The invoice was created.
          headers:
            Location:
              description: URL of the new invoice.
              schema:
                type: string
                format: uri
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Invoice"

What an Octri SDK does with a 201

An Octri SDK treats every 2xx as a success and returns the body decoded into the type your spec declares for the operation’s success response.

Idempotency keys are on by default for POST and PATCH. If the connection drops before the 201 arrives, the SDK sends the request again with the same Idempotency-Key, so your API can recognise the retry and the caller doesn’t end up with two invoices.

typescript
import { Acme } from "acme-sdk";

const acme = new Acme({ apiKey: process.env.ACME_API_KEY });

// Resolves with the 201 body, typed as Invoice from your spec. If the
// connection drops first, the retry carries the same Idempotency-Key.
const invoice = await acme.invoices.create({ customerId: "cus_123", amount: 4200 });

More on retries and typed errors in SDK error handling.

HTTP 201 questions

Should a 201 response have a body?

Usually, yes. RFC 9110 only asks the server to identify what it created, but returning the new resource saves the client a second request to read fields the server filled in, like an ID or a timestamp.

Is 200 wrong for a create?

No. It’s allowed and common, and Stripe returns 200 for every create. A 201 carries a little more information, and your spec should say whichever one your API sends.

Can the Location header be a relative URL?

Yes. RFC 9110 allows a relative reference, resolved against the request URL. An absolute URL is easier for clients that log or forward it.

Should a PUT return 201?

Yes, when the PUT created the resource. When it replaced one that existed, return 200 or 204.

Share