> ## 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.

# Report historic energy cost

Flatpeak supports aggregated energy cost reporting at both **Device** and **Location** (i.e. property address) levels.

Use device-based reporting if you are calculating cost (or value if exported energy) for a specific device at a location — this allows you to add additional devices to the same location in the future without losing your data.

If you already use [instant-cost-calculate](/api-reference/anode/costs/instantly-calculate-energy-cost), you do not need to re-submit meter reading to get aggregated costs. Every reading you submit is stored and can be used to report aggregated costs.

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 historic meter records">
    <Note>Skip this step if you already submit meter records using the [instant-cost-calculate](/api-reference/anode/costs/instantly-calculate-energy-cost) endpoint</Note>

    * If your system generates **interval** meter records, use the [submit-meter-interval](/api-reference/anode/meters/submit-meter-interval) endpoint to submit energy consumption or export data from your device.

    * If your system generates **cumulative** meter records, use the [submit-meter-cumulative](/api-reference/anode/meters/submit-meter-cumulative) endpoint instead.

    * 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.

    The response includes confirmation of acceptance and processing status. You can submit up to **10,000** records at a time.

    <CodeGroup>
      ```json Request example 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_65e6d8334c8d715963d99db3",
          "session_reference_id": "SESSION1234567890",
          "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": "bat_65e42b7827c0526548432b9f",
        "object": "meter_batch",
        "records_submitted": 1,
        "records_accepted": 1,
        "records_processed": 1,
        "time_created": "2022-02-01T11:01:03Z"
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Get energy cost/value report">
    * Call [report-cost-by-interval](/api-reference/anode/costs/calculate-energy-cost-by-time-interval) endpoint to request cost report for a time interval.

    * If your use case requires reporting energy cost by non time-based event, such as EV charging session, include `session_reference_id` when submitting meter records and call [report-cost-by-session-id](/api-reference/anode/costs/calculate-energy-cost-by-session-id) to get cost report.

    <CodeGroup>
      ```json Request example theme={"system"}
      curl --request POST \
        --url https://api.flatpeak.com/costs/interval/{id} \
        --header 'Authorization: Bearer <token>' \
        --header 'Content-Type: application/json' \
        --data '{
        "start_time": "2023-11-07T05:31:56Z",
        "end_time": "2023-12-07T05:31:56Z",
        "tariff_direction": "IMPORT"
      }'
      ```

      ```json Response example theme={"system"}
      {
        "id": "ecs_65ea3fb185c1541f247c251e",
        "object": "energy_cost",
        "object_id": "dev_65e6d8334c8d715963d99db3",
        "tariff_direction": "IMPORT",
        "location_timezone": "Europe/London",
        "currency_code": "EUR",
        "energy_units": "WH"
        "data": [
          {
            "start_time": "2023-11-07T05:31:56Z",
            "end_time": "2023-12-07T05:31:56Z",
            "energy": {
              "value": 10284
            },
            "cost": {
              "value": 6.372,
              "confidence": 1
            }
          }
        ]
      }
      ```
    </CodeGroup>
  </Step>

  <Step title="Submit 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**.

    They will be applied immediately for all cost reporting. The per-kWh cost is assumed to be zero unless the customer [uses the Connect to set a local generation price](/guides/connect/settings-page#when-flatpeak-location-id-is-not-yet-available) (`COMMODITY+LOCAL` case).

    * 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>
  </Step>
</Steps>

## 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>
