Turn kilowatt-hours into actual cost.

powercost is a tiny, dependency-free SDK that converts electricity consumption into the true all-in cost — spot energy, grid fees, energy tax and VAT, itemised. It runs in the browser (or Node), with tariff data as lazy-loaded packs. Calibrated to real Swedish tariffs.

npm i powercost

import { price } from 'powercost';
import { swedenDb } from 'powercost/data/se';   // lazy data pack

const cost = await price({
  consumption: [{ start, end, kwh }],
  config: { zone: 'SE3', providerPlanId: 'tibber-kvartspris', gridOperatorId: 'vattenfall-e4-25a', reportCurrency: 'USD' },
  db: swedenDb,
  live: true,                       // fetch spot + FX in the browser
});
cost.total.format();                // "1.23 SEK"
~9 kB
core, gzipped-tiny · 0 deps
0.02%
error vs. a real Tibber invoice
serverless
runs on a static site / GitHub Pages
15 min
live spot resolution (SE1–SE4)

What it does

A Swedish electricity bill is two companies plus the state. powercost models all of it.

Spot + provider

Day-ahead spot price per bidding zone (15-min), plus your provider's påslag and fees — e.g. Tibber.

🔌

Grid + tax

Your grid operator's transfer fee and fixed charges, energy tax (energiskatt), and 25% VAT on top of everything.

🧾

Itemised & auditable

Every line returned separately in exact integer money — so you can trust the number, not just see it.

📈

Marginal vs. total

Separates the per-kWh cost that scales with usage from fixed monthly fees — the number load-shifting needs.

🌐

Serverless

Pure ESM, no backend. Live spot (elprisetjustnu) + FX (ECB) are fetched directly from the browser.

🧩

Data as packs

Load only what you need — import('powercost/data/se'). New countries are just new modules.

Built for net-profit decisions

The first thing it powers: is hosting a GPU worth it after electricity?

Feed measured consumption and your tariff; powercost returns the marginal all-in cost of those kWh. Net it against rental income for profit per day, week, month — and the break-even spot price to auto-pause above. The same engine works for EV charging, batteries, heat pumps, or any "what did this actually cost?" question.

How the cost model works →

Three steps

1 · Log consumption

A series of intervals — { start, end, kwh }. 5-minute, 15-minute, hourly; whatever you measure.

2 · Load a data pack

import('powercost/data/se') — region (SE1–SE4) + provider + grid operator. New markets are new packs.

3 · Call price()

One call returns the itemised, all-in cost in your currency — computed locally, no server.