universal unit conversion

Unit Converter
API Documentation

Convert between 400+ units across 17 categories โ€” length, weight, temperature, currency, and more โ€” with precise, real-time results over a simple REST API. Built for developers.

Try it now Back to API Hub

Overview

The Unit Converter API provides accurate conversions across 17 categories including length, weight, temperature, currency, area, volume, speed, time, data storage, bandwidth, pressure, energy, power, torque, frequency, fuel economy, and angle. With over 400 supported units, it offers a generic conversion endpoint, category-specific endpoints, category discovery, and a health check. Every request returns structured JSON with clear error codes.

Base URL & Authentication

Base URL

Base URL

https://api.chemhub.com/api/v1

Authentication

Include your API credentials in every request header.

Headers

X-API-Key: your_api_key
X-API-Secret: your_secret
Content-Type: application/json

Get API Keys

Follow these steps to obtain your API credentials:

1

Log In to Your Account

Existing Users: Go to /login to access your dashboard

New Users: Visit /register to create your free account first

2

Access Your Profile

Once you log in, click on your profile picture in the top-right corner, then click on "Your profile" from the dropdown menu.

3

Create API Key

From your profile page, proceed to the "API Keys" section and create a key by filling in a name you prefer.

Example name

"Unit converter bot" or "My Measurement App"

4

Save Your Credentials

Click on "Create API Key" to generate your credentials, then immediately copy and save both the API Key and Secret.

Critical Warning

Your secret key will only be displayed once! Copy it immediately and store it securely. You won't be able to see it again.

Security Notice

Never share your API keys publicly or commit them to version control. Treat them like passwords โ€” regenerate immediately if compromised.

Rate Limits

Free tier: 5 requests/day | Pro tier: Unlimited. Check your dashboard for current usage and limits.

Endpoints

๐Ÿ’š Health CheckGET /convert/health
๐Ÿ“‹ Get CategoriesGET /convert/categories
๐Ÿ”„ Generic ConvertPOST /convert
๐Ÿ—‚๏ธ Category ConvertPOST /convert/<category>

Health Check

GET/convert/health

Health check endpoint to verify the Unit Converter API status.

Response

Success Response

{
  "success": true,
  "status": "healthy",
  "categories": ["length", "weight", "temperature", "currency", "area", "volume", "speed", "time", "storage", "bandwidth", "pressure", "energy", "power", "torque", "frequency", "fuel", "angle"],
  "timestamp": "2026-07-23T12:00:00"
}

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/convert/health"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

res = requests.get(url, headers=headers)
print(res.json())

cURL

curl -X GET https://api.chemhub.com/api/v1/convert/health \
-H "X-API-Key: your_api_key" \
-H "X-API-Secret: your_secret"

JavaScript

fetch('https://api.chemhub.com/api/v1/convert/health', {
  method: 'GET',
  headers: {
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret'
  }
})
.then(res => res.json())
.then(console.log);

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;

public class HealthCheck {
    private static final String BASE_URL = "https://api.chemhub.com/api/v1";
    private static final String API_KEY = "your_api_key";
    private static final String API_SECRET = "your_secret";

    private static final HttpClient client = HttpClient.newHttpClient();

    public static String checkHealth() throws Exception {
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(BASE_URL + "/convert/health"))
            .header("X-API-Key", API_KEY)
            .header("X-API-Secret", API_SECRET)
            .GET()
            .build();

        HttpResponse response = client.send(
            request, BodyHandlers.ofString()
        );

        return response.body();
    }

    public static void main(String[] args) throws Exception {
        String result = checkHealth();
        System.out.println(result);
    }
}

Get Categories

GET/convert/categories

Returns all available conversion categories with their supported units.

Response

Success Response

{
  "success": true,
  "categories": [
    {
      "id": "length",
      "name": "Length",
      "units": ["meters", "kilometers", "centimeters", "millimeters", "micrometers", "nanometers", "miles", "yards", "feet", "inches", "nautical_miles"]
    },
    {
      "id": "weight",
      "name": "Weight",
      "units": ["kilograms", "grams", "milligrams", "micrograms", "metric_tons", "pounds", "ounces", "stones", "us_tons", "imperial_tons"]
    },
    {
      "id": "temperature",
      "name": "Temperature",
      "units": ["celsius", "fahrenheit", "kelvin"]
    }
  ]
}

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/convert/categories"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

res = requests.get(url, headers=headers)
print(res.json())

cURL

curl -X GET https://api.chemhub.com/api/v1/convert/categories \
-H "X-API-Key: your_api_key" \
-H "X-API-Secret: your_secret"

JavaScript

fetch('https://api.chemhub.com/api/v1/convert/categories', {
  method: 'GET',
  headers: {
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret'
  }
})
.then(res => res.json())
.then(console.log);

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;

public class GetCategories {
    private static final String BASE_URL = "https://api.chemhub.com/api/v1";
    private static final String API_KEY = "your_api_key";
    private static final String API_SECRET = "your_secret";

