Semver compare
Exactsemver_compareDeterministic and authoritative — the canonical answer for this input.
Compare two SemVer versions. Returns order='lt'|'eq'|'gt' using full precedence rules: numeric major/minor/patch, pre-release identifier-by-identifier (numeric < alphanumeric, more identifiers wins). Build metadata is ignored per the spec. Fixes the naive string-comparison 2.10.0 < 2.9.0 trap. Processing multiple inputs? Use `semver_compare_batch` to do up to 1000 in one call.
Parameters
astringrequiredLeft operand.
bstringrequiredRight operand.
Call it
curl -X POST https://api.snipget.ai/v1/semver/compare \
-H "Authorization: Bearer sk_live_..." \
-H "Content-Type: application/json" \
-d '{"a":"2.10.0","b":"2.9.0"}'The Batch tab sends up to 1000 inputs in one call via /v1/semver/compare/batch.
Example response
{
"is_valid": true,
"a": "2.10.0",
"b": "2.9.0",
"order": "gt",
"a_is_prerelease": false,
"b_is_prerelease": false
}FAQ
Why not just compare the two version strings myself?
Plain text comparison gets version numbers wrong. As text, "2.10.0" looks smaller than "2.9.0" because "1" sorts before "9", but as a real version 2.10.0 is newer. This tool applies the official SemVer rules so you get the right answer every time.
What does the result tell me?
It returns order as one of three values: "lt" means the first version is older, "gt" means it is newer, and "eq" means they are the same. It also flags whether either side is a pre-release like 1.0.0-beta.
Is the answer reliable, or is it a guess?
It is exact and authoritative. The comparison is fully deterministic by the SemVer 2.0.0 specification, so the same two versions always return the same result. There is no fuzzy matching or estimation involved.
Does it consider build metadata, like the +build.7 part?
No. Per the SemVer spec, build metadata is ignored when ordering versions, so 1.0.0+build.1 and 1.0.0+build.2 compare as equal. Pre-release tags like -beta.1 do count, and a pre-release always ranks below the matching final release.
What happens if I pass something that isn't a real version?
You get a clear answer, not a crash. If either side is not a valid version, the tool returns confidence 0 with is_valid false and a why_invalid reason explaining which side was bad.