- Class
- 4xx client error
- Defined in
- RFC 9110, section 15.5.5
- Retry
- No
- Fix
- Check the ID or path
- Cacheable by default
- Yes
When your API should return 404
Return 404 when the resource in the path doesn’t exist, like /invoices/inv_999, and when the path itself isn’t one your API serves. Say which in the body, since “no such invoice” and “no such endpoint” get fixed in different places.
If the resource existed and was removed for good, a 410 says so. If the path exists and the method doesn’t, like a PATCH on a read-only resource, that’s a 405. A 404 is also the safe answer for a resource the caller isn’t allowed to know about.
How public APIs declare 404 in their OpenAPI specs
Six of the eleven public specs we score declare a 404, as they were on 4 December 2026. GitHub declares it on 717 of its 1,288 operations and Asana on all but one of its 302.
Stripe, Slack, Plaid and Twilio don’t name it, although every one of them has endpoints that take an ID.
| API | Operations | Declare 404 | How errors are described |
|---|---|---|---|
| GitHub | 1,288 | 717 | Per status code |
| Asana | 302 | 301 | Per status code |
| OpenAI | 406 | 291 | Per status code |
| Box | 297 | 141 | Per status code, plus a default |
| Swagger Petstore | 19 | 8 | Per status code, plus a default |
| SendGrid Mail | 3 | 2 | Per status code |
| Stripe | 612 | 0 | One default error response |
| Plaid | 351 | 0 | One default error response |
| Twilio | 197 | 0 | No error responses |
| Slack | 174 | 0 | One default error response |
| Adyen Checkout | 28 | 0 | Per status code |
Counted per operation from each vendor’s public OpenAPI document on 4 December 2026.
Declare 404 in your OpenAPI spec
Declare 404 on every operation with an ID in its path, pointing at one shared response.
paths:
/invoices/{invoiceId}:
get:
operationId: getInvoice
responses:
"200":
$ref: "#/components/responses/Invoice"
"404":
$ref: "#/components/responses/NotFound"
components:
responses:
NotFound:
description: No invoice has this ID.
content:
application/json:
schema:
$ref: "#/components/schemas/Error"What an Octri SDK does with a 404
An Octri SDK doesn’t retry a 404. The caller gets an SdkNotFoundError in TypeScript, Python, Java, Kotlin, PHP and Ruby, so “not found” can be handled as an expected case without parsing a message.
That keeps the common fetch-or-create pattern short. Catch the one class, create the resource, and let every other error through.
import { Acme, SdkNotFoundError } from "acme-sdk";
const acme = new Acme({ apiKey: process.env.ACME_API_KEY });
async function findInvoice(invoiceId: string) {
try {
return await acme.invoices.get({ invoiceId });
} catch (err) {
if (err instanceof SdkNotFoundError) return null;
throw err;
}
}More on retries and typed errors in SDK error handling.
HTTP 404 questions
Should an empty list return 404?
No. GET /invoices with no invoices worked and found nothing, so return 200 with an empty array. Keep 404 for a specific resource that doesn’t exist.
Can a 404 be retried?
Partly. A resource created a moment ago may not be visible yet on a read replica, so a short retry can work. Otherwise the same request keeps failing.
Should a 404 include a body?
Yes. A JSON error with the resource type and ID helps the developer spot a typo in the ID, and it tells them the endpoint exists.