HTTP status codes tell the client what happened with their request. They are the first thing your API communicates before the response body, and choosing the right one makes your API predictable, debuggable, and pleasant to work with. Choosing the wrong one — or worse, returning 200 for everything — creates confusion and bugs.

This guide covers the status codes you will actually use, when to use each one, and how to design error responses that help developers fix their problems. If you are also working through the rest of your API’s design, see our REST API conventions guide.

The Five Categories

Status codes are grouped into five ranges:

Range Category Meaning
1xx Informational Request received, processing continues
2xx Success Request was successfully received and processed
3xx Redirection Further action needed to complete the request
4xx Client Error The request contains an error on the client side
5xx Server Error The server failed to fulfill a valid request

The first digit tells you the category. The other two digits provide specificity within that category.

2xx: Success Codes

200 OK

The request succeeded. The response body contains the requested resource or the result of the operation.

Use for: Successful GET requests, successful PUT/PATCH updates that return the updated resource, successful DELETE when returning confirmation data.

GET /api/users/123 HTTP/1.1

HTTP/1.1 200 OK
Content-Type: application/json

{"id": 123, "name": "Alice", "email": "alice@example.com"}

201 Created

A new resource was created successfully. The response should include the created resource and, ideally, a Location header pointing to it.

Use for: Successful POST requests that create a new resource.

POST /api/users HTTP/1.1
Content-Type: application/json

{"name": "Bob", "email": "bob@example.com"}

HTTP/1.1 201 Created
Location: /api/users/456
Content-Type: application/json

{"id": 456, "name": "Bob", "email": "bob@example.com"}

204 No Content

The request succeeded, but there is no content to return.

Use for: Successful DELETE requests, successful PUT/PATCH when you do not need to return the updated resource.

DELETE /api/users/123 HTTP/1.1

HTTP/1.1 204 No Content

Less Common 2xx Codes

  • 202 Accepted: The request has been accepted for processing but is not yet complete. Use for asynchronous operations like batch jobs or queued tasks.
  • 206 Partial Content: Used with range requests when the server returns only part of the resource (e.g., video streaming, resumable downloads).

3xx: Redirection Codes

301 Moved Permanently

The resource has permanently moved to a new URL. Clients and search engines should update their references.

HTTP/1.1 301 Moved Permanently
Location: /api/v2/users/123

302 Found (Temporary Redirect)

The resource is temporarily at a different URL. The client should continue using the original URL for future requests.

304 Not Modified

Used with conditional requests. The resource has not changed since the client’s last request, so the client can use its cached version.

GET /api/users/123 HTTP/1.1
If-None-Match: "etag-abc123"

HTTP/1.1 304 Not Modified

307 Temporary Redirect / 308 Permanent Redirect

Like 302 and 301, but they guarantee the HTTP method is preserved. A POST request redirected with 307 remains a POST. Use these for API redirects.

4xx: Client Errors

These are the codes you will use most often in APIs. They tell the client what they did wrong so they can fix it.

400 Bad Request

The request is malformed or contains invalid data.

Use for: Invalid JSON, missing required fields, validation errors, malformed query parameters.

POST /api/users HTTP/1.1
Content-Type: application/json

{"name": "", "email": "not-an-email"}

HTTP/1.1 400 Bad Request
Content-Type: application/json

{
  "error": "validation_error",
  "message": "Request validation failed",
  "details": [
    {"field": "name", "message": "Name is required"},
    {"field": "email", "message": "Invalid email format"}
  ]
}

401 Unauthorized

Authentication is required and has not been provided or is invalid. Despite the name, this is about authentication (who are you?), not authorization (what can you do?).

Use for: Missing API key, expired token, invalid credentials.

GET /api/users HTTP/1.1

HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer
Content-Type: application/json

{"error": "unauthorized", "message": "Valid API key required"}

403 Forbidden

The server understands the request and the client is authenticated, but the client does not have permission to access the resource. This is about authorization.

Use for: Insufficient permissions, accessing another user’s private data, feature not available on the current plan.

DELETE /api/users/123 HTTP/1.1
Authorization: Bearer valid-token-for-regular-user

HTTP/1.1 403 Forbidden
Content-Type: application/json

{"error": "forbidden", "message": "Admin role required to delete users"}

404 Not Found

The requested resource does not exist.

Use for: Invalid resource IDs, deleted resources, endpoints that do not exist.

GET /api/users/999999 HTTP/1.1

HTTP/1.1 404 Not Found
Content-Type: application/json

{"error": "not_found", "message": "User 999999 not found"}

409 Conflict

The request conflicts with the current state of the resource.

Use for: Duplicate entries, version conflicts, trying to transition a resource to an invalid state.

POST /api/users HTTP/1.1
Content-Type: application/json

