Skip to content
Last updated

API versioning: strategies, best practices, and tools

API versioning is how you change an API without breaking the clients that already use it. You can either keep every change backward compatible, or publish the incompatible change as a new version and give clients time to move. Redocly recommends: put the major version in the URI path (/v1/), make only additive changes inside it, and diff your OpenAPI description in CI so breaking changes can't ship by accident. Avoid query parameter and media type versioning, and use a version header only if you adopt Stripe-style date-based versions.

What is API versioning?

An API version is a promise about the shape and behavior of an API. A client built against version 1 keeps working as long as version 1 keeps that promise.

Some changes are backward compatible, and others break existing clients. API versioning settles four decisions:

  • how a client asks for a version (the versioning scheme)
  • which changes need a new version
  • how long you support an old version, and how you tell clients that it is going away
  • how you document each version and the changes between versions

What counts as a breaking change in an API?

A breaking change is any change that can make a working client fail. The client does not need to be wrong for the change to break it. The client only needs to rely on behavior that the API used to guarantee.

Common breaking changes:

  • removing or renaming an endpoint, operation, or operationId
  • removing or renaming a request parameter, a request body, or a response field
  • making an optional parameter or request field required
  • changing the type of a field, for example from integer to string
  • narrowing what a request accepts, for example a lower maxLength or a removed enum value
  • widening what a response returns, for example a new enum value that a client's switch statement does not handle
  • changing authentication, scopes, or the server URL
  • changing a status code or a response media type

Changes that are usually safe:

  • adding an endpoint or an operation
  • adding an optional request parameter or field
  • adding a field to a response
  • accepting more values in a request, for example a higher maxLength
  • improving descriptions and examples

The direction of the data matters. A new enum value is safe in a request, because old clients never send it. The same new value in a response can break a client that does not expect it. If a request and a response share a schema, a change to that schema must be safe for both.

"Safe" also depends on your clients. A new response field is non-breaking only if clients ignore unknown fields. Document that expectation, sometimes called the tolerant reader principle, in your API guidelines.

API versioning strategies compared

HTTP APIs use six common versioning approaches, and the approaches are not equally good. The following sections rank them, best first. Each example requests the same resource in version 2.

URI path versioning

The version is part of the path.

GET /v2/orders/123 HTTP/1.1
Host: api.example.com

URI path versioning is the most common approach in public APIs. Google's API design guidance, for example, puts the major version in the path.

  • Pros: The version is visible in every URL, log line, and code sample. Routing is simple, caches work without extra configuration, and clients can try a version in a browser.
  • Cons: A version applies to the whole API. One breaking change in one endpoint creates a new version of every endpoint. The URL of a resource changes between versions, which does not fit strict REST, where a URL identifies a resource and not a representation.

Verdict: use this by default. The cons are smaller than they look. A whole-API version is a feature if major versions are rare, because clients migrate once instead of endpoint by endpoint. REST purity doesn't help anyone integrate faster. Put only the major version in the path: /v2/, never /v2.1/.

Evolving without versions

Some APIs never publish a new version. They make only additive changes, and they deprecate and eventually remove old fields and endpoints after a notice period. GraphQL APIs often work this way, and many internal REST APIs do too.

  • Pros: You build, test, and document one API. Clients get new features without an upgrade.
  • Cons: It works only if you can avoid most breaking changes, or if you control the clients. Deprecated fields accumulate, and a removal after the notice period is still a breaking change for clients that did not move.

Verdict: this is how every API should change inside a major version. For internal APIs where you control the clients, it is all you need. For public APIs, pair it with path versioning, and treat a new major version as a last resort, not a release milestone.

Date-based versioning

The version is a release date, usually sent in a header.

GET /orders/123 HTTP/1.1
Host: api.example.com
Api-Version: 2026-11-01

Stripe popularized this approach. Stripe pins each account to the API version that was current when the account made its first request, and a request can override the pinned version with the Stripe-Version header. The server keeps one current implementation and transforms requests and responses for older versions.

  • Pros: You can ship small breaking changes often, each in its own dated version, without a big-bang v3. Clients upgrade on their own schedule, and the date tells them how old their integration is.
  • Cons: The server must maintain a chain of compatibility transforms for every old version. A date says when a version was released, not how much changed, so clients need a good changelog to understand an upgrade.

