Deprecation and Sunset Headers for APIs - Announce Change Without Pretending It Enforces Migration
An API can remain technically available while its preferred path has already moved elsewhere. Documentation may explain the change, yet a client that only exchanges HTTP messages might never visit that page. How can the server make the lifecycle change visible at the resource itself without pretending that a notice is an enforcement mechanism?
The Deprecation and Sunset response headers address two different moments in that lifecycle. Used with typed Link headers, they can expose a machine-readable date and lead a developer to the human-readable migration details. The distinction matters: deprecation says “please stop building new dependence here,” while sunset says “this resource is expected to become unavailable around this time.” Neither header moves a client automatically.
Deprecation and sunset are two different dates
RFC 9745 defines Deprecation as a response field that signals that the resource identified by the response will be or has been deprecated. Crucially, the act of deprecation does not itself change the resource's behavior. A successful request does not become an error merely because the field appears, and the representation does not acquire new semantics.
The field carries the date when deprecation takes effect. That date may be in the future, allowing advance notice, or in the past, describing a resource that is already deprecated. Its wire syntax is a Structured Field Date: Unix-epoch seconds prefixed with @. For example, this value represents 1 March 2027 at 00:00:00 UTC:
Deprecation: @1803859200
This is not an HTTP-date string. The @ form comes from the Date type in RFC 9651, Structured Field Values for HTTP. Sending Deprecation: Mon, 01 Mar 2027 00:00:00 GMT would therefore use the wrong syntax for this field.
Sunset answers a later question. RFC 8594 defines it as the time when a resource is expected to become unresponsive. Unlike Deprecation, it uses the historical HTTP-date format:
Sunset: Wed, 01 Sep 2027 00:00:00 GMT
The difference in syntax is easy to miss because both fields describe dates. The difference in meaning is more important. A deprecated resource can keep working for a migration period. A sunset date signals expected retirement. When both fields are sent, RFC 9745 requires the sunset timestamp not to be earlier than the deprecation timestamp.
A date needs an explanation
A timestamp alone cannot tell a developer what replaces the old resource, whether authentication changes, which fields map to the new representation, or whom to contact when migration fails. Both specifications therefore pair their date fields with registered link relations.
Deprecation: @1803859200
Sunset: Wed, 01 Sep 2027 00:00:00 GMT
Link: <https://api.example.com/docs/migrations/orders-v1>; rel="deprecation"; type="text/html"
Link: <https://api.example.com/policies/retirement>; rel="sunset"; type="text/html"
The deprecation relation points to documentation about deprecation of the link's context. That page can contain the replacement resource, a migration sequence, examples, and the relevant timeline. The sunset relation identifies information about retirement policy. These relation names are not improvised labels: they are listed in the IANA Link Relations registry.
Under the Web Linking model in RFC 8288, a link is a typed connection between a context and a target. In the example, the response resource is the context, the documentation URL is the target, and deprecation or sunset explains their relationship. The type="text/html" parameter is only a hint about the target representation; it does not replace the target's actual Content-Type.
A small PHP response example
A native PHP endpoint can emit these fields with ordinary response headers. Keeping the dates in UTC and deriving each serialization from a date object reduces the chance that two manually copied timestamps drift apart:
<?php
$deprecation = new DateTimeImmutable('2027-03-01T00:00:00Z');
$sunset = new DateTimeImmutable('2027-09-01T00:00:00Z');
header('Deprecation: @' . $deprecation->getTimestamp());
header('Sunset: ' . $sunset->format(DATE_RFC7231));
header(
'Link: <https://api.example.com/docs/migrations/orders-v1>; ' .
'rel="deprecation"; type="text/html"',
false
);
header(
'Link: <https://api.example.com/policies/retirement>; ' .
'rel="sunset"; type="text/html"',
false
);
header('Content-Type: application/json');
echo json_encode(['orders' => []], JSON_THROW_ON_ERROR);
The second argument false tells PHP to add another field line rather than replace the previous Link field. RFC 8288 permits multiple links in one field value or across multiple Link field lines, so either serialization can be valid. What matters is that the application and its web-server/proxy path preserve the resulting fields.
This sample verifies formatting, not deployment behavior. A real application still needs tests at the public HTTP boundary because middleware, reverse proxies, caches, and error handlers may alter or omit headers. Responses other than the happy-path 200 also deserve an explicit decision: if a deprecated resource returns validation errors, should those responses carry the same lifecycle signal so active clients can still observe it?
Scope belongs to the resource carrying the response
By default, each field applies to the resource identified by the response in which it appears. A header returned by /v1/orders/42 therefore announces lifecycle information for that resource. It does not automatically declare every route under /v1/ deprecated.
An API may define a broader convention, such as publishing lifecycle fields only on an API home document. Both RFCs allow a service to document expanded scope. However, a generic client cannot infer that convention from the header alone. A client unaware of the service-specific rule sees only the standard, resource-level meaning.
This creates a practical choice rather than a universal answer. Sending the fields on every affected response improves visibility but adds implementation and testing work. Sending them only on a home or discovery resource centralizes the metadata but works only for consumers that inspect that resource and understand the documented scope. Whichever approach is chosen should be explicit in the API contract.
What a cautious client can do
A client can parse the fields, record the affected resource and dates, surface a warning in logs or developer tooling, and present the linked documentation for review. Build or integration checks might turn an already-effective deprecation into a visible warning. Teams can then schedule migration before the announced sunset.
Automatic migration is a much riskier response. The linked page may be stale, compromised, or interpreted outside its intended scope. RFC 9745 advises consumers to verify the authenticity and accuracy of deprecation documentation, while RFC 8594 warns that machine-readable migration information can effectively redirect resource identity at scale. RFC 8288 likewise cautions applications against automatically following or trusting links gathered from headers.
It is also unsafe to treat a sunset timestamp as a service-level guarantee. The resource might disappear earlier, remain available later, redirect, return a 4xx response, or fail in another way. Clients must continue to handle ordinary HTTP outcomes. Unknown or ignored headers are normal in HTTP, so a provider cannot assume every consumer saw the notice.
What these fields do not solve
Lifecycle fields complement communication; they do not replace it. Maintainers still need a stable migration guide, release notes or direct notices where appropriate, observability for remaining traffic, a rollback decision, and a clear post-sunset behavior. The fields neither negotiate a new API version nor authenticate a replacement endpoint.
Schedules can also change. A provider may postpone a retirement after discovering that an important consumer cannot migrate safely. That is another reason to treat both dates as lifecycle metadata rather than a distributed timer that clients execute blindly.
There is a disclosure tradeoff as well. RFC 8594 notes that sunset information can reveal expiration or retention details that were not otherwise visible. A public API retirement date may be harmless and useful; a per-user resource expiry might expose information that deserves the same access control as the representation itself.
A measured rollout
- Define exactly which resources are deprecated and what replaces them.
- Publish migration documentation before or with the first lifecycle signal.
- Choose a deprecation date and, only when there is a credible retirement plan, a later sunset date.
- Serialize
Deprecationas a Structured Field Date andSunsetas an HTTP-date. - Document any scope broader than the individual resource carrying the fields.
- Test headers on public responses, including relevant error paths and the reverse-proxy layer.
- Observe remaining usage and communicate through channels that important consumers actually monitor.
Conclusion
Deprecation and Sunset give an HTTP resource a small vocabulary for describing change: when dependence becomes discouraged, when availability is expected to end, and where a developer can learn what to do next. Their value comes from making lifecycle information discoverable in the protocol, not from enforcing a migration.
The honest implementation is therefore modest. Send correctly formatted dates, attach useful typed links, define scope carefully, and keep normal operational communication around them. A header can make a transition visible, but only maintained documentation and deliberate coordination can make that transition dependable.
References
- RFC 9745: The Deprecation HTTP Response Header Field - IETF, March 2025.
- RFC 8594: The Sunset HTTP Header Field - IETF, May 2019.
- RFC 9651: Structured Field Values for HTTP - IETF, September 2024.
- RFC 8288: Web Linking - IETF, October 2017.
- IANA Hypertext Transfer Protocol (HTTP) Field Name Registry.
- IANA Link Relations Registry.
