The engineering API error response design decision record: why the error schema you chose determines your client error handling ceiling and your API evolution compatibility surface

API error response design is treated as an implementation detail — a field name, a status code, a JSON structure — not as a founding architectural decision with compatibility consequences that compound over years. The error schema that the first endpoint establishes propagates to every subsequent endpoint and every client that integrates the API. Three founding choices — the error response field set, the HTTP status code policy for application error categories, and the versioning contract for error codes — determine how completely clients can handle errors, how silently clients can fail when the schema evolves, and how much coordination is required when the error schema needs to change.

A 23-person developer tools company was building a workflow automation platform — a service that allowed software teams to configure automated workflows triggered by code events, test results, and deployment outcomes. The platform had three backend services: a Workflow API that handled workflow definition and scheduling, a Notifications API that managed delivery of workflow outcome alerts to Slack, email, and PagerDuty, and an Execution API that ran workflow steps and reported results. The three services were built by three different engineers over 18 months, each during a different phase of the company's growth, each inheriting a codebase that did not have an explicit error response design standard.

The Workflow API, built first, returned errors with a single message field: {"message": "Workflow not found"}. The engineer who built it considered error responses straightforward — the message field described what went wrong, the HTTP status code conveyed the error category, and clients could read the message to present an error to the user. No additional structure was needed for a service that had four endpoints and two error types at launch.

The Notifications API, built six months later by a second engineer, returned errors with an error field: {"error": "Invalid Slack webhook URL"}. The choice was habitual — the engineer had come from a previous company where the error field was the convention. The name difference between message and error seemed minor; both contained a human-readable string describing the problem. The engineer did not inspect the Workflow API's error format before choosing the field name.

The Execution API, built a year later by a third engineer who had joined as the team grew, used a JSON:API-inspired error format: {"errors": [{"status": "422", "title": "Invalid step configuration", "detail": "Step 'run_tests' requires a command field"}]}. The Execution API had complex multi-step validation, and the array format allowed multiple validation errors to be returned in a single response — a genuine usability improvement for clients trying to surface per-step error details. The engineer reviewed RFC 7807 and the JSON:API spec before choosing the format. The choice was deliberate and well-reasoned. It was also incompatible with the two existing services' error formats in every field name.

The web application client, a React SPA built alongside the Workflow API, had error handling written at launch that read from response.error.message. When the Notifications API shipped, a frontend engineer patched the error handler to try response.error.message first, then fall back to response.error.error. When the Execution API shipped, a second patch added a check for response.error.errors[0].detail. The web client's error handling had become a three-branch case statement — not documented anywhere, not enforced by types, and not tested end-to-end against all three service formats. It worked because the engineer who made each patch was careful and tested it manually before shipping.

The React Native mobile client was different. It was built eight months into the product by a contractor who was given access to the Workflow API documentation but not to the Notifications API documentation — the Notifications API had shipped internally and the external documentation hadn't been updated yet. The contractor implemented error handling against the Workflow API format: read response.error.message, display it to the user. The contract ended, the client shipped to the App Store, and the error handling worked correctly for all Workflow API errors.

Three weeks after the mobile client shipped, the platform's customer success team noticed a pattern in support tickets: mobile users were reporting that notification settings appeared to save successfully but their Slack notifications stopped working. The users didn't see an error message. The notification configuration form showed a spinner, then closed — which was the success behavior. The engineering team added logging to the mobile client and replicated the issue in a staging environment. When the Notifications API returned a {"error": "Invalid Slack webhook URL"} error, the mobile client read response.error.message — which was undefined for the Notifications API error format — and fell through to the success path because undefined was falsy and the error display logic was wrapped in if (errorMessage). A silent failure: the HTTP status code was 422, the error body was present, the client received both — and swallowed the error completely because the field name was wrong.

The fix was a one-line mobile client patch after the root cause was identified. The investigation took four hours. The issue had been present for three weeks, affecting every mobile user who tried to configure Slack notifications with an invalid webhook URL. The engineering team could not determine how many users had been silently failed — there was no client-side error logging for the fall-through path, only server-side request logs that showed 422 responses being returned without any subsequent retry from the client.

A 38-person B2B SaaS building a subscription billing platform for mid-market software companies had been shipping a payment API for two years. The error response schema included a code field that identified the specific payment failure type: PAYMENT_001 through PAYMENT_018. Each code was documented in the API reference with its meaning, its probable cause, and the recommended client action. The documentation had a note that read: "Error codes are informational. They are provided to assist with support triage and are subject to change as the billing infrastructure evolves." No enterprise customer had flagged the note as a concern.

