AllUnits API v1.0 · JSON over HTTPS · CORS enabled

Convert units with the factors the site actually uses

Every response returns the stored factor, the offset, the display precision and the page that documents the definition — so you can reproduce the number instead of trusting it.

Quickstart

No key needed for light use:

curl "https://api.allunits.org/v1/convert?from=km&to=mi&value=10"
{
  "ok": true,
  "input":  { "value": 10, "from": "km" },
  "output": { "value": 6.213712, "unit": "mi" },
  "pair": "km-to-miles",
  "factor": 0.6213711922,
  "offset": 0,
  "decimals": 6,
  "unrounded": 6.213711922,
  "formula": "mi = km x 0.621371",
  "definition_page": "https://allunits.org/km-to-miles/",
  "category": "length",
  "attribution": "AllUnits.org - https://allunits.org/",
  "quota": { "plan": "anonymous", "remaining_today": 99 }
}

Trimmed for readability; the live response also carries direction and the rate-limit headers.

Unit names work as well as symbols — kilometers, pounds, fahrenheit, celsius. The reverse direction needs no second pair: ?from=mi&to=km uses (value − offset) / factor.

Batch

Up to 100 conversions per request. One bad row does not fail the batch — each item comes back with ok and either output or error, in the same order.

curl -X POST https://api.allunits.org/v1/convert \
  -H "Content-Type: application/json" \
  -H "x-api-key: $ALLUNITS_KEY" \
  -d '{"batch":[
        {"from":"kg","to":"lb","value":2.5},
        {"from":"psi","to":"bar","value":35}
      ]}'

Endpoints

MethodPathPurpose
GET/v1/healthLiveness and dataset version
GET/v1/pairsThe 30 supported pairs
GET/v1/factorsFull dataset with factors, formulas, pages
GET/v1/convertOne conversion from query parameters
POST/v1/convertOne conversion or a batch
GET/v1/usageQuota for the calling key or IP

Machine-readable spec: /openapi.json (OpenAPI 3.1). The same dataset is downloadable as factors.json.

Auth & limits

TierHowDaily limit
Anonymousno key100 requests per IP
API Basicx-api-key: YOUR_KEY10,000
API Creatorx-api-key: YOUR_KEY100,000

Authorization: Bearer YOUR_KEY works as well. Every response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset (seconds until reset); a 429 includes Retry-After.

The daily counter is a soft abuse guard, not a billing meter: Cloudflare KV has no atomic increment, so a handful of concurrent requests can escape counting. Tell us at order time if you need exact metering — that needs a Durable Object in front of the key.

Errors

All errors are { "ok": false, "error": { "code": "...", "message": "..." } }.

CodeHTTPMeaning
missing_units400from or to absent
missing_value400value absent
invalid_value400Not a finite number
value_too_large400Beyond ±1e15
unknown_pair400Includes available_pairs_from_source
batch_too_large400More than 100 items
invalid_key401Key not found or inactive
rate_limited429Daily quota exhausted
not_found404Unknown route

Precision, and what is exact

factor and offset are the values the site computes with; decimals is what the site displays. Rounding happens only at the display step — unrounded is always in the response, and ?decimals= accepts 0–12.

Some definitions are exact and some are working precision. A pair is exact when the underlying standard defines it exactly (1 mile = 1,609.344 m, 1 lb = 0.45359237 kg, 1 in = 25.4 mm, 1 yd = 0.9144 m). Binary prefixes (KiB, MiB, GiB) follow IEC 80000-13. Temperature uses the offset form: result = value × factor + offset.

The definition_page field points at the page that states which convention is in use — US vs imperial gallon, statute vs nautical mile. If your use case depends on a convention, read that page rather than assuming.

Pricing

API Basic

$9 / month
  • 10,000 requests per day
  • Batch endpoint
  • Priority inbox

API Creator

$29 / month
  • 100,000 requests per day
  • Batch endpoint
  • Priority inbox

Data licence

$49 one-time
  • Attribution waived
  • 12 months of dataset updates
  • One product or report

Anonymous

Free
  • 100 requests per day
  • No signup
  • Attribution required

Keys are delivered by email, usually within a few hours. Cancel any time; keys stay valid until the end of the paid period.

Request a key — contact@allunits.org

Licence & attribution

The data is published under CC BY 4.0. Using it in a product, a report or a dataset requires attribution:

Unit conversion data: AllUnits.org — https://allunits.org/

Every successful response already includes an attribution field you can render. If you cannot carry a visible attribution (internal tooling, a paid product, a printed datasheet), the one-time data licence removes the requirement.