Verdict: excellent at Stripe's scale, too expensive for most teams. It works only if you build and test the compatibility layer from day one and keep every old version working for years. With a small team and a few hundred clients, path versioning plus additive changes gets you most of the benefit for a fraction of the cost.

Custom header versioning

The version is a request header.

GET /orders/123 HTTP/1.1
Host: api.example.com
Api-Version: 2

The GitHub REST API uses the X-GitHub-Api-Version header, with a date as the value.

  • Pros: URLs stay clean and stable. The version is separate from the resource, and a gateway can route on the header.
  • Cons: The version is invisible in a URL. A hidden version is harder to test in a browser and to find in logs. Responses must include Vary: Api-Version, or shared caches can return the wrong version.

Verdict: avoid it for public APIs. A hidden version makes every support ticket, log search, and curl example harder, and a missing Vary header causes cache bugs that are slow to trace. A header makes sense only as the carrier for date-based versions, where an SDK sends it for the client.

Query parameter versioning

The version is a query parameter.

GET /orders/123?api-version=2 HTTP/1.1
Host: api.example.com

Microsoft Azure REST APIs use a required api-version query parameter with a date value.

  • Pros: The path of a resource stays the same. The version is still visible in the URL, and clients can add it to existing requests without other changes.
  • Cons: Callers can omit the parameter. You must decide how to handle requests without it. Some caches and proxies ignore or reorder query parameters, and the parameter mixes API metadata with resource filters.

Verdict: avoid it. It is as visible as path versioning but less simple, and it adds a default-version question with no good answer. If a request without the parameter gets the oldest version, new clients get stale behavior. If it gets the newest version, old clients break on your next release. Azure makes the approach work by requiring the parameter on every request. If you must use query parameter versioning, require the parameter too.

Media type versioning (content negotiation)

The client asks for a versioned media type in the Accept header.

GET /orders/123 HTTP/1.1
Host: api.example.com
Accept: application/vnd.example.v2+json
  • Pros: It is the most REST-aligned approach. The URL names the resource, and the media type names the representation. You can version each resource on its own, instead of the whole API.
  • Cons: It is the hardest approach for clients to discover and use. SDK generators and documentation tools handle custom media types inconsistently, and caches need Vary: Accept.

Verdict: avoid it unless you are building a hypermedia API. It is the most correct approach on paper and the most painful in practice. Per-resource versions sound flexible, but they leave each client tracking a different version for every resource it uses.

Comparison table

The following table compares the six approaches:

ApproachVerdictVisibilityCachingUse it for
URI pathRecommended defaultHighWorks by defaultPublic APIs (almost always)
Evolving, no versionsRecommended inside a versionNot neededWorks by defaultAny change inside a major version, and internal APIs
Date-basedOnly at scaleLow (header)Needs VaryAPIs with many clients and frequent breaking changes
Custom headerAvoid for public APIsLowNeeds VaryCarrying date-based versions from an SDK
Query parameterAvoidHighDepends on cache setupMatching an existing platform convention
Media typeAvoidLowNeeds Vary: AcceptHypermedia APIs

How to choose an API versioning strategy

Start with URI path versioning for the major version and additive changes inside it. Move away from that default only for one of these reasons:

  • You have many clients, ship breaking changes often, and can staff a compatibility layer: use date-based versions in a header.
  • Your platform already has a convention: follow it, even if it uses query parameters. Consistency across your APIs beats the better scheme.
  • You build a hypermedia API: use media types.

If none of these apply, you don't need anything more elaborate. In Redocly's experience, versioning problems come from breaking changes that ship by accident far more often than from the wrong scheme, which is why the rest of this article focuses on catching them.