After 18 months of operation, the billing platform had accumulated two payment processor integrations: Stripe for card payments and PayPal for PayPal wallet payments. The error codes had been defined for the original Stripe-only integration and had been patched with new codes for PayPal errors as they were discovered — a process that produced an irregular sequence (PAYMENT_013 through PAYMENT_018 were PayPal-specific codes added over six months) with no discernible organizational pattern. When a third payment processor integration was planned, the VP of Engineering proposed a refactor of the error code namespace to organize codes by payment processor: STRIPE_001 through STRIPE_010 for Stripe errors, PAYPAL_001 through PAYPAL_010 for PayPal errors, and GENERIC_001 through GENERIC_005 for processor-agnostic errors. The refactor was straightforward and well-motivated — the new namespace was more legible, more extensible, and would accommodate the third processor without further namespace pollution. The API changelog documented the full mapping from old codes to new codes. The engineering team classified the refactor as a non-breaking change because the existing error messages and HTTP status codes were unchanged; only the code field values were updated. The release shipped to production on a Tuesday.

By Thursday morning, the customer success team had flagged an anomaly in three accounts: payment recovery rate — the percentage of initially declined payments that were successfully recovered through automatic retry with an alternate payment method — had dropped from an average of 34% to approximately 11% across those three accounts. The accounts had no obvious connection in size, industry, or geography. The customer success lead escalated to engineering, noting that the decline had started precisely when the Tuesday release shipped.

The root cause was identified in two hours. All three affected customers had built client-side payment recovery flows that branched on specific error codes to determine when to trigger automatic retry with a backup payment method. PAYMENT_015 was the code for "card declined by issuer — retry with alternate payment method recommended" — the clearest signal that an automatic alternate-method retry had a reasonable probability of success. All three customers had implemented the same logic independently: catch the payment error, check if error.code === 'PAYMENT_015', if yes, trigger the automatic retry with the customer's backup card. After the refactor, PAYMENT_015 no longer existed. The equivalent code was now STRIPE_006. The clients received error responses with "code": "STRIPE_006", the if (error.code === 'PAYMENT_015') branch never fired, and the automatic recovery flow never triggered. The clients did not get an exception, a parse error, or any visible failure — they received a well-formed error response with an unexpected code value that fell through to the generic error handler, which logged the error and displayed a generic "payment failed" message to the user instead of triggering the alternate-method retry.

The recovery required coordinated redeployment across all three customer accounts. Each customer needed to update their error handling code to use the new code names, test the update in staging, and deploy to production. The engineering team provided a migration guide and offered expedited support. The 11-day window between the Tuesday release and the final customer account redeployment was 11 days during which those customers' payment recovery rates were 11% instead of 34% — a difference that represented real revenue: in aggregate across the three accounts, the reduced recovery rate represented approximately 180 additional subscription cancellations over the 11-day window that an effective alternate-method retry would have prevented. The post-incident review produced one recommendation: treat error codes as a versioned API contract, communicate breaking changes with a deprecation period and a migration guide issued in advance, and add enterprise customer notification to the release checklist for any change to error code values regardless of how the team classifies the change internally.

A 61-person enterprise SaaS building a data processing platform for insurance and financial services companies had been offering a bulk data import API for three years. The API accepted large CSV and JSON files — workflow templates, customer account data, policy records — and processed them asynchronously. The import flow was: POST to /imports with the file, receive HTTP 202 Accepted with an import job ID, poll /imports/{id}/status until the status field showed completed or failed.

The founding engineer who designed the import API had a clear rationale for the HTTP status code on the job status endpoint: the HTTP request to /imports/{id}/status always succeeded — the server received the request, found the import job in the database, and returned its current status. Whether that status was completed or failed was a property of the import job, not of the HTTP request. Returning HTTP 200 for a failed job reflected the semantic fact that the HTTP request had succeeded; the job outcome was in the response body. Returning HTTP 422 or HTTP 500 for a failed job would conflate the job failure with an HTTP-layer failure, which the founding engineer considered semantically incorrect. The rationale was recorded in a comment in the route handler and in a brief design note in the internal engineering wiki.

For the first two years, every consumer of the import API was an internal service or a customer using the platform's web UI, which explicitly polled the status endpoint and read the status field from the response body regardless of the HTTP status code. No external customer had raised a concern about the HTTP 200 response for failed jobs. The pattern appeared to be working correctly.

