---
agent:
  instructions: "Use this search API to find relevant content across this site with keywords or natural-language queries, instead of crawling individual pages. Results are returned in Markdown."
  endpoint: "https://arihantgv.com/.well-known/search?q={query}"
  method: "GET"
  documentation: "https://developers.cloudflare.com/ai-search/how-to/search-for-agents/"
---

# API Compatibility for Long-Lived Interfaces

How to change an interface that other teams and vendors already call: versions, additive changes, deprecation, and the tests that catch a break.

A payroll feed, a case-status query, a procurement notice, a partner billing call: in an enterprise or a public institution these interfaces outlive the team that built them. Callers include other divisions, integrators on multi-year contracts, packaged products you do not patch, and sometimes another public body. You can change your code. You cannot redeploy theirs. This guide covers consumers you do not control, additive and breaking changes, explicit versions, deprecation windows, contract tests, error semantics, idempotency keys, and a changelog a buyer can read.

## Consumers you do not control

The caller that matters does not share your release train. An internal team can often take a change in the same sprint. A vendor on a fixed-price contract cannot. A packaged product may expose the interface only through configuration. Another agency may be frozen through year-end processing. Some callers are batch jobs nobody has opened since handover. They remain entitled to the behavior they built against until they have a real chance to move.

Staff turnover does not reset that promise. The interface belongs to the organization, and new owners inherit callers who never filed a ticket. If you cannot name who calls an operation, assume the list is longer than the logs suggest, and change the interface more slowly.

Write the rules while you still know them: the operations, the fields a caller may rely on, whether unknown fields must be ignored, how long a version lives, and how a break is announced. Public-sector programs usually put this in an interface control document a contract can cite. A large enterprise puts it next to the API standard. Design the first version for a stranger calling it years later: explicit fields, stable error codes, and no message text meant to be parsed. Coordination with known consumers is useful, and it is not a plan for the callers you cannot schedule.

## Additive changes and breaking changes

A change is additive when every caller who followed the contract can keep the same requests and the same reading of the response. It is breaking when at least one of those callers must change. Someone who already violated a written rule is not the constraint.

On a request, a new required field, a narrower type, a newly rejected value, a rename, or an optional field made required is a break. On a response, removing or renaming a field, changing a type, or dropping a field you promised to send is a break. So is a new default for page size, sort order, timezone, rounding, or null, even when the schema text is unchanged. Callers bind to behavior.

You can usually add an optional request field, a response field, or a new operation, but only if callers must ignore what they do not recognize. Generated clients often reject unknown fields and unknown enumeration values. A new status is the usual false additive change: the schema grows, and an exhaustive branch throws. If the set must grow, say so in the first contract, with a documented fallback for unrecognized values or a string for open-ended state beside a closed code.

A body that still parses can still be a break. A retryable error that becomes terminal, pagination that no longer lines up, and an idempotency key that creates a second record all belong on the same list as a renamed field. The rule that makes addition safe has to be in the contract: consumers ignore unknown fields, and a field is never given a new meaning.

## Explicit versions

A version is a named set of behavior you keep until a published end date. Callers pin it. It is not a date on a file, and it is not the word "latest." A break is a new version. The previous one stays up for the deprecation window.

Put the identifier where logs already show it. A path segment does not depend on headers surviving every proxy. A header or a content type is fine only when every gateway, mock, and document you operate will keep it. Use one signal on every operation. Two signals that can disagree will disagree at cutover.

Support few versions, because each one must be patched, tested, and explained. Prefer additive edits inside the current version. Open another for a break you cannot avoid, or for one deliberate bundle of breaks, not once per release.

For each version, publish the operations, schemas, error codes and which are retryable, idempotency rules, pagination, and authentication at a stable address. Generate it from the same OpenAPI document, or equivalent, that the tests run. Do not keep a second copy that can drift, and do not offer an unversioned URL that silently tracks the newest behavior. A default path, if you keep one, names a real version and moves only on sunset notice. How versioning sits with gateways and events is in the [enterprise integration strategy guide](/guides/enterprise-integration-strategy-guide/). Record the policy in an [architecture decision record](/guides/architecture-decision-records-explained/).

## Deprecation windows

The window runs from the announcement that a version or field will end until those calls fail. Publish the length before the first external caller, so a solicitation or statement of work can price the upgrade.

Callers who ship every week can sometimes use a short window. A public institution on a multi-year integration often cannot: the work may need a contract change, a shared test slot, and a date outside a statutory freeze. Across organizations, plan on a year or more, and shorten it only for a security defect you explain in the changelog.

Notice has to reach someone who can schedule the work. A commit the buyer never sees is not notice. Use the changelog, the interface control document, the named support contact, and the HTTP `Deprecation` and `Sunset` headers where the stack supports them. Say what ends, what replaces it, and when calls will fail, and repeat that before the window is half gone.