    private static final HttpClient client = HttpClient.newHttpClient();

    public static String getCategories() throws Exception {
        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(BASE_URL + "/convert/categories"))
            .header("X-API-Key", API_KEY)
            .header("X-API-Secret", API_SECRET)
            .GET()
            .build();

        HttpResponse response = client.send(
            request, BodyHandlers.ofString()
        );

        return response.body();
    }

    public static void main(String[] args) throws Exception {
        String result = getCategories();
        System.out.println(result);
    }
}

Generic Convert

POST/convert

Generic conversion endpoint. Specify the category, value, source unit, and target unit.

Request Parameters

Request Body

Request Body

{
  "category": "length",
  "value": 100,
  "from": "meters",
  "to": "feet"
}

Response

Success Response

{
  "success": true,
  "category": "length",
  "category_name": "Length",
  "value": 100,
  "from_unit": "meters",
  "to_unit": "feet",
  "result": 328.0839895013123,
  "formula": "100 meters = 328.0839895013123 feet"
}

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/convert"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

data = {
    "category": "length",
    "value": 100,
    "from": "meters",
    "to": "feet"
}

res = requests.post(url, json=data, headers=headers)
print(res.json())

cURL

curl -X POST https://api.chemhub.com/api/v1/convert \
-H "X-API-Key: your_api_key" \
-H "X-API-Secret: your_secret" \
-H "Content-Type: application/json" \
-d '{"category":"length","value":100,"from":"meters","to":"feet"}'

JavaScript

fetch('https://api.chemhub.com/api/v1/convert', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret'
  },
  body: JSON.stringify({
    category: 'length',
    value: 100,
    from: 'meters',
    to: 'feet'
  })
})
.then(res => res.json())
.then(console.log);

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;

public class UnitConverter {
    private static final String BASE_URL = "https://api.chemhub.com/api/v1";
    private static final String API_KEY = "your_api_key";
    private static final String API_SECRET = "your_secret";

    private static final HttpClient client = HttpClient.newHttpClient();

    public static String convert(String category, double value, String from, String to) throws Exception {
        String json = String.format(
            "{\"category\":\"%s\",\"value\":%f,\"from\":\"%s\",\"to\":\"%s\"}",
            category, value, from, to
        );

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(BASE_URL + "/convert"))
            .header("Content-Type", "application/json")
            .header("X-API-Key", API_KEY)
            .header("X-API-Secret", API_SECRET)
            .POST(BodyPublishers.ofString(json))
            .build();

        HttpResponse response = client.send(request, BodyHandlers.ofString());
        return response.body();
    }

    public static void main(String[] args) throws Exception {
        String result = convert("length", 100, "meters", "feet");
        System.out.println(result);
    }
}

Category Convert

POST/convert/<category>

Category-specific conversion endpoint. Replace <category> with one of the supported categories. Supports the same request/response format as the generic endpoint.

Request Parameters

Request Body

Request Body

{
  "value": 1,
  "from": "kilograms",
  "to": "pounds"
}

Response

Success Response

{
  "success": true,
  "category": "weight",
  "category_name": "Weight",
  "value": 1,
  "from_unit": "kilograms",
  "to_unit": "pounds",
  "result": 2.2046226218487757,
  "formula": "1 kilograms = 2.2046226218487757 pounds"
}

Code Examples

Python

import requests

url = "https://api.chemhub.com/api/v1/convert/weight"

headers = {
    "X-API-Key": "your_api_key",
    "X-API-Secret": "your_secret"
}

data = {
    "value": 1,
    "from": "kilograms",
    "to": "pounds"
}

res = requests.post(url, json=data, headers=headers)
print(res.json())

cURL

curl -X POST https://api.chemhub.com/api/v1/convert/weight \
-H "X-API-Key: your_api_key" \
-H "X-API-Secret: your_secret" \
-H "Content-Type: application/json" \
-d '{"value":1,"from":"kilograms","to":"pounds"}'

JavaScript

fetch('https://api.chemhub.com/api/v1/convert/weight', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'X-API-Key': 'your_api_key',
    'X-API-Secret': 'your_secret'
  },
  body: JSON.stringify({
    value: 1,
    from: 'kilograms',
    to: 'pounds'
  })
})
.then(res => res.json())
.then(console.log);

Java

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse.BodyHandlers;

public class WeightConverter {
    private static final String BASE_URL = "https://api.chemhub.com/api/v1";
    private static final String API_KEY = "your_api_key";
    private static final String API_SECRET = "your_secret";

    private static final HttpClient client = HttpClient.newHttpClient();

    public static String convertWeight(double value, String from, String to) throws Exception {
        String json = String.format(
            "{\"value\":%f,\"from\":\"%s\",\"to\":\"%s\"}",
            value, from, to
        );

        HttpRequest request = HttpRequest.newBuilder()
            .uri(URI.create(BASE_URL + "/convert/weight"))
            .header("Content-Type", "application/json")
            .header("X-API-Key", API_KEY)
            .header("X-API-Secret", API_SECRET)
            .POST(BodyPublishers.ofString(json))
            .build();

        HttpResponse response = client.send(request, BodyHandlers.ofString());
        return response.body();
    }