In the third year, an enterprise insurance company built a direct API integration to migrate their legacy policy records into the platform — a 15,000-record migration distributed across 32 batches of approximately 470 records each. Their engineering team built a polling integration using Python's requests library. The integration posted each batch, received the job ID, and polled the status endpoint in a loop. The polling loop was: response = requests.get(status_url); response.raise_for_status(); data = response.json(); if data['status'] in ('completed', 'failed'): break.

The integration code was correct — it checked data['status'] for both completed and failed. What the integration team had not considered was the platform's data validation rules for insurance policy records: the platform's import processor applied a set of business validation rules — required fields, format constraints, cross-field consistency checks — that were specific to the insurance policy template. If a record failed validation, the job status was set to failed and the error details were included in the response body. If the import job contained records that partially failed validation and partially succeeded, the platform's behavior was: set the job status to completed (not failed) and include a partial_failures array in the response with per-record failure details.

The integration team had read the import API documentation for the basic success and failure cases. The partial failure response format — documented in a section titled "Partial import results" that the integration team had skipped because they believed their source data was clean — returned HTTP 200 with "status": "completed" and a partial_failures array. The integration code checked data['status'] in ('completed', 'failed'), saw completed, and treated the job as fully successful without inspecting partial_failures.

The integration ran over three days. All 32 batches returned HTTP 200 with "status": "completed". The integration logged each batch as successful. When the migration was complete, the enterprise customer's data team began configuring their reporting environment and noticed an immediately apparent discrepancy: the platform showed 11,200 policy records. The customer had migrated 15,000. The customer reported a 25% data loss in their migration and asked engineering to investigate.

The investigation took three days and required the platform team to reconstruct which records had been silently dropped by parsing 32 batches of import job response bodies from the job history table. Of the 32 batches, 21 had returned partial_failures entries. The 3,800 silent failures were distributed across insurance policy records that failed the platform's cross-field consistency checks — specifically, records where the policy effective date was more than 180 days in the past, which the platform's validation rules treated as likely data quality issues requiring manual review. The validation rule had been added six months earlier for a different customer segment and had not been communicated to external API consumers as a new validation constraint. The rule was documented in the platform's data requirements guide, which the enterprise customer had not been given access to during their integration testing.

Three contributing decisions had combined to produce the silent data loss: the HTTP 200 response for the job status endpoint (which meant the integration's HTTP client library never raised an exception for any batch); the partial failure response format using status: completed rather than status: partial_failure (which meant the integration's explicit status check never triggered the failure path); and the undocumented addition of a new validation rule without an API changelog notification to external API consumers. The remediation required a data recovery process to identify and re-import the 3,800 failed records, a customer communication explaining the root cause and the remediation steps, and a 6-hour joint session between the platform team and the customer's data team to reconcile record-level validation failures and prepare a corrected re-import file. The incident review produced three recommendations: introduce a partial_failure status value to distinguish complete-success from partial-success, communicate validation rule additions to external API consumers as changes to the API's input contract, and add an explicit note to the import API documentation that the HTTP status code on the job status endpoint reflects the HTTP request outcome, not the import job outcome.

Structural properties set by the API error response design decision

Two structural properties are determined by the founding decisions about error response field set, HTTP status code policy, error code taxonomy, and versioning contract. Both are invisible during early development when the API has one or two services, a small number of error types, and a client base limited to internal consumers or early adopters who build direct integrations without production-critical branching logic. Both become visible as the API grows to multiple services, as error types proliferate, and as external consumers build production integrations that depend on specific error response properties for control flow decisions.

