Accent colour
 
Shortcuts: press ?
 

How API Versioning Works — Without Breaking Your Clients

Muhammad Tahir December 01, 2026

The Monday morning your API broke someone else's app

It is 9:04 on a Monday. Your team shipped a small change on Friday afternoon: the status field on an order, which used to be a string like "paid", is now an object with a code and a label. It was a tidy improvement. The new shape carries more information, the tests passed, and the deploy went out cleanly.

Then the support tickets start. A customer's mobile app is crashing on checkout. An integration partner's dashboard shows every order as failed. A warehouse system has stopped printing labels. None of them changed anything over the weekend. You did — and your change, which looked harmless from inside your codebase, broke the assumptions their code was built on.

This is the problem API versioning exists to solve. An API is a promise between you and every developer who builds on it, and that promise outlives any single deploy. Clients in production are running every historical version of your assumptions at the same time. Some of them will not update for months. Some of them cannot update at all, because they are embedded in a device, or in a customer's system you do not control, or in an app store review queue. Versioning is how you keep changing your API without breaking those clients. Done well, it is boring. Done badly, it is the reason your biggest customer is on the phone.

What a version is actually promising

Before choosing a scheme, it helps to say plainly what a version number means. It is not a marketing label, and it is not a record of how many times you deployed. It is a contract: code written against version N will keep behaving the way it behaved when version N was current, for as long as version N is supported.

That promise has two parts. The first is that you will not change the meaning of existing fields, endpoints, or behaviours inside a version. The second is that when you do need to change something in a way that breaks that promise, you will do it in a new version, run both versions side by side, and give clients a clear path and a clear deadline for moving.

The second part is where most teams fail. It is easy to add a new version. It is hard to keep the old one running, to answer questions about it, to backport a security fix to it, and to eventually turn it off without stranding anyone. Every versioning scheme is, at bottom, a way of managing that cost. The schemes differ in how visible the version is, how much machinery they need, and how gracefully they age. None of them removes the work. They just decide where it lands.

One more distinction matters before the details. Libraries and APIs do not version the same way, even though both use numbers that look alike. Semantic versioning — major, minor, patch — fits libraries well, because a library is compiled into the consumer's code at a specific moment. A network API has no such moment. Clients are calling every historical version simultaneously, in production, right now. That is why most public APIs expose only the major number in the URL, like /v1/ or /v2/, and treat everything inside it as additive.

Where the version lives

There are four places a version can live. Each is used by a major API, each has real trade-offs, and the choice is worth making deliberately rather than copying whatever the last API you used did.

The most common is the URI, or URL path: /v1/charges, /v2/charges. GitHub, Twilio, and most public APIs use it, and Stripe's public REST surface does too. Its strength is visibility. The version is impossible to miss: it shows up in the URL, in the logs, in a curl command, in a support ticket. Routing is simple — your framework mounts a new sub-application per version. Debugging is simple too, because anyone reading a request can see which version it hit. The cost is URL proliferation. Every resource exists at two addresses once you have two versions, and your documentation has to cover both.

The second is a header. The version travels in the request headers, either as a custom media type in the Accept header — Accept: application/vnd.example.v2+json — or as a dedicated header like X-API-Version: 2. The URL stays clean, and the response shape can change without the URL changing. This is what REST purists wanted. In practice, almost nobody ships it for public APIs, because it is hard to debug. A support engineer looking at a customer's curl command cannot tell which version was hit without inspecting the headers. Caches need a Vary header that everyone forgets to set, and when it is missing, a CDN can serve a v1 body to a v2 caller. GitHub used media-type versioning for its v3 API, and even GitHub has moved toward date-based headers since.

The third is the query string: /customers?api-version=2. It is easy to implement and easy to test in a browser, which is why it shows up in prototypes and internal APIs. It is also the weakest option for anything public. The version pollutes the query namespace, it is easy for a client to forget, and caches treat different query strings as different resources, which is sometimes what you want and sometimes a surprise.

The fourth is date-based versioning, and it is the most interesting, because it solves a problem the other three do not. Instead of a number, the client sends a date, usually in a header: Stripe-Version: 2024-09-30.acacia. Stripe is the canonical example. Its API has accumulated hundreds of date-based versions since 2011, and every account has a pinned default version it can override per request. GitHub uses the same idea with X-GitHub-Api-Version: 2022-11-28. The date conveys recency, there is no debate about what counts as a major change, and new customers are automatically pinned to the latest version while existing customers keep working exactly as they were. The price is machinery: behind the scenes, Stripe runs a chain of transformers that convert responses between versions, and building that machinery is real engineering work.