{"email": "alice@example.com"}

HTTP/1.1 409 Conflict
Content-Type: application/json

{"error": "conflict", "message": "A user with this email already exists"}

422 Unprocessable Entity

The request syntax is valid, but the server cannot process the contained instructions. This is more specific than 400 — the JSON is valid, but the semantics are wrong.

Use for: Business logic validation errors that are not about syntax.

POST /api/orders HTTP/1.1
Content-Type: application/json

{"product_id": 123, "quantity": -5}

HTTP/1.1 422 Unprocessable Entity
Content-Type: application/json

{"error": "unprocessable", "message": "Quantity must be positive"}

429 Too Many Requests

The client has sent too many requests in a given time window.

Use for: Rate limiting. Always include headers telling the client when they can retry.

HTTP/1.1 429 Too Many Requests
Retry-After: 60
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 0
X-RateLimit-Reset: 1625097600
Content-Type: application/json

{"error": "rate_limited", "message": "Rate limit exceeded. Try again in 60 seconds."}

Other Useful 4xx Codes

  • 405 Method Not Allowed: The HTTP method is not supported for this endpoint (e.g., DELETE on a read-only resource)
  • 408 Request Timeout: The client took too long to send the request
  • 413 Payload Too Large: The request body exceeds the server’s size limit
  • 415 Unsupported Media Type: The Content-Type is not supported (e.g., sending XML to a JSON-only API)

For a quick lookup of any status code and its meaning, use our HTTP error lookup tool. You can also try the status code finder to search by description when you know what you need but not the code.

5xx: Server Errors

These mean something went wrong on your end. The client’s request was valid, but you could not process it.

500 Internal Server Error

A generic server error. Something unexpected went wrong.

Use for: Unhandled exceptions, unexpected states, bugs.

HTTP/1.1 500 Internal Server Error
Content-Type: application/json

{"error": "internal_error", "message": "An unexpected error occurred"}

Never expose stack traces, database errors, or internal details in 500 responses. Log them server-side.

502 Bad Gateway

The server, acting as a gateway or proxy, received an invalid response from the upstream server.

Use for: Reverse proxy errors, upstream service failures.

503 Service Unavailable

The server is temporarily unable to handle the request. Include a Retry-After header when possible.

Use for: Maintenance mode, overloaded server, temporary outages.

HTTP/1.1 503 Service Unavailable
Retry-After: 300
Content-Type: application/json

{"error": "service_unavailable", "message": "System maintenance in progress. Try again in 5 minutes."}

504 Gateway Timeout

The server, acting as a gateway, did not receive a timely response from the upstream server.

Designing Error Responses

A good error response helps the developer fix the problem without looking up documentation. Follow a consistent structure:

{
  "error": "validation_error",
  "message": "Human-readable description of what went wrong",
  "details": [
    {
      "field": "email",
      "message": "Must be a valid email address",
      "code": "invalid_format"
    }
  ],
  "request_id": "req_abc123",
  "documentation_url": "https://api.example.com/docs/errors#validation_error"
}

Best Practices for Error Responses

  1. Use a machine-readable error code: "validation_error" is parseable. "Something went wrong" is not.
  2. Include a human-readable message: Developers read these in logs and debugging sessions.
  3. Provide field-level details for validation errors: Telling the developer which field failed and why saves round-trips.
  4. Include a request ID: Essential for correlating client-side errors with server-side logs.
  5. Link to documentation: A URL to the relevant docs page helps developers self-serve.
  6. Never expose internals: Stack traces, SQL queries, file paths, and server versions are gifts to attackers.

Common Mistakes

Returning 200 for Everything

Some APIs return 200 with an error in the body:

{"status": "error", "message": "User not found"}

This breaks HTTP semantics. HTTP clients, proxies, CDNs, and monitoring tools all rely on status codes. A 200 with an error body is invisible to infrastructure-level tools.

Confusing 401 and 403

  • 401: “I do not know who you are” (missing or invalid credentials)
  • 403: “I know who you are, but you cannot do this” (insufficient permissions)

Using 500 for Client Errors

If the client sends invalid data, that is a 400, not a 500. A 500 means your server has a bug, and it triggers alerts. Do not cry wolf.

Not Using 429

If you rate limit clients but return 403 or 400, the client has no way to know they should back off and retry. Use 429 with Retry-After headers.

Summary

HTTP status codes are a shared vocabulary between your API and its consumers. Use 2xx to confirm success, 4xx to explain what the client did wrong, and 5xx to admit when your server failed. Be specific — 201 is more informative than 200 for resource creation, and 409 is more helpful than 400 for duplicate entries. Pair status codes with structured error responses that include machine-readable codes, human-readable messages, and enough detail to fix the problem. Your API consumers will thank you.