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

# Create a schedule by setting energy use duration

If the only input available is the duration your device needs to consume or can export energy, call the [schedule-by-duration](/api-reference/anode/schedules/schedule-by-duration) endpoint.

Flatpeak uses the Location’s tariff and, if a [PV array is present](/guides/schedule/solar-forecasts), the local solar generation forecast to identify the lowest (or highest) cost time slots within the specified period.

In the example below, you request the lowest-priced two-hour window within a given timeframe:

<CodeGroup>
  ```json Request example theme={"system"}
  curl --request POST \
    --url https://api.flatpeak.com/schedules/duration/loc_641b90b758fb8e6293716e40 \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
    "start_time": "2024-05-19T23:21:00Z",
    "end_time": "2024-05-20T06:00:00Z",
    "tariff_direction": "IMPORT",
    "segment": "LOW",
    "duration": 120
  }'
  ```

  ```json Response example (truncated) theme={"system"}
  {
    "id": "std_65e42cdd73e9f861edda35d7",
    "object": "schedule_duration",
    "live_mode": true,
    "location_id": "loc_65e42ce4d3b813479b252160",
    "location_timezone": "Europe/London",
    "currency_code": "EUR",
    "tariff_direction": "IMPORT",
    "data": [
      {
        "start_time": "2024-05-20T01:30:00Z",
        "end_time": "2024-05-20T04:30:00Z",
        "price": {
          "average": 3.221,
          "confidence": 1
        }
      }
    ]
  }
  ```
</CodeGroup>