For a new public API, the pragmatic default is URI versioning with a single major version, and additive-only changes inside it. Pick that unless you have a concrete reason not to. Date-based versioning is the right answer when you are Stripe-sized, with thousands of integrations and a promise never to break any of them. Header versioning is the right answer mostly for internal services where the clients are your own teams and the debugging cost stays inside the building.

What counts as breaking

The word "breaking change" gets thrown around loosely, and that looseness causes real damage. A change is breaking if it can make working client code stop working, or start behaving differently, without the client changing anything. That definition is wider than most teams expect.

Removing a field is breaking. Renaming a field is breaking. Changing a field's type — a string to a number, a number to an object, a single value to an array — is breaking, and it is the most common way a well-meaning improvement breaks clients, as the status field story at the top shows. Adding a new required parameter is breaking, because existing callers do not send it. Changing the meaning of an existing value is breaking, even if the type stays the same: if "pending" used to mean "awaiting payment" and now means "awaiting review", every client that branched on that value is now wrong. Tightening validation is breaking: a request that succeeded yesterday and fails today, for the same payload, is a break. So is changing an error response — the status code, the error code, the shape of the error body — because clients parse those.

What is not breaking? Adding a new field to a response is safe, as long as clients ignore fields they do not recognise — and they should, because that is the deal. Adding a new endpoint is safe. Adding a new optional parameter is safe. Adding a new value to an enumeration is safe only if clients handle unknown values gracefully, which is a big "if" and worth stating in your documentation. Loosening validation is safe. Fixing a bug is safe, unless clients have come to depend on the buggy behaviour, which happens more often than anyone admits.

The practical rule is simple to state and hard to follow: inside a version, only additive changes. Anything else waits for a new version. Write that rule down, put it in your API guidelines, and make it the default answer in code review when someone proposes changing a field "because it's a small change". Small changes to a contract are still changes to a contract.

The additive rule, and how to make it work

Additive-only evolution sounds restrictive until you see the techniques that make it practical. There are four that cover most situations, and they are worth knowing by name.

The first is the expand-and-contract pattern, also called parallel change. You never change a field in place. You add the new field, keep the old one working, tell clients to move, wait, and only then remove the old one — in a new version. A field rename becomes two steps: add customer_name, deprecate name, remove name in v2. The pattern costs a little duplication and buys you the ability to change anything without a flag day.

The second is optional everything. New parameters are optional, with sensible defaults. New fields appear in responses without breaking old clients. This is the discipline behind the rule that a v1 can live for years while the product changes underneath it: the surface grows, but nothing already there moves.

The third is the envelope. Wrap your responses in a stable structure — a data object, a meta object, pagination fields — from day one. Later, when you need to add pagination, rate-limit information, or warnings, you have somewhere to put them that does not disturb the payload. Teams that skip the envelope always regret it the first time they need to add something to every response.

The fourth is never returning bare values. An endpoint that returns a raw string or a raw array cannot grow without breaking. An endpoint that returns an object can always gain a field. This is a small design choice with a long tail: it is the difference between an API that can evolve and one that has to be versioned the first time anyone wants to add anything.

There is one more habit that makes additive evolution work, and it is a social one rather than a technical one. Treat unknown fields as data to ignore, not errors to reject. A client that fails when it sees a field it does not recognise is a client that will break the first time you add anything. Document the rule — "we may add fields at any time; ignore what you don't understand" — and make sure your own SDKs follow it. The same applies in reverse: your server should ignore unknown fields in requests, or at least not reject them outright, because a client built against a newer version of your docs will send fields your older server does not know.

Stripe, GitHub, and Twilio in practice

Abstract rules are easier to trust when you can see them running at scale, so it is worth looking at how three of the most-used APIs actually do this.

Stripe is the most instructive, because it versioned its way out of the hardest version of the problem: payments, where a breaking change can move real money. Stripe's URLs carry a stable /v1/ prefix that has not changed in years. The versioning happens in a header, Stripe-Version, with date-based values like 2024-09-30.acacia. The first time an account makes an API request, it is pinned to the current version, and from then on every call uses that version unless the client overrides it per request. Starting with the 2024-09-30.acacia release, Stripe ships new API versions monthly with no breaking changes, and twice a year it issues a major release — Acacia, Basil, Clover, Dahlia, Endive — that starts with an API version containing breaking changes. The current version, as of Stripe's own documentation, is 2026-11-18.endive. The model works because the pinning means existing integrations never change behaviour unless their owner chooses to upgrade, and the monthly cadence means upgrades are small and frequent rather than rare and terrifying.

GitHub took a different path to a similar place. Its REST API uses /v3/ in the URL historically, and since 2022 it has used a date-based header, X-GitHub-Api-Version: 2022-11-28, to control behaviour. GitHub also versions its media types, so a client can request a preview of a feature with a specific Accept header. The lesson from GitHub is about communication: its changelog and migration guides are the model most teams copy, because a versioning scheme is only as good as the documentation that explains how to move between versions.

