Retiring API versions with the Deprecation and Sunset headers
Every API eventually carries endpoints that nobody wants to maintain and somebody still calls. Retiring them is less a technical problem than a communication problem — and HTTP now has standard headers that put the communication where integrators actually look: in the responses their code already receives.
Contents
Key facts
- RFC 9745, published in March 2025, defines the Deprecation HTTP response header field and a deprecation link relation.
- RFC 8594 defines the Sunset header field, which announces when a resource is expected to become unresponsive.
- RFC 9745 requires that the Sunset timestamp must not be earlier than the Deprecation timestamp.
- Deprecation does not change behaviour: a deprecated resource keeps working until it is actually removed.
Why deprecations fail
A typical deprecation goes like this: a note in the changelog, an email to the address registered years ago, a date chosen by the team that wants to delete code. On the sunset date the endpoint is switched off and support receives tickets from integrators who never saw any of it. The team rolls back, the date slips, and the old endpoint lives on indefinitely.
The root causes are predictable. The provider does not know who still uses the endpoint. The notice reaches people who are not the ones maintaining the integration. And nothing in the integrator's normal workflow — their code, their logs, their monitoring — signals that a change is coming.
A good process fixes all three: measure usage per client, communicate through several channels including the responses themselves, and set dates based on observed migration progress rather than wishful thinking.
Start with compatibility rules
Deprecation should be rare, and that starts with deciding what counts as a breaking change. A written compatibility policy lets most changes ship without any version bump.
| Change | Usually compatible? | Note |
|---|---|---|
| Add an optional request field | Yes | Server must have a default |
| Add a response field | Yes | Only if clients ignore unknown fields — say so in the docs |
| Add an enum value in a response | Risky | Strict clients may reject unknown values |
| Remove or rename a field | No | Requires deprecation |
| Tighten validation | No | Previously valid requests start failing |
| Change error format or status codes | No | Clients branch on them |
Encode these rules in an automated check. Tools that compare two versions of an OpenAPI document can flag removed fields, changed types and new required parameters in CI, so a breaking change cannot be merged without an explicit decision.
Signalling deprecation at runtime
The Deprecation header lets the server tell a client, in each response, that the resource it just used is deprecated — or will be from a given date. Its value is a date expressed as a structured-field date (an integer number of seconds since the epoch, prefixed with @). A Link header with the deprecation relation can point to human-readable documentation.
The Sunset header from RFC 8594 adds the second date: when the resource is expected to stop responding. Used together, they give client code everything it needs to raise a warning, open a ticket or fail a CI job long before the endpoint disappears.
HTTP/1.1 200 OK
Content-Type: application/json
Deprecation: @1788220800
Sunset: Mon, 01 Mar 2027 00:00:00 GMT
Link: <https://developer.example.com/changes/v1-orders>; rel="deprecation"; type="text/html"Note the two formats: Deprecation uses the structured-field date defined in RFC 9745, while Sunset uses an HTTP-date. Generate both from the same configuration so they cannot disagree, and validate in tests that the sunset is never earlier than the deprecation date.
Know who is still calling
Runtime headers only help clients that read them. The provider still needs to know who is affected. Record usage per client credential, endpoint and version — as a metric with bounded labels, or from access logs into an analytics store. That gives you three things: the list of integrators to contact, a migration curve to track, and evidence for when it is safe to switch off.
- Contact the technical owners of active clients directly, not only a generic newsletter list.
- Publish the migration guide before the deprecation date, with request and response examples for the replacement.
- Send reminders at fixed points — for example 90, 30 and 7 days before sunset — to clients still calling.
- Offer a sandbox where integrators can test the replacement without production risk.
The switch-off
Turning an endpoint off should be a gradual, reversible operation. A useful technique is the brown-out: shortly before the sunset, return errors for short scheduled periods so that clients still calling notice in their monitoring while there is time to react. Announce the brown-out schedule in advance.
After the sunset date, return a clear, documented error — commonly 410 Gone with a Problem Details body that links to the migration guide — instead of a generic 404. Keep the routing rule for a while so you can see who still calls, and only then remove the code.
Deprecating internal APIs
The same process works inside an organisation, often with less ceremony. Internal consumers can be identified precisely through service identities or tracing data, migration can be tracked in the same ticketing system, and deprecation headers can trigger warnings in the consumers' logs or tests. What changes is the timeline: internal deprecations can move faster, but they still fail when the owning team switches something off without knowing who depends on it.
Worked example: retiring an orders endpoint
An API exposes GET /v1/orders, which returns prices as floating-point numbers. The replacement GET /v2/orders returns integer minor units and a currency field.
- The v2 endpoint ships first. The compatibility check confirms it is additive.
- Usage data shows 37 client credentials calling v1 in the last 30 days; their owners are contacted with the migration guide.
- v1 responses start carrying Deprecation, Sunset (six months later) and a Link to the guide.
- The provider tracks weekly v1 traffic per client. Reminders go to the remaining callers at 90, 30 and 7 days.
- Two weeks before sunset, three ten-minute brown-outs return 410 with a pointer to the guide.
- On the sunset date the route returns 410 Gone; traffic is monitored for another month before the code is removed.
The date is moved only if a significant integrator has a credible migration plan and asks for it — and the new date is communicated through the same headers.
Common pitfalls
- Announcing deprecations only in a changelog that integrators do not read.
- Choosing the sunset date before measuring who still calls the endpoint.
- Sending Sunset and Deprecation from separate configuration so the dates disagree.
- Returning 404 after sunset, which looks like a typo rather than a planned removal.
- Removing code immediately after the sunset date, losing visibility of late callers.
- Treating every change as breaking because no compatibility policy exists.
FAQ
Should we version in the URL or in a header?
Both work. URL versions are visible and easy to route; header or media-type versions keep URLs stable. What matters more is a clear compatibility policy so new versions are rare.
How long should the deprecation period be?
Long enough for your slowest important integrator to plan and ship a change — often several months for partner APIs. Measure migration progress and adjust.
Can clients act on the headers automatically?
Yes. Client libraries can log a warning or fail tests when a response carries Deprecation, which turns the header into an alert inside the integrator's own pipeline.
Checklist
- Written compatibility policy and an automated breaking-change check in CI.
- Per-client usage tracking for every endpoint and version.
- Deprecation, Sunset and Link headers generated from one configuration.
- Migration guide published before the deprecation date.
- Reminder schedule and brown-outs announced in advance.
- 410 Gone with Problem Details after sunset; code removed only after monitoring.