This is an open API that allows you to calculate energy costs for different power units and time periods. The API accepts various power units and returns costs in your preferred currency.
https://yourdomain.com/calc
Calculate energy costs for a given power value and cost per kWh.
Send a JSON POST request with the following structure:
{
"watts": 1000,
"costPerKwh": 0.24,
"currency": "£",
"powerOnHours": 24
}
You must provide exactly one power unit with its value:
milliwatts - Power in milliwattswatts - Power in wattskilowatts - Power in kilowattsmegawatts - Power in megawattsgigawatts - Power in gigawattspowerUnit (required) - One of the power units above with its valuecostPerKwh (required) - Cost per kilowatt-hour as a numbercurrency (optional) - Currency symbol (defaults to £)powerOnHours (optional) - Hours per day the device is powered on (defaults to 24){
"power": {
"value": 1000,
"unit": "watts"
},
"costPerKwh": 0.24,
"currency": "£",
"costs": {
"hour": "0.12",
"day": "2.88",
"week": "20.16",
"month": "87.60",
"year": "1051.20"
}
}
cURL:
curl -X POST https://yourdomain.com/calc \
-H "Content-Type: application/json" \
-d '{
"kilowatts": 1.5,
"costPerKwh": 0.15,
"currency": "$",
"powerOnHours": 12
}'
JavaScript:
fetch('https://yourdomain.com/calc', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
watts: 1000,
costPerKwh: 0.24,
currency: '£',
powerOnHours: 16
})
})
.then(response => response.json())
.then(data => console.log(data));
The API returns appropriate HTTP status codes and error messages:
400 - Bad Request (invalid input)405 - Method Not Allowed (non-POST requests)This is an open API with no rate limits. Please use responsibly.
This API is provided as-is for educational and development purposes. Feel free to use it in your projects!