Twilio is the straightforward case, and the one most teams should copy: it versions in the URL — /2010-04-01/ is the famous one, a date in the path — and keeps old versions running for years. Simple, visible, and boring, which is exactly what you want from infrastructure customers build businesses on.

What the three have in common is more important than how they differ. All three treat backward compatibility as a promise, not a preference. All three run old versions alongside new ones for a long time. And all three communicate changes early, in writing, with migration guides. The scheme is the easy part. The promise, and the communication, is the work.

Deprecation done properly

Eventually, an old version has to die. Keeping every version alive forever is not a strategy; it is a slow accumulation of code nobody understands, tests nobody runs, and security patches nobody backports. The question is how to end a version without stranding the clients still on it.

There is a standard, and it is worth using instead of inventing your own. Two HTTP headers do most of the work. The Deprecation header, standardised in RFC 9745, marks a resource or version as deprecated, with a Unix timestamp: Deprecation: @1735689599. The Sunset header, from RFC 8594, gives the date after which the resource will be gone: Sunset: Sat, 31 Dec 2026 23:59:59 GMT. Used together, they let any client — or any piece of monitoring — see both the fact and the deadline, in a machine-readable form. Add a Link header pointing at the migration guide, and a client can find the way forward without opening a support ticket.

Headers alone are not enough. A good deprecation has a timeline clients can plan around, and the shape of that timeline is nearly always the same: announce, grace period, sunset, delete. Announce the deprecation in the changelog, in the docs, and by email to the affected accounts — not just in a header, because most clients never read headers. Give a grace period of six to twelve months for a public API, longer if you know slow-moving enterprise clients are on the old version. During the grace period, keep the old version fully working, including security fixes. At the sunset date, return a clear error — a 410 Gone, or a 404 with a message pointing at the new version — not a silent failure. Then delete the code, and say so in the changelog.

The part teams skip most often is knowing who is still on the old version. Before you announce a sunset, measure. Log the version on every request and identify the stragglers by name, then contact them directly — a generic email reaches the developers who already upgraded, and the ones still on v1 are, by definition, the ones not reading your emails. For them, a direct message or a support ticket is the difference between a planned migration and a Monday morning outage.

Questions developers ask about versioning

Do we need to version from day one?

Yes, and it costs almost nothing. Put /v1/ in the URL before your first public caller arrives. Adding it later means either breaking every existing client or supporting an unversioned legacy surface forever. Internal APIs are the exception: if the only clients are services your own team deploys together, you can move in lockstep and skip versioning until the API escapes the building. The moment an external client appears, version it.

Should we use semantic versioning for our API?

Use it for your SDKs and libraries, not for the API itself. Semantic versioning assumes a compile-time binding between consumer and version, which does not exist over HTTP. Expose only the major version in the URL, keep minor and patch changes additive inside it, and reserve a new major version for the rare breaking change. If you publish an OpenAPI document, version that document alongside the API it describes.

How many versions should we support at once?

Two, or three at most. One current version, one previous version in its deprecation window, and occasionally a third that is about to be switched off. More than that and the maintenance cost explodes: every bug fix, every security patch, and every new feature has to be considered against each live version. If you find yourself supporting four versions, the problem is not your versioning scheme. It is that your deprecation process is not finishing.

What about GraphQL and event-driven APIs?

GraphQL changes the mechanics but not the principle. Fields are deprecated with the @deprecated directive rather than removed, and the schema evolves additively, which is the same rule in different clothes. Event-driven systems version their events too: a message schema changes, consumers running the old schema still need to work, and the same expand-and-contract pattern applies. If your events travel through a broker, the versioning conversation connects to how you design message queues, because the queue is where old and new event shapes meet.

Our API is internal only. Do we still need this?

Less of it, but not none of it. Internal APIs have a real advantage: you can find every caller and change them all at once. That works until the day it doesn't — the day a mobile app ships with a hardcoded endpoint, or another team builds a dashboard against your API without telling you, or the company acquires a product whose integration you did not know existed. A version in the URL from the start costs nothing and saves you from discovering your API was public the hard way.

What to do next

Versioning is not a feature you ship once. It is a promise you keep, release after release, and the teams that keep it well share a small set of habits. Put them in place before your API has its first real customer, and most of the hard decisions never become emergencies.

Start with the URL. Ship /v1/ from day one, even if you are the only caller. Write the compatibility rule down and put it where code review can see it: additive changes only inside a version, breaking changes only in a new version. Wrap responses in an envelope, never return bare values, and ma

Was this article helpful?

Muhammad Tahir

Author

 

Get new articles by email

 

Comments