Unit converter API: length, mass, temperature, data sizes and Mbps to MB/s
Pass a number plus two units and get the converted value back as JSON. Covers everyday length and mass, careful temperature formulae (C, F, K), and the decimal-vs-binary data-size trap (KB is 1000 bytes; KiB is 1024).
/v1/units?value=5&from=km&to=mi returns JSON. No key, CORS on, 60 requests a minute./v1/units
Convert length, mass, temperature, data-size or data-rate units. Change the values and press Send request to call the live API.
Parameters
| Name | Type | What it does | Default |
|---|---|---|---|
value required | string | Number to convert | — |
from required | string | Source unit (m, km, lb, C, MiB, Mbps, MB/s…) | — |
to required | string | Target unit | — |
category | string | Optional: length, mass, temperature, data or rate (disambiguates) | — |
Example
Request:
GET https://api.oddlathe.com/v1/units?value=5&from=km&to=mi
Response (generated by the real code when these docs were last built; random or time-based values will differ for you):
{
"value": 5,
"from": "km",
"to": "mi",
"category": "length",
"result": 3.10685596119
}
Code examples
curl 'https://api.oddlathe.com/v1/units?value=5&from=km&to=mi'const params = new URLSearchParams({
value: "5",
from: "km",
to: "mi"
});
const res = await fetch(`https://api.oddlathe.com/v1/units?${params}`);
if (!res.ok) throw new Error((await res.json()).error.message);
const data = await res.json();
console.log(data);import json, urllib.parse, urllib.request
params = urllib.parse.urlencode({"value": "5", "from": "km", "to": "mi"})
url = "https://api.oddlathe.com/v1/units?" + params
# Send a User-Agent: the edge network refuses Python's default one.
req = urllib.request.Request(url, headers={"User-Agent": "my-script/1.0"})
with urllib.request.urlopen(req, timeout=10) as r:
data = json.load(r)
print(data)When it's useful
- Scripts that normalise mixed units from spreadsheets or CSV without pulling in a conversion library
- Showing "5 km is about 3.1 mi" next to a measurement in a UI
- Turning an advertised broadband speed in Mbps into the MB/s a download bar will actually show
- Checking whether a file-size limit is 5 MB (5,000,000 bytes) or 5 MiB (5,242,880 bytes)
- Teaching the difference between Celsius, Fahrenheit and Kelvin with a live example
Good to know
value,fromandtoare required. Optionalcategory=length|mass|temperature|datarejects units from the wrong family.- Length base is the metre:
m,km,cm,mm,mi,yd,ft,in,nmi(international nautical mile). - Mass base is the kilogram:
kg,g,mg,lb,oz,t(metric tonne = 1000 kg, not the US/UK ton). - Temperature uses offset formulae via Kelvin, not a multiply. Values below absolute zero (0 K) are rejected. A short
noteis included. - Data sizes:
B,KB/MB/GB/TBare SI (1000-based);KiB/MiB/GiB/TiBare IEC binary (1024-based). The responsenotereminds you which is which. - Data rates (
category=rate): base is bits per second.bps,kbps,Mbps,Gbpsare bits;B/s,KB/s,MB/s,GB/sare bytes (×8);KiB/s,MiB/s,GiB/sare binary byte rates. Case matters for the compact forms:Mbpsis megabits,MBpsis megabytes. URL-encode the slash (MB%2Fs) or useMBps. - Aliases like
kilometre,pounds,celsiusormebibyteare accepted and normalised to the short form in the response. - Both units must be in the same category. Pure maths on the query string; nothing is stored.
- Browser UI: Tooltern unit converter (same maths, nothing leaves your device). Plain-words companions: KB vs KiB / MB vs MiB, Celsius ↔ Fahrenheit ↔ Kelvin, metric tonne vs ton.
Convert a number between common units of length, mass, temperature or digital data size. Length uses metres as the base (m, km, cm, mm, mi, yd, ft, in, nmi). Mass uses kilograms (kg, g, mg, lb, oz, t for the metric tonne). Temperature accepts C, F and K with proper offset formulae. Data sizes distinguish SI (KB/MB/GB/TB = 1000) from IEC binary (KiB/MiB/GiB/TiB = 1024). Data rates convert between bits and bytes per second (Mbps, MB/s, MiB/s…; lower-case b = bits). Optional category disambiguates. Pure maths; nothing is stored.
Errors
Errors are JSON like {"error": {"code": "…", "message": "…"}}. The ones this endpoint can return:
missing_param(400): a required parameter is missing or emptybad_param(400): a value is the wrong type or out of range (the message says which)rate_limited(429): over 60 requests a minute; wait for Retry-After seconds
Questions
Why is 1 KB not 1024 bytes?
Hard-drive makers and the SI standard use 1000. Memory and many OS tools historically used 1024 and later renamed that to KiB (kibibyte). This API keeps both: KB = 1000, KiB = 1024.
Can I convert pounds to kilometres?
No. Units must share a category (length, mass, temperature or data). Mixing them returns bad_param.
How is temperature converted?
Everything goes through Kelvin with the standard offsets (C = K − 273.15, F = C × 9/5 + 32). Absolute zero and below are rejected.
How many MB/s is 100 Mbps?
12.5. <code>/v1/units?value=100&from=Mbps&to=MBps</code> returns 12.5, because one byte is 8 bits. Real downloads land a little lower after protocol overhead.
Is t a US ton?
No. t is the metric tonne (1000 kg). US short ton and UK long ton are not supported.
Is anything stored?
Never. Pure maths on the query string.
Related endpoints
/v1/percentPercentage calculator: of, is, change, apply, reverse/v1/colorColour formats (hex, RGB, HSL, OKLCH) and WCAG contrast/v1/date/diffAge, duration and ISO week maths between two dates
Prefer a page to an API?
- Unit converter (length, mass, °C/°F/K, KB vs KiB) on Tooltern: same job, nothing leaves your browser.
Published , updated · OpenAPI 3.1 spec · Limits and privacy