Until that date, the old version receives security fixes and repairs that restore documented behavior, not new features. Features on a dying version remove the reason to migrate. When the date arrives, fail with a stable error that names the retired version and points to the migration note. Executing those calls as the new behavior is a break of its own. Traffic charts do not justify an earlier end. A monthly job, or a system that appears only during annual enrolment, can be missing from a dashboard and still be relying on you.

## Contract tests that catch a break

Contract tests fail the build when the published promise changes by accident. They do not replace end-to-end tests. They check whether a stranger's view of the interface still matches what you last published.

Test the file callers download. A suite aimed at an internal model stays green while the portal serves a different contract. If the pipeline generates that file, fail when the generated copy and the published copy differ.

In continuous integration, diff the candidate against every version you still support. Additive changes pass. Breaking changes fail unless they are aimed at a new version on purpose. OpenAPI and other schema diff tools exist; the merge rule is the part that matters. Also fail when an example loses a field, or when a newly required property appears in no example.

Schemas miss behavior. Keep a short fixture list: status, error code, and body shape for a valid call, a malformed field, a missing credential, an idempotency key reused with a different body, and a version treated as retired. That list is what catches two codes that swapped meanings, or a retry that writes a second record and returns success. For a system of record, or one strategic caller, also replay that caller's requests and the fields it reads. Provider-side fixtures still cover the callers you cannot replay. Give each live version its own fixtures, updated in the same change as its contract.

## Error semantics that stay stable

Retry logic written against your errors is part of the interface. Change it in place and callers create duplicates, drop messages, or stall their queues. Treat that the way you would treat a removed field.

Inside a version, three facts stay stable and separate. Transport status is the HTTP or messaging result. A published code is your decision, and that code is never reused for a different decision. The message is for a person. Callers may branch on the status and the code. They must not branch on the sentence, so do not give the sentence a shape that looks parseable.

Mark every code retryable or terminal. Moving a code between those classes is a break. Validation failure is terminal: the same body will fail until the caller changes it. An unavailable dependency is retryable. One status used for both "fix the payload" and "try again" forces every caller to guess. Publish the map. An idempotency conflict is terminal for that key. An upstream timeout is retryable. Bad credentials are terminal until they are replaced. A retired version is terminal.

A new code is additive only if unknown codes are handled by class, not by a closed list. Otherwise it belongs in a new version. Use one error object for every operation. A special body on one route is the body a generated client will skip.

## Idempotency keys

Networks, gateways, and schedulers retry when they cannot tell whether the first write finished. Any operation that changes state needs a defined result for the second arrival. Changing that result later, from a second record to the original or the reverse, breaks recovery code already in production.

Take a client-supplied key on operations you declare idempotent. Say which operations require it and which error you return if it is missing. Scope the stored key by operation and caller so two tenants cannot collide on the same string.

State three outcomes in the contract. The same key and the same body return the original result, including a recorded terminal error, so a lost response can be recovered. The same key and a different body is a stable conflict, and the second body is not applied. A retry that overlaps the first attempt must not start another execution: the caller waits, or it receives a documented retryable "in progress" error. Test the one you choose.

Publish a retention period at least as long as the caller's retry horizon. Ending it early creates the duplicate a correct client was trying to avoid. Lengthening retention is usually safe; shortening it is a break. Keep only enough of the body to detect a mismatch, then delete the key. The period is a compatibility promise and a privacy decision. A server-generated identifier does not help the caller who never received the response. Deduplicating events a provider pushes at you is covered separately in the [webhook reliability guide](/guides/webhook-reliability-patterns/).

## A changelog a buyer can read

The changelog is how a person who will never clone the repository decides whether to act. Write it for a contract manager and an integration lead. Keep a stable URL, date every entry, and leave old entries in place so due diligence is not an exercise in ticket search.

Each entry needs six facts. The date of the notice and the version it covers. The class: additive, a compatible behavior change, breaking, or security. What changed, in sentences, including error codes and idempotency rules when those changed. Who must act, named by situation — anyone still on the previous version, anyone branching on a given code — or an explicit line that no existing caller must change. The date the change takes effect, and the sunset date if something is being removed. A link to the contract diff and to a migration note that shows the old call beside the new one.

Describe a security fix without a recipe for the old flaw. Rejecting input you used to accept is still a break: mark it that way, use the shortest window you can defend, and leave it out of a list called improvements. The changelog and the notice period have to match. An exception inside the window says why it was made and what help callers who cannot move will get. The page works when an outsider can tell whether an integration still works and what to attach to a contract amendment. A git log cannot do that. It omits sunset dates and mixes in commits that never touched the interface.

## What to write down first

If callers already exist, record current behavior before minting versions: the contract, error classes, idempotency rules, live versions, and the notice period you will honor. Keep that record as an architecture decision record, and publish the changelog at a URL you would cite in a solicitation.

After that, additive changes stay in the current version and are still announced. Breaks open a version and start the window. Tests fail when the diff and the announcement disagree. That is what lets the interface outlive the team that shipped it.

To have the policy and the tests designed for an interface other organizations already call, review our [engagement models](/engagements/) and [capabilities](/capabilities/), or [contact us](/contact/).
