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.
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
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
integertostring - narrowing what a request accepts, for example a lower
maxLengthor a removedenumvalue - widening what a response returns, for example a new
enumvalue that a client'sswitchstatement 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.
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.
The version is part of the path.
GET /v2/orders/123
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/.
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.
The version is a release date, usually sent in a header.
GET /orders/123
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.
The version is a request header.
GET /orders/123
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.
The version is a query parameter.
GET /orders/123?api-version=2
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.
The client asks for a versioned media type in the Accept header.
GET /orders/123
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.
The following table compares the six approaches:
| Approach | Verdict | Visibility | Caching | Use it for |
|---|---|---|---|---|
| URI path | Recommended default | High | Works by default | Public APIs (almost always) |
| Evolving, no versions | Recommended inside a version | Not needed | Works by default | Any change inside a major version, and internal APIs |
| Date-based | Only at scale | Low (header) | Needs Vary | APIs with many clients and frequent breaking changes |
| Custom header | Avoid for public APIs | Low | Needs Vary | Carrying date-based versions from an SDK |
| Query parameter | Avoid | High | Depends on cache setup | Matching an existing platform convention |
| Media type | Avoid | Low | Needs Vary: Accept | Hypermedia APIs |
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.
- 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.versionto the changes. Use semantic versioning ininfo.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
DeprecationandSunsetheaders, 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 (semver) uses a MAJOR.MINOR.PATCH version number. For an API, the parts mean:
| Part | Bump when | Example change |
|---|---|---|
| MAJOR | A change can break an existing client | A removed operation, or a new required parameter |
| MINOR | A change adds to the API and breaks nothing | A new endpoint, or a new optional response field |
| PATCH | A change neither breaks nor adds anything | A 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.
Deprecation is a notice that an item still works but is scheduled for removal. Sunset is the date when the deprecated item stops working.
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.
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:
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.
- 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 Gonewith a link to the migration guide, instead of a generic error.
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.
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.
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
diffcommand, 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.
Redocly covers three parts of API versioning: breaking-change detection, API design governance, and versioned docs.
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.
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.
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
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.
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).
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.
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
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.yamlA 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.
- Keep the OpenAPI description in the same repository as the code, with a semver
info.version. - On every pull request, run
redocly lintandredocly diff origin/main:openapi.yaml openapi.yaml --check-version --format=github-actions. - If the diff finds a breaking change, either make the change backward compatible or plan it for the next major version.
- At release, use
--format=next-versionto set the version and--format=markdownto draft the changelog entry. - For a new major version, add a version folder to the docs, mark the old version as deprecated in
versions.yaml, and sendDeprecationandSunsetheaders from the old 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.
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.
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.
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.
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.
diffcommand reference - Options, output formats, and CI examples of theredocly diffcommand- Diff rules - Changes that each diff rule reports, and the impact of each change
- Version content in Redocly - Version folders, the
versions.yamlfile, and the version picker - Use AI to review API design for backward compatibility risks - AI review of an API design for changes that can break clients
- Common decisions about OpenAPI - Recommendations on how to structure and store OpenAPI descriptions