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

# Instantly calculate energy cost

Flatpeak supports instant energy cost (for imports) and value (for exports) calculation at both **Device** and **Location** levels (i.e. property address).

**Use device-level reporting** when calculating costs for a specific device — this allows additional devices to be added to the same location later without losing historical data (recommended).

To implement:

<Steps>
  <Step title="Create device identifier">
    * Call [create-a-device](/api-reference/anode/devices/create-a-device) endpoint; add you internal device ID for cross-reference.
    * Store the returned `device_id` permanently in your system.

    <Note>This step only needs to be performed once per device.</Note>

    <CodeGroup>
      ```json Request example theme={"system"}
      curl --request POST \
        --url https://api.flatpeak.com/devices \
        --header 'Authorization: Bearer <token>' \
        --header 'Content-Type: application/json' \
        --data '{
        "reference_id": "DEV1234567890"
      }'
      ```

      ```json Response example theme={"system"}
      {
        "id": "dev_63a6087272941ef077a8fd3e",
        "object": "device",
        "reference_id": "DEV1234567890"
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Submit meter records & get energy cost/value">
    * Call [instant-cost-calculate](/api-reference/anode/costs/instantly-calculate-energy-cost) endpoint to submit energy consumption or export meter records collected from your device.

    * Set  `energy_flow_direction=INBOUND` and `tariff_direction=IMPORT` to submit meter records for energy import and calculate cost using import price.

    * Set  `energy_flow_direction=OUTBOUND` and `tariff_direction=EXPORT` to submit meter records for energy export and calculate cost using export price.

    <CodeGroup>
      ```json Request example theme={"system"}
      curl --request POST \
        --url https://api.flatpeak.com/costs/instant \
        --header 'Authorization: Bearer <token>' \
        --header 'Content-Type: application/json' \
        --data '{
        "location_id": "loc_641b90b758fb8e6293716e40",
        "device_id": "dev_65e6d8334c8d715963d99db3",
        "energy_flow_direction": "INBOUND",
        "tariff_direction": "IMPORT",
        "units": "W",
        "value": 20567,
        "start_time": "2022-02-01T10:30:00Z",
        "end_time": "2022-02-01T11:00:00Z"
      }'
      ```

      ```json Response example theme={"system"}
      {
        "id": "mre_65e641b570b2901d3a40199d",
        "object": "meter_record",
        "energy_flow_direction": "INBOUND",
        "tariff_direction": "IMPORT",
        "currency_code": "GBP",
        "energy_units": "WH",
        "data": {
          "start_time": "2022-02-01T10:30:00Z",
          "end_time": "2022-02-01T11:00:00Z",
          "cost": {
            "value": 8.372,
            "confidence": 1
          }
        }
      }
      ```
    </CodeGroup>
  </Step>
</Steps>

## Submit actual solar generation data

If a PV system is installed at the location and you have access to its production records, submit them **as they arrive**. This is particularly important if you use [Solar Generation Forecasts](/guides/schedule/solar-forecasts), as it ensures accurate generation data for cost calculations.

Submitted records are applied immediately in all energy cost calculations. The per-kWh cost is assumed to be zero unless the customer uses the [Connect](/guides/connect/settings-page#when-flatpeak-location-id-is-not-yet-available) to set a local generation price.

* Submit generation to [submit-meter-interval](/api-reference/anode/meters/submit-meter-interval) endpoint.
* If your system generates cumulative records, use [submit-meter-cumulative](/api-reference/anode/meters/submit-meter-cumulative) instead.
* Include relevant `device_id` and `location_id`
* Set `energy_flow_direction=INBOUND` and `tariff_direction=LOCAL`
* Set the `confidence` parameter to **1**

<CodeGroup>
  ```json Request example highlight={10} theme={"system"}
  curl --request PUT \
    --url https://api.flatpeak.com/meters/interval \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '[
    {
      "location_id": "loc_641b90b758fb8e6293716e40",
      "device_id": "dev_63a6087272941ef077a8fd3e",
      "energy_flow_direction": "INBOUND",
      "tariff_direction": "LOCAL",
      "confidence": 1,
      "units": "W",
      "value": 968,
      "start_time": "2025-08-01T10:30:00Z",
      "end_time": "2025-08-01T11:00:00Z",
    }
  ]'
  ```

  ```json Response example theme={"system"}
  {
    "id": "bat_65e42b7827c0526548432b9f",
    "object": "meter_batch",
    "records_submitted": 1,
    "records_accepted": 1,
    "records_processed": 1
  }
  ```
</CodeGroup>

## Simulate energy cost profiles

<Tip>
  To estimate energy cost without storing the data, pass the `non_persistent=true` in your request.
  This lets you model scenarios without affecting actual meter data or triggering downstream reporting.
</Tip>
