> ## Documentation Index
> Fetch the complete documentation index at: https://docs.engrate.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Cost of Energy quickstart

> Find the grid tariff for an address and calculate what a connection pays for a month.

In this guide you find the metering grid area for an address, pick the tariff that fits the connection, and calculate the month's cost per tariff component. The steps are the same for any connection: an apartment, a house, a business or a producer.

The example answers one question: **what does a house in Västerås pay for its grid connection in January?** It takes about ten minutes.

## Before you start

* **An API key.** Create one in the [console](https://console.engrate.io). See [Authentication](https://docs.engrate.io/guides/authentication.md).
* **Access to the Västmanland Södra grid area.** On a trial, pick it as your trial metering grid area in the console, under **Cost of Energy**, before you start. With full access you can skip this.
* **Python 3.10 or later** with [httpx](https://www.python-httpx.org/), for the last step: `pip install httpx`.

```bash theme={null}
export API_KEY="<your key>"
```

**1. Find the metering grid area**

A tariff depends on where the house connects to the grid. Look up the metering grid area for the house's coordinates:

```bash curl theme={null}
curl --request GET \
  --url "https://api.engrate.io/core/v1/metering-grid-areas?lat=59.611&lon=16.545" \
  --header "authorization: $API_KEY"
```

```python Python theme={null}
import os
import httpx

api = httpx.Client(
    base_url="https://api.engrate.io",
    headers={"authorization": os.environ["API_KEY"]},
)

mga = api.get("/core/v1/metering-grid-areas", params={"lat": 59.611, "lon": 16.545}).json()["mgas"][0]
```

```json Response theme={null}
{
  "mgas": [
    {
      "id": "fa393787-4a78-52a9-8863-85ffe4508f21",
      "name": "Västmanland Södra",
      "extra_ids": [
        { "kind": "se.mga_code", "value": "VLS" }
      ]
    }
  ]
}
```

You can also search by address with `street`, `city` and `zipcode`.

**2. List the tariffs in the area**

A grid area has many tariffs: for apartments, houses, businesses and producers. Each one says who it is for in `eligibility`:

```bash curl theme={null}
curl --request GET \
  --url "https://api.engrate.io/cost-of-energy/v1/tariffs?metering_grid_area_id=fa393787-4a78-52a9-8863-85ffe4508f21" \
  --header "authorization: $API_KEY"
```

```python Python theme={null}
tariffs = api.get("/cost-of-energy/v1/tariffs", params={"metering_grid_area_id": mga["id"]}).json()["tariffs"]
```

```json Response (shortened) theme={null}
{
  "tariffs": [
    {
      "id": "e01abc49-ff64-57de-8294-bb38c8a79dec",
      "name": "Säkringsabonnemang Lägenhet",
      "eligibility": {
        "fuse_size": { "minimum": 16.0, "maximum": 25.0, "unit": "A" },
        "other": ["fuse_based", "apartment", "offtake"]
      }
    },
    {
      "id": "042c0b34-f270-52c6-b9ac-4a55518aa122",
      "name": "Säkringsabonnemang 20 A",
      "eligibility": {
        "fuse_size": { "value": 20.0, "unit": "A" },
        "other": ["fuse_based", "offtake"]
      }
    },
    {
      "id": "99d8a11a-227c-5ad0-a5c9-6b5cd4e63b31",
      "name": "Lågspänning",
      "eligibility": {
        "fuse_size": null,
        "other": ["low_voltage_grid", "business", "offtake"]
      }
    }
  ]
}
```

**3. Pick the house's tariff**

The house has a 20 A main fuse and takes energy from the grid. Match that against `eligibility`, and leave out the apartment tariff:

```python Python theme={null}
def fits(eligibility: dict, fuse_a: float) -> bool:
    fuse = eligibility.get("fuse_size")
    if not fuse:
        return False
    if "value" in fuse:
        return fuse["value"] == fuse_a
    return (fuse["minimum"] or 0) <= fuse_a <= (fuse["maximum"] or fuse_a)

tariff = next(
    (
        t for t in tariffs
        if fits(t["eligibility"], 20)
        and "offtake" in t["eligibility"]["other"]
        and "apartment" not in t["eligibility"]["other"]
    ),
    None,
)
if tariff is None:
    raise SystemExit("No tariff for a 20 A household connection in this grid area")
```

That gives **Säkringsabonnemang 20 A**. Its four components are what the house pays in January 2026:

| Component | What it charges | Rate |
| - | - | - |
| Effektavgift | The highest weekday hour between 07:00 and 19:00, holidays excluded | 47.4 SEK per kW per month |
| Fast avgift | A fixed fee | 318 SEK per month |
| Elöverföring | Energy transferred | 0.172 SEK per kWh |
| Energiskatt | Energy tax | 0.36 SEK per kWh |

Fetch the tariff with `GET /cost-of-energy/v1/tariffs/{tariff_id}` to see each component's [calculation pipeline](https://docs.engrate.io/api-reference/cost-of-energy/calculation-pipeline.md). A component also has a validity window: when the operator changes a price, a new component takes over from that date.

**4. Calculate January**

Send the house's consumption for January, one value per quarter-hour in kWh, and get the cost per component back. This example generates a simple household profile: a little at night, more in the morning, most in the evening.

```python Python theme={null}
from datetime import datetime, timedelta, timezone
from zoneinfo import ZoneInfo

stockholm = ZoneInfo("Europe/Stockholm")
start = datetime(2026, 1, 1, tzinfo=stockholm)
end = datetime(2026, 2, 1, tzinfo=stockholm)

def kwh(t: datetime) -> float:
    local = t.astimezone(stockholm)
    if 17 <= local.hour < 21:
        return 0.9
    if 7 <= local.hour < 9 and local.weekday() < 5:
        return 0.6
    if local.hour < 6:
        return 0.25
    return 0.4

t, offtake = start.astimezone(timezone.utc), []
while t < end.astimezone(timezone.utc):
    offtake.append(kwh(t))
    t += timedelta(minutes=15)

result = api.post("/cost-of-energy/v1/calculate", json={
    "tariff_id": tariff["id"],
    "start_time": start.isoformat(),
    "end_time": end.isoformat(),
    "time_series": [{"name": "quarter-hourly-energy-offtake", "values": offtake}],
}).json()

for component in result["components"]:
    print(component["name"], round(sum(component["time_series"][0]["values"]), 2))
```

```text Output theme={null}
Effektavgift 170.64
Fast avgift 318.0
Elöverföring 234.26
Energiskatt 490.32
```

**The house pays 1,213.22 SEK for its grid connection in January.** It used 1,362 kWh. Its highest weekday hours inside the peak window, 17:00 to 19:00, used 3.6 kW, so the peak fee is 3.6 kW × 47.4 SEK/kW = 170.64 SEK. The same load after 19:00 never counts towards the peak.

Each component returns its cost at its own resolution: the peak and fixed fees once for the month, transfer and tax per quarter-hour. Add `?include_intermediate_time_series=true` to see every step of each pipeline.

## Next steps

> [card] [Which tool for which question](https://docs.engrate.io/products/cost-of-energy.md#which-question-are-you-asking)
>
> Calculate, compare tariffs, optimise a battery, or find the expensive hours.

> [card] [Calculation pipelines](https://docs.engrate.io/api-reference/cost-of-energy/calculation-pipeline.md)
>
> How a component turns consumption into cost, step by step.

> [card] [Python SDK](https://docs.engrate.io/api-reference/cost-of-energy/engratepy.md)
>
> Run the same calculation, or an optimisation, on your side.

> [card] [Cookbook](https://github.com/engrate/engrate-cookbook)
>
> Runnable recipes: fetch a tariff, calculate a cost, optimise a home battery.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.