Property 1: Client error handling ceiling. The client error handling ceiling is the highest fidelity that any client can achieve in its error handling — the most specific, most actionable, most reliably correct error response a client can build — bounded by the properties of the error schema it integrates against. Three components. The schema consistency component: a client that integrates multiple services from the same platform must implement one error handling branch for each distinct error schema format; the client error handling ceiling for any given service is bounded by the least consistent error format the client must also support, because the error handling infrastructure must be generic enough to handle all formats without breaking on any. A client that correctly handles Format A and Format B but misses Format C does not raise an exception — it silently swallows errors from Format C, producing a behavioral failure that is harder to detect than a crash because there is no error to investigate, only a missing outcome. Connect to the API schema design decision record: the schema design decisions that govern success response field naming, field typing, and optional vs required field handling apply with equal force to error response schemas; a team that enforces schema consistency for success responses but treats error responses as implementation details will accumulate format divergence in the error schema at the same rate that new services and endpoints are added, and each divergence compounds the client's error handling complexity and the ceiling's height. The HTTP status code semantic alignment component: HTTP client libraries in every major language implement default behaviors keyed to HTTP status codes — axios raises an AxiosError for 4xx and 5xx responses, Python requests raises HTTPError when raise_for_status is called, Faraday raises on non-2xx responses by default, Go's net/http returns a non-error response for 2xx status codes. Applications that use 2xx status codes for error conditions receive responses that bypass all of these built-in behaviors — the client must check the response body explicitly on every request rather than relying on the HTTP client's error propagation, and any code path that forgets the explicit check silently treats application-level errors as successes. The partial failure representation is a specific sub-case: when a batch operation partially succeeds, using status: completed at the HTTP layer for a result that is semantically incomplete forces every client to implement its own partial-failure detection logic rather than relying on a status value that communicates incompleteness directly. Connect to the error handling strategy decision record: error handling strategy decisions about retry policies, exponential backoff, and circuit breaker thresholds assume that the error propagation path from the server to the client is reliable — that a failed request produces a detectable error rather than a successful-looking response; when the HTTP status code policy returns 2xx for application-level failures, the error handling strategy's retry and backoff logic receives no signal to act on, because the client library does not distinguish the 2xx error from the 2xx success. The error code semantic stability component: error codes that clients use to branch their error handling are contractual regardless of whether the API documentation classifies them as such. When a client builds a payment recovery flow that checks for error code PAYMENT_015 and triggers a retry with an alternate payment method, that code is load-bearing — it determines whether customers successfully recover from declined payments. Renaming PAYMENT_015 to STRIPE_006 in a refactor classified as non-breaking is a breaking change to every client that branches on the code, even if the rename is documented accurately in the API changelog. The semantic stability commitment for error codes must be communicated to API consumers as a versioning guarantee before they build production integrations against the codes — not communicated as a post-incident remediation after the integrations break.

Property 2: API evolution compatibility surface. The API evolution compatibility surface is the total coordination cost imposed on API consumers when the error schema evolves — the number of clients that require updates, the complexity of those updates, and the window between the API change and the clients' ability to handle it without degraded error handling. Three components. The error schema versioning component: in the absence of an explicit versioning contract for error responses, API consumers cannot distinguish schema changes that require client updates from changes that do not. A team that adds a new required field to the error response, adds a new error code category, changes an error code value, or changes the type of an existing field has made a change that may require client updates — but without a versioning contract, those clients have no advance notice, no deprecation period, and no mechanism for receiving the update without an interruption. Connect to the API versioning decision record: API versioning decisions about version identifiers, breaking change classification, and deprecation timelines are as applicable to error response schemas as to success response schemas; a team that versions its success response schema under a strict backward compatibility contract but treats the error schema as exempt from versioning will find that error schema changes impose the same compatibility burden on consumers as success schema changes — the asymmetric treatment does not reduce the burden, it only makes the burden invisible until the first incident. The error message stability component: error messages that contain human-readable descriptions of internal implementation details become implicit API contracts when clients begin matching on them. When the API's error message changes from "Database connection pool exhausted" to "PgBouncer connection limit reached" because the underlying infrastructure changed, every client that matches on the previous message text has a silent branching failure. The fix is not to tell clients to stop matching on message text — it is to provide a machine-readable error code that identifies the error category with the same specificity as the message text, so clients have a stable branching surface and messages can change freely. Connect to the API deprecation policy decision record: deprecation policy decisions about deprecation notice periods, sunset dates, and communication channels for breaking changes apply to error response properties; an error code that is renamed without a deprecation notice and migration window imposes the same client impact as a success response field that is renamed without notice — the client's production integration breaks at the moment the change is deployed, not at the moment the client is ready to migrate. The backward compatibility classification component: the absence of an explicit classification of which error response changes are breaking vs non-breaking means API teams apply inconsistent standards when evaluating proposed changes. Adding a new optional field is non-breaking. Adding a new required field is breaking. Adding a new error code is non-breaking. Renaming an existing error code is breaking. Changing an error message is non-breaking if no client branches on message text; it is breaking in practice when clients do branch on it. An explicit classification — documented in the API's versioning policy, included in the error response design ADR, and enforced in the release review process — is the mechanism that prevents the API team from inadvertently shipping breaking changes to production integrations in releases classified as non-breaking. Connect to the API rate limiting decision record: rate limit error responses are among the most commonly-branched error types in client integrations — clients implement retry-after logic, alternate endpoint routing, and usage monitoring against the rate limit error code and the Retry-After header; when rate limit error code values change (from RATE_LIMIT_EXCEEDED to domain-specific codes like REQUEST_QUOTA_EXCEEDED and RESOURCE_QUOTA_EXCEEDED in a refactor of the rate limiting model), every client that branches on the previous code value silently stops implementing correct retry behavior for rate limit errors; the backward compatibility classification for rate limit error code changes must be evaluated against the production impact on client retry behavior, not just the semantic correctness of the new code names.

