# API Versioning When Gen 2 Changes the Contract | gen2.dev

> When Gen 2's API is not the same as Gen 1's, every client is affected. How Stripe and Google version APIs, what counts as breaking, and how to sunset Gen 1.

Source: https://gen2.dev/guide/api-versioning/

---

Field Guide

# Versioning an API when Gen 2 changes the contract

Gen 2 can change everything behind the API. The API itself is a promise to people you do not control, and it changes on their schedule, not yours.

![Slide: phone, laptop and partner clients call /v1, Gen 1's contract with a sunset date, and /v2, Gen 2's contract. Clients change on their schedule, not yours.](https://gen2.dev/img/api-versioning.png)

Inside your own system, a rewrite can change anything. At the API boundary it cannot. Every mobile app in the field, every partner integration and every customer script was written against Gen 1's contract, and none of them will change because you shipped Gen 2.

## What counts as breaking

Stripe's Brandur Leach gives the clearest test. If a client checks a field and that field disappears, "the code will break because it depends on a field that no longer exists. This type of change is backwards-incompatible, and we avoid making them. Fields that were present before should stay present, and fields should always preserve their same type and name."

The other side of the line: "it's safe to add a new API endpoint, or a new field to an existing API endpoint that was never present before."

For Gen 2, that turns into one question asked of every endpoint: does Gen 2 return the same fields, with the same names and types, for the same requests? Where the answer is yes, clients need never know Gen 2 exists. Where it is no, you need a version.

## Option 1: keep Gen 1's contract

The cheapest client migration is none. Gen 2 implements Gen 1's API exactly, and a translation layer maps it onto Gen 2's new model. That layer is an [anti-corruption layer](https://gen2.dev/guide/anti-corruption-layer/) pointed outward: it keeps the old contract out of Gen 2's design, and it keeps Gen 2's design out of the clients' code.

[Characterization tests](https://gen2.dev/guide/characterization-tests/) recorded against Gen 1's API, run against Gen 2, prove the contract held.

## Option 2: a new major version

When the contract has to change, Google's rule for its own APIs is a major version in the path: interfaces "must provide a major version number, which is encoded at the end of the protobuf package, and included as the first part of the URI path for REST APIs." Google exposes major versions only: "Google APIs use v1, not v1.0, v1.1, or v1.4.2."

One rule from that page matters for a rewrite: "A new major version of an API must not depend on a previous major version of the same API." In Gen 2 terms, v2 is Gen 2's contract and must not be built on top of Gen 1's v1. When Gen 1 goes, v1 can go with it, and v2 keeps working.

## Option 3: many small versions

Stripe chose a different shape. "At Stripe, we implement versioning with rolling versions that are named with the date they're released (for example, 2017-05-24). Although backwards-incompatible, each one contains a small set of changes that make incremental upgrades relatively easy so that integrations can stay current."

Each client is fixed in place until it chooses to move: "The first time a user makes an API request, their account is automatically pinned to the most recent version available, and from then on, every API call they make is assigned that version implicitly." Inside, older versions are handled by code that converts responses step by step, so "version change modules keep older API versions abstracted out of core code paths."

This works when the changes come one at a time. A full Gen 2 that changes the whole contract at once is usually a major version.

## Retiring Gen 1's version

The old version is part of Gen 1, and it is the part with the most outside users. Tell clients in the protocol, not only in an email. RFC 8594 defines the Sunset response header, "which indicates that a URI is likely to become unresponsive at a specified point in the future," and a sunset link relation that points to the details.

A retirement that works:

1.  **Measure who still calls the old version,** by client, before announcing anything.
2.  **Announce a date,** and send the Sunset header on every response from the old version.
3.  **Contact the largest remaining callers directly.** The long tail is usually a handful of clients.
4.  **Brown out before the date.** Short, scheduled periods of errors find the callers nobody knew about.
5.  **Turn it off on the date,** and keep the translation code until the logs stay quiet.

The [killing Gen 1](https://gen2.dev/guide/killing-gen-1/) page covers the rest of the switch-off.

## When not to use it

A version has a cost for as long as it lives. Skip it when nothing is at stake.

-   **Every client is yours and ships with the server.** Change both together and delete the old shape.
-   **The change is additive.** A new optional field or endpoint does not need a new version.
-   **Nobody calls the endpoint.** Measure first; an unused route can be removed instead of versioned.

## Where it goes wrong

-   **Accidental breaking changes.** A field changes from a number to a string because Gen 2's language prefers it. Nobody versioned it because nobody noticed. Compare Gen 1 and Gen 2 responses field by field.
-   **Behavior changes behind the same contract.** Same fields, different meaning: an amount in dollars becomes cents. That is a breaking change even though no schema test fails.
-   **A v2 built on v1.** Gen 1 cannot be retired because v2 still calls it.
-   **No date for the old version.** Clients have no reason to move, so they never do, and Gen 1 runs forever to serve them.

## Checklist

-   Every endpoint is marked: same contract in Gen 2, or changed.
-   Gen 1's responses are recorded and compared with Gen 2's, field by field and type by type.
-   Changed contracts go in a new version that does not depend on the old one.
-   Each client's version is known, and old-version traffic is measured.
-   The old version has a sunset date, sent in the Sunset header.
-   Removing the old version is on the plan for retiring Gen 1.

## Sources

1.  [Brandur Leach - APIs as infrastructure: future-proofing Stripe with versioning (Stripe, August 5, 2017)](https://stripe.com/blog/api-versioning) - what counts as backwards-incompatible, date-named rolling versions, pinning each account, and version change modules
2.  [AIP-185: API Versioning - Google API Improvement Proposals](https://google.aip.dev/185) - a major version in the path, no minor or patch numbers exposed, and a new major version that must not depend on the previous one
3.  [RFC 8594: The Sunset HTTP Header Field (IETF, May 2019)](https://www.rfc-editor.org/rfc/rfc8594.html) - the Sunset response header and the sunset link relation

Last updated November 29, 2026.

## Field Guide

-   [Rewrite vs refactor](https://gen2.dev/guide/rewrite-vs-refactor/)
-   [The 7 Rs](https://gen2.dev/guide/seven-rs/)
-   [Characterization tests](https://gen2.dev/guide/characterization-tests/)
-   [Estimating a rewrite](https://gen2.dev/guide/estimating-a-rewrite/)
-   [Strangler fig pattern](https://gen2.dev/guide/strangler-fig/)
-   [Monolith to microservices](https://gen2.dev/guide/monolith-to-microservices/)
-   [Lift and shift](https://gen2.dev/guide/lift-and-shift/)
-   [Second-system effect](https://gen2.dev/guide/second-system-effect/)
-   [Branch by abstraction](https://gen2.dev/guide/branch-by-abstraction/)
-   [Anti-corruption layer](https://gen2.dev/guide/anti-corruption-layer/)
-   [Parallel run](https://gen2.dev/guide/parallel-run/)
-   [Shadow traffic](https://gen2.dev/guide/shadow-traffic/)
-   [Dual write and data migration](https://gen2.dev/guide/dual-write/)
-   [Expand and contract](https://gen2.dev/guide/expand-and-contract/)
-   [Data migration tools](https://gen2.dev/guide/data-migration-tools/)
-   [The cutover](https://gen2.dev/guide/cutover/)
-   [Feature flags and dark launches](https://gen2.dev/guide/feature-flags-and-dark-launches/)
-   [Big-bang cutover](https://gen2.dev/guide/big-bang-cutover/)
-   [API versioning](https://gen2.dev/guide/api-versioning/)
-   [Running two systems](https://gen2.dev/guide/running-two-systems/)
-   [Killing Gen 1](https://gen2.dev/guide/killing-gen-1/)
-   [Rewriting a mobile app](https://gen2.dev/guide/rewriting-a-mobile-app/)
-   [Selling a rewrite](https://gen2.dev/guide/selling-a-rewrite/)
-   [AI-written code](https://gen2.dev/guide/ai-written-code/)

## Should we rewrite it?

Sixteen questions about your system. A recommendation, and the reasoning behind it.

[Start the questions](https://gen2.dev/should-we-rewrite/)
