Skip to content
Preptima
hardDesignConceptMidSeniorStaff

How do you design the error contract for an API that other teams have to program against?

6 min readUpdated 2026-08-15Target archetype: Big Tech, Enterprise Captive, Product Startup

Answer

Short answer

Treat errors as published contract: an HTTP status that classifies the failure, a stable machine-readable code the client branches on, a human message that carries no internal detail, per-field detail for validation, and an explicit statement of whether a retry is safe.

The practical api design test is whether the designing the error contract for an answer gives the interviewer something concrete to challenge.

Was this answer helpful?

Likely follow-ups

  • You discover a client is retrying on 400. How do you find that out, and what do you change?
  • Where do you draw the line between 400 and 422, and does the distinction help the client?
  • How do you add a new error code without breaking clients that switch on the current set?
  • What goes in the response so support can trace one failed call, without leaking anything internal?

Related questions

Further reading