The API error response design ADR: five sections

Section 1: Error response schema model. The error response schema model defines the standard field set for all error responses across all endpoints and services, the field naming and typing conventions, and the distinction between machine-readable and human-readable fields. The ADR must specify the complete field set for single-error responses and the structure for multi-error responses. Single-error schema: the minimum viable consistent schema has four required fields. The status field (integer) mirrors the HTTP status code in the response body, allowing clients that log or serialize the response body to include the status without separately tracking the HTTP response status code. The code field (string) is the machine-readable error identifier — the field clients should branch on for control flow decisions. The code namespace must be documented and version-controlled; the ADR specifies the namespace format (see Section 3: Error Code Taxonomy Model). The message field (string) is the human-readable description intended for developer troubleshooting and support triage. The ADR explicitly states that message text is not part of the versioning contract — clients should not branch on message text, and the documentation communicates this explicitly. The request_id field (string) is the unique request identifier for log correlation. Without request_id, the client's error report and the server's error log cannot be correlated without time-window searches that are expensive and unreliable. Multi-error schema for validation errors: the errors array alongside the top-level fields, where each array element contains field (the dot-notation path of the field that failed validation), code (a validation-specific error code that clients can match for per-field error display logic), and message (a human-readable description of the specific validation failure). The ADR must specify whether validation errors also include the top-level code field (recommended: yes, with a code like VALIDATION_FAILED that signals the error type at the top level before the client inspects the errors array). The RFC 7807 adoption decision is made in this section: if the API has external consumers, the ADR specifies whether to adopt RFC 7807 field names (type, title, status, detail, instance) as the base schema with code as a named extension field, or to use a custom schema. The rationale for the choice is documented: RFC 7807 provides portability for tooling (API clients, error monitoring integrations, API gateway configurations) that parses the standard, at the cost of field name changes from the team's existing convention if the API is already in production. Connect to the API schema design decision record: the error schema model is a subcomponent of the broader API schema design decisions; the type constraints, optional/required field policies, and null-handling conventions that the API schema design ADR establishes for success responses should apply identically to error responses, with the error schema model document referencing the main schema design ADR for the shared conventions rather than duplicating them.

Section 2: HTTP status code usage model. The HTTP status code usage model defines the mapping from application error categories to HTTP status codes, the policy for async operation failure representation, and the policy for partial success. The ADR must address the standard error category mapping explicitly rather than leaving it to individual engineers to interpret the HTTP specification. The standard mapping: 400 for client-caused errors where the request is malformed or syntactically invalid; 401 for authentication failures (missing, expired, or invalid credentials); 403 for authorization failures (authenticated but insufficient permissions); 404 for resources that do not exist; 409 for state conflicts (resource already exists, concurrent state change prevents the operation, idempotency key was already used with a different payload); 422 for semantic validation failures (well-formed request with field values that fail application validation rules); 429 for rate limit exceeded (must include Retry-After header); 500 for server-side failures where the client cannot fix the issue. The ADR must address two non-obvious cases. The async operation failure case: when an async operation fails (a background job, an import process, an async rendering task), what HTTP status code does the job status endpoint return for a failed job? The two defensible positions are: return HTTP 200 for the status endpoint unconditionally (the HTTP request to retrieve the status succeeded; the job outcome is a semantic property in the response body, not an HTTP-layer outcome) and return a job-category-appropriate HTTP status code when the job has failed (200 for a completed job, 4xx for a job that failed due to client-caused issues such as invalid input data, 5xx for a job that failed due to server-side issues). The ADR documents which position the team adopts and the rationale — not because one position is universally correct, but because a consistent, documented position allows client-side HTTP library configuration (such as raise_for_status) to be used reliably or explicitly not used. The partial success case: when a batch operation partially succeeds — some items processed, some failed — what HTTP status code is returned and what is the value of the top-level status field? The options range from HTTP 200 with a custom partial_success status value in the body, to HTTP 207 Multi-Status (the HTTP specification code for responses whose items have different status codes), to HTTP 422 for any batch that contains failures. The ADR specifies which approach the team adopts and communicates the decision to API consumers as part of the batch API documentation — not as a note buried in a "Partial import results" section that integrators may skip.