API versioning best practices

  • Design for change from the start. Use objects instead of bare arrays or strings in responses, to leave room for new fields. Prefer optional fields with defaults over required ones.
  • Save major versions for batched breaking changes. Ship additive changes inside the current version, and group breaking changes into one major release instead of publishing a new major version for each. Never put a minor version in the URL. A path such as /v2.1/ turns every additive change into a migration.
  • Version the contract, not the code. Keep an OpenAPI description for each supported version, and treat it as the source of truth for the version.
  • Detect breaking changes in CI, not in code review. Reviewers miss breaking changes, especially in shared schemas. Compare each pull request's API description with the description on the main branch, and fail the build on an unplanned breaking change.
  • Tie info.version to the changes. Use semantic versioning in info.version, and check that each release bumps the right part of the version for its changes.
  • Deprecate before you remove. Mark deprecated items in the OpenAPI description, send Deprecation and Sunset headers, and give clients a notice period.
  • Support at most two major versions at once. Keep the current version and the previous one, and support the previous one for at least 12 months after the new release. Each extra version multiplies your testing, docs, and support work.
  • Keep a changelog for every version. List each change, its impact, and what clients must do.
  • Publish docs for every supported version. Clients on an old version need the docs for that version, not only for the latest.

Semantic versioning for APIs

Semantic versioning (semver) uses a MAJOR.MINOR.PATCH version number. For an API, the parts mean:

PartBump whenExample change
MAJORA change can break an existing clientA removed operation, or a new required parameter
MINORA change adds to the API and breaks nothingA new endpoint, or a new optional response field
PATCHA change neither breaks nor adds anythingA fixed typo in a description, or a new example

Most public APIs expose only the major version to clients, for example /v2/. The full semver number belongs in the info.version field of the OpenAPI description, where it tells readers and tools exactly which revision of the contract they have.

Below version 1.0.0, semver allows a minor release to break the API. Use 0.x versions for APIs in preview, and release 1.0.0 when you commit to stability.

How to deprecate an API version

Deprecation is a notice that an item still works but is scheduled for removal. Sunset is the date when the deprecated item stops working.

Mark deprecated items in OpenAPI

OpenAPI has a deprecated field for operations, parameters, and schemas. Documentation tools mark deprecated items, and code generators can mark the generated methods as deprecated. The following example deprecates an operation and names its replacement:

paths:
  /orders/{orderId}/cancel:
    post:
      operationId: cancelOrder
      deprecated: true
      description: |
        Deprecated. Use `PATCH /orders/{orderId}` with `status: cancelled`.
        This operation stops working on 2027-06-30.

Always say what replaces the deprecated item and when it goes away.

Send Deprecation and Sunset headers

Two standard HTTP response headers tell clients about deprecation at runtime:

  • Deprecation (RFC 9745) says that a resource is deprecated and gives the deprecation time as a Unix timestamp.
  • Sunset (RFC 8594) gives the date after which the resource can stop responding.

The following response marks a resource as deprecated and links to the migration guide:

HTTP/1.1 200 OK
Deprecation: @1782864000
Sunset: Wed, 30 Jun 2027 23:59:59 GMT
Link: <https://api.example.com/docs/migrate-to-v3>; rel="deprecation"; type="text/html"

Client libraries and API gateways can log a warning when they see these headers, so developers learn about the deprecation before the sunset date.

Plan the notice period

  • Announce the deprecation in the changelog, in the docs, and by email to the clients that use the deprecated item.
  • Give a notice period that fits your clients. Public APIs often give 6 to 12 months, and internal APIs can use a shorter window.
  • Watch the traffic to deprecated endpoints, and contact the clients that still use them before the sunset date.
  • After the sunset date, return 410 Gone with a link to the migration guide, instead of a generic error.

API changelogs

A changelog is the record of what changed between versions of an API. Clients read it to decide whether to upgrade and what to change.

A useful API changelog entry has:

  • the version and the release date
  • each change, grouped by impact: breaking, new, and fixed or deprecated
  • for each breaking change, what clients must do
  • links to the reference docs of the changed operations

Write the changelog from the difference between two API descriptions, not from memory. An automated diff lists every change, including the ones that nobody mentioned in the pull request. Then add the context that a diff cannot give: why the change happened and how to migrate.

How to detect breaking changes in an OpenAPI description

