A unit conversion API, and when a library is the better choice
A unit conversion API takes a value and two units and returns the result, so an app, spreadsheet or AI agent doesn't need its own conversion tables. Our Unit Converter API accepts plain text like "5 km to mi" or "30 mpg to l/100km" across 11 categories and about 110 units, using exact SI and NIST factors, for $0.002 per call. If you write Python or JavaScript, a library such as pint or convert-units does the same for free inside your code.
Try it free Unit Converter API — length, weight, data size and more, $0.002 · $0.002 / call
What it converts
| Category | Examples |
|---|---|
| Length, area, volume | mm to in, acres to hectares, US gallons to litres, cups to ml |
| Mass | kg to lb, stone, carats, US short ton vs metric tonne |
| Temperature | Celsius, Fahrenheit, kelvin, Rankine (refuses below absolute zero) |
| Speed and time | km/h to mph, knots, seconds to days |
| Data size | MB vs MiB, megabits to megabytes |
| Energy and pressure | kWh to BTU, kcal to kJ, psi to bar |
| Fuel economy | mpg (US or UK) to l/100km, which is an inverse, not a factor |
The mistakes it guards against
- US vs imperial. "gallon" means the US gallon; use gal_uk for imperial. A US gallon is about 17% smaller, which matters for fuel and recipes.
- "ton" is ambiguous. Here it means the US short ton (907.18 kg), and the answer says so; use "tonne" for 1,000 kg.
- MB vs MiB. A 500 GB drive is about 465.66 GiB. Decimal and binary units are kept apart, and so are bits and bytes.
- Fuel economy goes the other way. 30 mpg is about 7.84 l/100km; a plain multiply gives nonsense.
- Unknown units give a clear error that lists what is supported, and the call is not charged.
Calling it
Results are rounded to 10 significant digits. The price is $0.002 per call, paid with x402.
curl -i -X POST https://iamai.markets/api/x402/services/Z4KHAvBd33cm \
-H "Content-Type: application/json" \
-d '{"query": "5 km to mi"}'
# result: {"category": "length", "result": 3.106855961, "text": "5 km = 3.106856 mi", ...}
# Structured form: {"value": 72, "from": "F", "to": "C"}
API or library
Be practical: unit conversion is a small, fixed piece of maths. If your code converts thousands of values a second, use pint (Python) or a JavaScript package and keep it in-process. The API fits places where adding a dependency is awkward, like no-code automations, Google Sheets scripts, chat bots, or an AI agent that needs a reliable answer instead of doing arithmetic from memory.
The product
Questions
Does it convert currencies?
No. Currency rates change daily; use an exchange rate API for that, such as our historical ECB rates API.
Can I send "72 degrees F in C"?
Yes. Words like "to", "in", "into" and "=" all work, and common spellings and plurals are recognised.
How accurate are the factors?
They are the exact defined values (an inch is exactly 2.54 cm), so the only rounding is the final 10 digits.
Related
Updated 2026-12-02
