Energy Converter API: The Complete Guide

Need to convert energy units in your application? This guide covers everything you need to know about energy conversion via API, including electrical, thermal, and nutritional energy units with implementation examples.

Understanding Energy Units

Energy is the capacity to do work. The SI unit is the joule (J), but different fields use different units: kilowatt-hours (kWh) for electricity, calories for nutrition, BTU for heating/cooling, and electron volts (eV) in physics.

Energy conversion is essential for utility applications, fitness/nutrition apps, HVAC systems, and scientific calculations.

Supported Energy Units

Unit Code Common Use
JouleJSI unit, physics
KilojoulekJNutrition (intl)
CaloriecalSmall scale
KilocaloriekcalNutrition (US)
Kilowatt-hourkWhElectricity
Watt-hourWhBatteries
BTUBTUHVAC (US)
Electron VolteVPhysics
Common Conversions: 1 kWh = 3,600,000 J, 1 kcal = 4,184 J, 1 BTU = 1,055.06 J

Using the Energy Converter API

TinyFn provides a dedicated endpoint for energy conversions:

API Request
GET https://api.tinyfn.io/v1/convert/energy
Headers: X-API-Key: your-api-key
Response
{
  "from_unit": "kcal",
  "to_unit": "kJ",
  "value": 2000,
  "result": 8368,
  "formula": "2000 × 4.184"
}

Parameters

Parameter Type Description
from string Source unit code (e.g., "kcal")
to string Target unit code (e.g., "kJ")
value number Value to convert

Code Examples

JavaScript / Node.js

const response = await fetch(
  'https://api.tinyfn.io/v1/convert/energy?from=kcal&to=kJ&value=2000',
  { headers: { 'X-API-Key': 'your-api-key' } }
);
const data = await response.json();
console.log(data.result); // 8368

Python

import requests

response = requests.get(
    'https://api.tinyfn.io/v1/convert/energy',
    params={'from': 'kcal', 'to': 'kJ', 'value': 2000},
    headers={'X-API-Key': 'your-api-key'}
)
data = response.json()
print(data['result'])  # 8368

cURL

curl "https://api.tinyfn.io/v1/convert/energy?from=kcal&to=kJ&value=2000" \
  -H "X-API-Key: your-api-key"

Common Use Cases

  • Nutrition Apps: Convert between kcal and kJ
  • Utility Monitoring: Track electricity usage in kWh
  • HVAC Applications: Calculate heating/cooling in BTU
  • Fitness Trackers: Display calories burned
  • Solar/Battery: Calculate stored energy in Wh

Best Practices

  1. Know your context: Use kcal for food (US), kJ internationally
  2. Be precise: Note that 1 Calorie (big C) = 1 kcal
  3. Show both units: Display kcal/kJ for nutrition labels
  4. Match industry: Use BTU for HVAC, kWh for electricity

Use via MCP

Your AI agent can call this tool directly via Model Context Protocol — no HTTP code needed. Add TinyFn to Claude Desktop, Cursor, or any MCP client:

{
  "mcpServers": {
    "tinyfn-convert": {
      "url": "https://api.tinyfn.io/mcp/convert/",
      "headers": {
        "X-API-Key": "your-api-key"
      }
    }
  }
}

See all conversion tools available via MCP in our Conversion MCP Tools for AI Agents guide.

Try the Energy Converter API

Get your free API key and start converting energy units in seconds.

Get Free API Key

Ready to try TinyFn?

Get your free API key and start building in minutes.

Get Free API Key