To detect breaking changes, compare the OpenAPI description of the new version with the description of the released version. Do it in CI on every pull request, so a breaking change fails the build before it merges.

A good breaking-change detector:

  • follows $refs, including references to other files
  • knows whether a schema is used in a request or a response
  • detects renames instead of reporting a removal and an addition
  • gives each change an impact that maps to semver
  • produces output for people (a pull request comment) and for machines (an exit code or JSON)

The comparison checks the contract, not the implementation. To check that the running API still matches its OpenAPI description, also run contract tests against the API. See API contract testing 101 and detecting drift between docs and a live API.

Which platforms handle API versioning best?

No single platform handles every part of API versioning. Versioning needs four capabilities, and teams usually combine tools to get them:

  • Breaking-change detection that compares two API descriptions and gives each change an impact. Open-source options include Redocly CLI's diff command, oasdiff, and OpenAPITools openapi-diff.
  • API design governance that lints every version against the same style guide, so versions stay consistent.
  • Versioned documentation that publishes the docs of every supported version, with a version picker and changelogs.
  • Routing and runtime control, usually in an API gateway, that sends each request to the right version and adds deprecation headers.

When you compare tools, also look for inline pull request annotations, a check that info.version matches the changes, and an API reference that displays deprecated operations, parameters, and schemas.

Redocly covers the first three capabilities: Redocly CLI detects breaking changes and lints API descriptions, and Redocly's docs platform publishes versioned API documentation.

How Redocly helps with API versioning

Redocly covers three parts of API versioning: breaking-change detection, API design governance, and versioned docs.

Detect breaking changes with redocly diff

The diff command in Redocly CLI compares two API descriptions and lists the changes between them. It gives each change a major, minor, or patch impact: the part of the semver version that a release with the change must bump.

Experimental

The diff command is an experimental feature of Redocly CLI. Its behavior, options, rule names, and output formats can change in future releases.

Compare two files:

npx @redocly/cli diff v1/openapi.yaml openapi.yaml

The command follows $refs into other files, detects renamed paths, properties, and parameters, and ignores reordered list items. It supports OpenAPI 3.x and AsyncAPI 3. It also applies the decorators from your configuration, so with remove-x-internal turned on, changes to internal operations do not count.

Stop breaking changes in CI with --fail-on

By default, redocly diff exits with code 1 if it finds a major change, so a CI job fails on a breaking change. Use --fail-on to change the threshold:

# Fail on breaking changes (the default)
npx @redocly/cli diff origin/main:openapi.yaml openapi.yaml

# Also fail on new features, for example during a feature freeze
npx @redocly/cli diff origin/main:openapi.yaml openapi.yaml --fail-on=minor

# Report changes without failing
npx @redocly/cli diff origin/main:openapi.yaml openapi.yaml --fail-on=none

Compare with a Git revision

You don't need a second copy of the file. Read the base description from any branch, tag, or commit, with the same revision:path syntax as git show:

npx @redocly/cli diff origin/main:openapi.yaml openapi.yaml
npx @redocly/cli diff v1.0.0:openapi.yaml v2.0.0:openapi.yaml

If the description has $refs to other files, the command reads those files from the same revision. In GitHub Actions, check out the full history so that the base branch is available:

steps:
  - uses: actions/checkout@v4
    with:
      fetch-depth: 0
  - run: npx @redocly/cli diff origin/${{ github.base_ref }}:openapi.yaml openapi.yaml --format=github-actions

The github-actions format adds an error annotation for each breaking change, on the changed line of the pull request.

Check info.version with --check-version

With --check-version, the command also fails if the new info.version is too low for the changes, for example a minor bump for a breaking change:

npx @redocly/cli diff origin/main:openapi.yaml openapi.yaml --check-version