Section 3: Error code taxonomy model. The error code taxonomy model defines the error code namespace and format, the versioning contract for error codes, and the communication model for error code changes. The ADR must address namespace design, versioning commitment, and documentation requirements. The namespace design decision has two primary options: domain-namespaced codes (PAYMENT_METHOD_DECLINED, AUTH_TOKEN_EXPIRED, VALIDATION_REQUIRED_FIELD_MISSING) and category-namespaced codes (RESOURCE_NOT_FOUND, PERMISSION_DENIED, RATE_LIMITED). Domain-namespaced codes are more extensible — each service team can add new codes within their domain namespace without coordinating with other service teams on a shared taxonomy — but produce inconsistency across domains (PAYMENT_RESOURCE_NOT_FOUND and USER_RESOURCE_NOT_FOUND are semantically identical but have different code values). Category-namespaced codes are more consistent — RESOURCE_NOT_FOUND means the same thing in every domain — but require coordination when new error categories are added, because the shared namespace must accommodate all domains without collision. The ADR specifies which approach is used, documents the full initial code list at time of writing, and specifies the process for adding new codes (who approves additions, how additions are documented before they are deployed, how external consumers are notified of additions). The versioning contract is the most consequential part of this section: the ADR explicitly states whether error codes are contractual (stable across minor version releases; renamed only with a versioned breaking change announcement and migration period) or informational (may change between releases without a breaking change designation). If codes are contractual, the ADR specifies the minimum deprecation period for code renames (recommended: same as the API's success response deprecation period, typically 6–12 months) and the communication channel for deprecation announcements. The common failure mode — classifying codes as informational in the documentation while API consumers treat them as contractual in production integrations — is addressed preemptively by the ADR: the documentation for each error code specifies whether it is contractual or informational, and the default for all codes is contractual unless explicitly marked as informational. This inverts the implicit expectation that undocumented codes are safe to change, replacing it with an explicit commitment that undocumented codes are stable until explicitly deprecated.

Section 4: Error message stability policy. The error message stability policy defines which fields in the error response are part of the versioning contract and which are free to change between releases, and provides explicit guidance for client-side error handling that should branch on codes rather than messages. The core principle: the message field is a human-readable string that describes what went wrong for the engineer reading a log or debugging an integration. It is not a machine-readable identifier that clients should match against in control flow logic. The ADR explicitly states this in the documentation for the message field, with a specific example: "Do not write code like if (error.message.includes('connection pool')). Use error.code === 'SERVER_CAPACITY_LIMITED' instead. The message text may change between releases; the code value is stable and version-controlled." The policy also addresses the scenario where the available error codes are not specific enough to support the client's desired branching — the client wants to distinguish "rate limited because too many requests" from "rate limited because quota exceeded" but both return RATE_LIMIT_EXCEEDED. The correct response is not to match on the message text but to request a more specific error code. The ADR specifies the process for requesting new error codes from the API team, so API consumers have a channel for surfacing insufficient code specificity without workarounding it by matching on message text. The policy applies to all human-readable fields in the error response: the title field in RFC 7807 responses is defined as "should not change from occurrence to occurrence of the same problem type" — it is a stable short description of the error category, not a per-occurrence description; teams that use the title for messages like "Email john@example.com is already registered" rather than "Email address already registered" are using it incorrectly and will find that it accumulates the same stability problems as the message field. Connect to the error handling strategy decision record: the client-side error handling strategy decisions about how clients categorize errors into retry, escalate, and abort categories require stable machine-readable error identifiers to implement correctly; the error message stability policy that the API provides must align with the error categorization model the client error handling strategy expects — if the error handling strategy requires distinguishing transient errors (retry) from permanent errors (abort), the API error code taxonomy must provide codes that map to those categories, not just HTTP status codes that approximate them.

Section 5: Error schema versioning and backward compatibility model. The error schema versioning and backward compatibility model defines the versioning contract for error responses, the classification of changes into breaking and non-breaking categories, the communication model for breaking changes, and the sunset timeline for deprecated error codes. The ADR must specify the backward compatibility classification explicitly to prevent the team from inadvertently shipping breaking changes in releases classified as non-breaking. The non-breaking change categories: adding a new optional field to the error response (clients that do not read the new field are unaffected); adding a new error code to the taxonomy (clients that do not branch on the new code receive an unexpected value and fall through to their generic handler — a degraded experience but not a failure); adding more specific error codes as children of an existing code, where the original code is preserved for clients that only handle the top-level category. The breaking change categories: removing an existing field from the error response (clients that read the field receive undefined or a parse error); renaming an existing field (clients that read the original name receive undefined); changing the type of an existing field (clients that assume the original type may receive a parse error or behavioral failure); renaming an existing error code (clients that branch on the original code value silently stop matching, producing behavioral failures without exceptions); removing an existing error code without a replacement (clients that branch on the removed code have no migration path without a code change); changing the HTTP status code for an existing error type (clients that handle errors based on HTTP status code category rather than body content may receive unexpected behavior from their HTTP client library). The breaking change communication model: the ADR specifies the minimum advance notice period before a breaking change is deployed to production (recommended: 30 days for internal consumers, 90 days for external consumers), the communication channels (API changelog, email notification to registered API consumers, deprecation notice in the API response headers), and the dual-support period (the period during which both the old and new error schema are supported simultaneously, allowing clients to migrate without a hard cutover deadline). The sunset process for deprecated error codes: deprecated codes should be preserved in the response for the full deprecation period with a Deprecation response header specifying the sunset date, allowing clients to programmatically detect the impending code removal. After the sunset date, the deprecated code is removed and replaced with the new code. The process for documenting breaking changes in the ADR itself: each breaking change to the error schema that completes the full deprecation cycle should be recorded in the error response design ADR as an amendment, with the original decision, the reason for the change, the deprecation period, and the final sunset date — so the ADR remains the authoritative history of the error schema's evolution and the rationale behind each change, rather than a snapshot that becomes stale after the first revision.

FAQ

How should API error responses be structured for consistency across multiple services?

API error responses across multiple services should be structured around a shared schema contract — a fixed set of field names, field types, and field semantics that all services implement identically, so clients can write error handling logic once and apply it uniformly. The minimum viable consistent schema has four fields: status (integer, mirrors HTTP status code), code (string, machine-readable error identifier for client branching), message (string, human-readable description for developer troubleshooting — not for client branching), and request_id (string, unique request identifier for log correlation). For validation errors, an errors array alongside the top-level fields, where each element contains field (dot-notation field path), code (validation-specific code), and message (validation failure description). The design constraint that matters most: every field in the shared schema must be present in every error response from every service. Optional fields create format divergence — one service omits request_id when unavailable, another omits errors when there are no field-level errors — and each omission requires clients to handle the absent field explicitly rather than relying on a consistent schema. If a field cannot always be populated with a meaningful value, populate it with a consistent default: an empty array for errors when there are no field-level errors, an empty string for request_id when the request ID is not available in the response path. The practical mechanism for enforcing consistency: define the shared error schema in a single place — an internal SDK, a shared type definition library, or a JSON Schema specification — and require all services to serialize their error responses using that shared definition. When a service wants to add a service-specific field to the error response, it adds it to the shared schema as an optional field rather than diverging from the shared definition. The schema definition is the contract; every service's error serialization is an implementation of the contract.

What HTTP status codes should be used for different types of API errors?

HTTP status codes for API errors should follow the semantic definitions in the HTTP specification because every HTTP-aware component in the request path — load balancers, proxies, CDNs, API gateways, monitoring tools, client libraries — uses HTTP status codes to make routing, caching, retry, and alerting decisions. The standard mapping: 400 for client-caused errors where the request is malformed or syntactically invalid; 401 for authentication failures (missing, expired, or invalid credentials — the name 'Unauthorized' is misleading by convention; this code means unauthenticated); 403 for authorization failures (authenticated but insufficient permissions — the distinction between 401 and 403 matters: 401 means 'authenticate and retry,' 403 means 'different credentials will not help'); 404 for resources that do not exist; 409 for state conflicts (resource already exists, concurrent state change prevents the operation); 422 for semantic validation failures (well-formed request with field values that fail application validation); 429 for rate limit exceeded (must include Retry-After header); 500 for server-side failures the client cannot fix. The two decisions that most commonly cause problems: first, whether to use 400 or 422 for validation errors — the practical choice depends on whether clients want to distinguish malformed-request errors (fix the request structure) from invalid-data errors (fix the data values), and 422 enables that distinction; second, what status code to use on the job status endpoint when an async job has failed — returning HTTP 200 for a failed job is semantically defensible (the HTTP request to retrieve the status succeeded) but breaks HTTP client libraries that treat 2xx as success, while returning 4xx or 5xx for a failed job requires the client to catch HTTP exceptions to read job failure details rather than inspecting a successful response body. The ADR should document which position is taken and communicate it to API consumers explicitly, because the choice determines how clients must structure their polling loops.

When should you adopt RFC 7807 Problem Details for your API error responses?

RFC 7807 Problem Details defines a standard error response format with five fields: type (a URI identifying the problem type), title (a stable short summary of the problem type, same for all occurrences of the same type), status (HTTP status code mirrored in the body), detail (a human-readable explanation specific to this occurrence), and instance (a URI identifying the specific occurrence, equivalent to request_id). Adopt RFC 7807 when two conditions are both true: your API has external consumers who build production integrations, and you are designing the error schema before shipping rather than retrofitting it. For external APIs at inception, RFC 7807 provides a machine-readable error format that standard tooling can parse without custom configuration. For internal APIs consumed only by services you own, the portability benefit is small because all consumers are under your control. The practical consideration for the type field: the RFC specifies that type should be a stable URI with documentation. For teams that want the portability benefit without maintaining documentation URLs for every error type, populate type with a URN-style stable identifier such as urn:your-platform:errors:PAYMENT_METHOD_DECLINED — stable, machine-readable, and unique without requiring a documentation page per error type. Add your code field as a RFC 7807 extension field: the standard explicitly supports extension fields, so a response body of {"type": "urn:...:PAYMENT_METHOD_DECLINED", "title": "Payment method declined", "status": 402, "detail": "Visa card ending 4242 was declined by the issuer.", "code": "PAYMENT_METHOD_DECLINED", "request_id": "req_01JDX3..."} is fully RFC 7807 compliant while also providing a machine-readable code field that clients can branch on without parsing URNs. The key constraint for title: it must be a stable string that is the same for all occurrences of the same problem type — not a per-occurrence description. 'Payment method declined' is a correct title; 'Visa card ending 4242 was declined by the issuer at 2026-11-07T14:23Z' is not a title, it is a detail.

How do API error response design decisions connect to AI chat sessions and decision preservation?

API error response design decisions are made in short sessions that feel like implementation detail work but are founding decisions with long-lasting compatibility consequences — and they are almost always made in AI chat sessions where the team works through the tradeoffs in real time: whether to use a flat error schema with a single message field or a structured schema with code, message, and errors array (the flat schema is simpler for the first endpoint but forces clients to parse human-readable text to distinguish error categories, while the structured schema requires upfront field taxonomy that is expensive to retrofit after clients are in production); whether to adopt RFC 7807 now or build a custom schema that can be migrated later (the migration cost is non-trivial for external APIs because field name changes require a versioned breaking change announcement); why the job status endpoint returns HTTP 200 for failed jobs rather than a 4xx or 5xx (the founding engineer's reasoning — 'the HTTP request to retrieve the status succeeded; the job failed; those are semantically different events' — is a defensible position that is correct until the first enterprise customer integrates with a standard HTTP client that never inspects 2xx response bodies for failure indicators); why the error code namespace uses domain prefixes (PAYMENT_*, AUTH_*) rather than category prefixes (RESOURCE_NOT_FOUND, PERMISSION_DENIED) — not an arbitrary choice, but a deliberate tradeoff between namespace extensibility and cross-domain consistency that the team evaluated explicitly for the services they planned to build; why the error codes are documented as 'informational' in the first API guide — not because the team was unaware of the versioning implications, but because at two endpoints and three error types, treating codes as contractual would have imposed a formal versioning process that was disproportionate to the API's maturity; the decision record flags the threshold at which the team will reclassify codes as contractual (when the first external enterprise integration is onboarded). The reasoning in those sessions — the specific tradeoffs between schema simplicity and client branching capability, the specific analysis of which HTTP status code policy aligns with the HTTP client libraries the platform's customers use, the specific decision about where HTTP semantics end and application semantics begin for async job failures — is the substance of the error response design. It is almost universally made and immediately discarded, leaving every engineer who joins the team afterward to infer intent from the implemented schema. The engineer who asks 'why do we return HTTP 200 for failed jobs?' six months into the product will get 'that's how it was built' rather than the founding reasoning — unless the AI chat sessions that made the decision were run through the open-source extractor and the decision record was produced at the time. The decision record allows the engineer inheriting the API to understand why the error schema uses a flat message field rather than a structured code and detail separation (not because the founding engineer did not understand the tradeoff, but because the first version had exactly three endpoints and two error categories — the structured schema would have been premature; the decision record also documents the team's intent to migrate to RFC 7807 when the API reaches external consumers, so the migration is planned rather than discovered); and why error codes are classified as informational rather than contractual in the initial documentation (not because the team intended to break integrations, but because the API was internal-only at launch and the versioning overhead was not yet justified — the decision record specifies the trigger for reclassifying codes as contractual, which is information that the note 'Error codes are informational' in the API documentation cannot convey).