    public static void main(String[] args) throws Exception {
        String result = convertWeight(1, "kilograms", "pounds");
        System.out.println(result);
    }
}

Python SDK

Complete Python SDK with all endpoints and error handling.

Complete SDK Class

import requests

BASE_URL = "https://your-api-domain.com"
API_KEY = "YOUR_API_KEY"
API_SECRET = "YOUR_API_SECRET"

session = requests.Session()
session.headers.update({
    "Content-Type": "application/json",
    "Accept": "application/json",
    "X-API-Key": API_KEY,
    "X-API-Secret": API_SECRET
})

# --- Health Check ---
def check_health():
    return session.get(f"{BASE_URL}/api/v1/convert/health").json()

# --- Get Categories ---
def get_categories():
    return session.get(f"{BASE_URL}/api/v1/convert/categories").json()

# --- Generic Convert ---
def convert(category, value, from_unit, to_unit):
    response = session.post(
        f"{BASE_URL}/api/v1/convert",
        json={
            "category": category,
            "value": value,
            "from": from_unit,
            "to": to_unit
        }
    )
    return response.json()

# --- Category-Specific Convert ---
def convert_length(value, from_unit, to_unit):
    response = session.post(
        f"{BASE_URL}/api/v1/convert/length",
        json={"value": value, "from": from_unit, "to": to_unit}
    )
    return response.json()

def convert_weight(value, from_unit, to_unit):
    response = session.post(
        f"{BASE_URL}/api/v1/convert/weight",
        json={"value": value, "from": from_unit, "to": to_unit}
    )
    return response.json()

# --- Test All Endpoints ---
def test_converter():
    print("=== Unit Converter API Test ===")

    health = check_health()
    print(f"Health: {health.get('status', 'unknown')}")

    cats = get_categories()
    print(f"Categories: {len(cats.get('categories', []))}")

    tests = [
        ("Generic length", convert("length", 100, "meters", "feet")),
        ("Weight", convert_weight(1, "kilograms", "pounds")),
        ("Temperature", convert("temperature", 100, "celsius", "fahrenheit")),
        ("Currency", convert("currency", 100, "us_dollars", "euros")),
    ]

    for name, result in tests:
        status = "OK" if result.get("success") else "FAIL"
        print(f"  {name}: {status}")

if __name__ == "__main__":
    test_converter()

Supported Categories

All 17 supported categories with their endpoint paths and sample units.

EndpointCategorySample Units
/convert/lengthLengthmeters, kilometers, centimeters, miles, yards, feet, inches, nautical_miles
/convert/weightWeightkilograms, grams, milligrams, metric_tons, pounds, ounces, stones, us_tons
/convert/temperatureTemperaturecelsius, fahrenheit, kelvin
/convert/currencyCurrencyus_dollars, euros, british_pounds, japanese_yen, canadian_dollars
/convert/areaAreasquare_meters, square_kilometers, square_feet, square_miles, hectares, acres
/convert/volumeVolumeliters, milliliters, cubic_meters, gallons_us, gallons_uk, cups_us, fluid_ounces_us
/convert/speedSpeedmeters_per_second, kilometers_per_hour, miles_per_hour, feet_per_second, knots, mach
/convert/timeTimeseconds, milliseconds, minutes, hours, days, weeks, months, years
/convert/storageData Storagebytes, kilobytes, megabytes, gigabytes, terabytes, petabytes, bits
/convert/bandwidthBandwidthbits_per_second, kilobits_per_second, megabits_per_second, gigabytes, bytes_per_second
/convert/pressurePressurepascals, kilopascals, bar, atmospheres, psi, torr, mmhg, inhg
/convert/energyEnergyjoules, kilojoules, calories, kilocalories, watt_hours, kilowatt_hours, btu, therms
/convert/powerPowerwatts, kilowatts, megawatts, horsepower_mechanical, horsepower_metric, btu_per_hour
/convert/torqueTorquenewton_meters, kilogram_force_meters, foot_pounds, inch_pounds, dyne_centimeters
/convert/frequencyFrequencyhertz, kilohertz, megahertz, gigahertz, terahertz, rpm
/convert/fuelFuel Economyliters_per_100km, miles_per_gallon_us, miles_per_gallon_uk, kilometers_per_liter
/convert/angleAngledegrees, radians, gradians, arcminutes, arcseconds

Errors & Status Codes

Error Response Format

Error Response

{
  "success": false,
  "error": "Invalid input format"
}

Status Codes

Rate Limits

Per-minute limit: 30 requests/minute per API key
Free tier: 5 requests/day
Pro tier: Unlimited requests/day
Concurrent requests: 10 (Pro) / 25 (Ultimate)