```text
❌ info.version went 1.2.0 → 1.3.0, but these changes require a major bump (2.0.0).

Get the next version, or a changelog draft

The next-version format prints the next semver version, based on the detected changes. Use it in a release script:

NEXT_VERSION=$(npx @redocly/cli diff origin/main:openapi.yaml openapi.yaml --format=next-version --fail-on=none)

The markdown format writes a table of the changes that you can post as a pull request comment or use as the starting point of a changelog entry:

npx @redocly/cli diff origin/main:openapi.yaml openapi.yaml --format=markdown -o diff.md

Other formats are stylish (the default, for the terminal), json (for scripts), and html (a standalone report).

The diff rules decide which changes are breaking. The diff-recommended ruleset turns on all of them as major. They cover removed paths and operations, changed operationIds, new required parameters and properties, removed response fields, enum changes, narrower or wider types and constraints, and security changes. Many rules check the direction of the data, so a new enum value is major in a response and safe in a request.

Change the impact of a rule, or turn it off, in redocly.yaml:

extends:
  - recommended
  - diff-recommended
diff:
  enum-values-added: minor

If the apis section of redocly.yaml defines both versions, compare them by alias, for example redocly diff cafe@v1 cafe@v2.

Keep versions consistent with an API style guide

Breaking-change detection compares two versions. Linting checks each version against your API standards, so v3 follows the same rules as v2. Run the lint command with the built-in rules, and add configurable rules for your versioning conventions.

The --check-version option fails if the changes require a bump and info.version is not a semver string. For example, the following rule requires a semver string in info.version:

extends:
  - recommended
rules:
  rule/info-version-semver:
    subject:
      type: Info
      property: version
    assertions:
      defined: true
      pattern: /^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$/
    message: info.version must be a semantic version, such as 2.1.0.
    severity: error

Publish versioned API docs

In Redocly's docs platform, you version content with folders whose names start with @, for example @v1 and @v2. Each folder can hold an OpenAPI description and the guides for that version. When a reader opens versioned content, the sidebar displays a version picker and updates to match the selected version. The following project has two versions of an Orders API, each with its own guides and OpenAPI description:

orders-api/├──@v1/│   ├──index.md│   └──openapi.yaml├──@v2/│   ├──index.md│   ├──migrate-from-v1.md│   └──openapi.yaml└──versions.yaml

A versions.yaml file sets the order of the versions, their names in the version picker, and the version that opens by default:

default: v2
versions:
  - version: v1
    name: v1 (deprecated)
  - version: v2
    name: v2 (current)

The versionPicker option in redocly.yaml hides the version picker or displays it on unversioned pages. The Redocly CLI documentation uses the same @v1/@v2 and versions.yaml setup.

To label operations and schema fields in the API reference, for example as Beta or Deprecated, use the x-badges OpenAPI extension.

Put it together: a versioning workflow

  1. Keep the OpenAPI description in the same repository as the code, with a semver info.version.
  2. On every pull request, run redocly lint and redocly diff origin/main:openapi.yaml openapi.yaml --check-version --format=github-actions.
  3. If the diff finds a breaking change, either make the change backward compatible or plan it for the next major version.
  4. At release, use --format=next-version to set the version and --format=markdown to draft the changelog entry.
  5. For a new major version, add a version folder to the docs, mark the old version as deprecated in versions.yaml, and send Deprecation and Sunset headers from the old API.

Frequently asked questions

What is the best way to version an API?

Put the major version in the URI path, make additive changes inside it, and publish a new major version only for breaking changes, which should be rare. Avoid query parameter and media type versioning. Date-based versioning in a header works well, but it is worth its cost only if you have many clients, ship breaking changes often, and can maintain compatibility layers.

Do I need a new version for every change?

No. Additive changes, such as a new endpoint or a new optional response field, do not need a new version. Only breaking changes need a new major version.

Should the OpenAPI info.version match the URL version?

The URL usually carries only the major version (/v2/), while info.version holds the full semver version of the description (2.4.1). Keep their major numbers in sync.

How do I find breaking changes between two OpenAPI files?

Run a breaking-change detector on the two files, for example npx @redocly/cli diff old.yaml new.yaml. The command lists each change with a major, minor, or patch impact, and exits with code 1 if it finds a breaking change.

How long should I support an old API version?

Support the previous major version for at least 12 months after the new one ships, and longer if enterprise clients depend on it. Publish that window and stick to it. Announce the sunset date in advance and send Sunset headers until then.

Learn more