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

# Schedule by time duration

> Find the lowest or highest-cost time slots by specifying a required total duration.

For example, to schedule 5 hours at the lowest price within a defined time window, Flatpeak will return the optimal periods. The schedule may be split into multiple segments to minimise cost.



## OpenAPI

````yaml api-reference/anode/flatpeak-api-spec-anode.json POST /schedules/duration/{id}
openapi: 3.0.3
info:
  description: Flatpeak API
  version: 2025-09-14.anode
  title: Flatpeak API
  termsOfService: https://flatpeak.com/legal
  contact:
    name: Technical Support
    email: support@flatpeak.com
    url: https://flatpeak.com/contact
  license:
    name: Apache 2.0
    url: https://flatpeak.com/legal
servers:
  - url: https://api.flatpeak.com
    description: Location
security: []
tags:
  - name: Consumption
    description: Consumption operations
  - name: Customers
    description: Customer operations
  - name: Devices
    description: Device operations
  - name: Meters
    description: Meter readings operations
  - name: Events
    description: Events operations
  - name: Login
    description: Bearer auth token operations
  - name: Connect
    description: Connect operations
  - name: Locations
    description: Location operations
  - name: Rates
    description: Rates operations
  - name: Costs
    description: Consumption cost calculations
  - name: Schedules
    description: Consumption schedules
  - name: Tariffs
    description: Tariff operations
  - name: Slots
    description: Slots operations
externalDocs:
  description: Location documentation
  url: https://docs.flatpeak.com
paths:
  /schedules/duration/{id}:
    parameters:
      - schema:
          type: string
        name: id
        in: path
        required: true
        description: Flatpeak `location_id`.
    post:
      tags:
        - Schedules
      summary: Schedule by time duration
      description: >-
        Find the lowest or highest-cost time slots by specifying a required
        total duration.


        For example, to schedule 5 hours at the lowest price within a defined
        time window, Flatpeak will return the optimal periods. The schedule may
        be split into multiple segments to minimise cost.
      operationId: schedule-by-duration
      parameters: []
      requestBody:
        $ref: '#/components/requestBodies/ScheduleByDurationCreate'
      responses:
        '200':
          $ref: '#/components/responses/ScheduleByDuration'
        '403':
          $ref: '#/components/responses/403'
        '422':
          $ref: '#/components/responses/422'
        '429':
          $ref: '#/components/responses/429'
      security:
        - bearerAuth: []
components:
  requestBodies:
    ScheduleByDurationCreate:
      content:
        application/json:
          schema:
            type: object
            properties:
              start_time:
                type: string
                x-stoplight:
                  id: 1gm4iijsiuyod
                description: >-
                  RFC 3339 timestamp marking the start of the data window, e.g.
                  2023-06-15T09:00:00Z or 2023-06-15T08:00:00+01:00; use either
                  UTC or time offset—if offsets differ, end_time takes
                  precedence.
                example: '2023-06-15T09:00:00Z'
                format: date-time
              end_time:
                type: string
                x-stoplight:
                  id: 35waatybp9nrf
                description: >-
                  RFC 3339 timestamp marking the start of the data window, e.g.
                  2023-06-15T09:00:00Z or 2023-06-15T08:00:00+01:00; use either
                  UTC or time offset—if offsets differ, end_time takes
                  precedence. The maximum period between start_time and end_time
                  for a single request is 3 days.
                example: '2023-06-16T09:00:00Z'
                format: date-time
              direction:
                type: string
                x-stoplight:
                  id: 90r93ftrxgwth
                description: >-
                  Sets the tariff direction; possible values are `IMPORT`,
                  `EXPORT`, or `LOCAL`.
                example: IMPORT
                default: IMPORT
              segment:
                type: string
                x-stoplight:
                  id: wrpfe17cwo671
                description: >-
                  Set to `HIGH` to get the most expensive rate segment and to
                  `LOW` to get the cheapest segment.
                example: HIGH
              duration:
                type: number
                x-stoplight:
                  id: 8do56s6bnpfif
                description: >-
                  Amount of time in minutes you need with the lowest or highest
                  (set segment=HIGH/LOW) tariff over the requested period.
                example: 60
            required:
              - start_time
              - end_time
              - segment
              - duration
  responses:
    '403':
      description: 403 forbidden
      content:
        application/json:
          schema:
            type: object
            x-examples:
              Example:
                message: Bad credentials
            properties:
              object:
                type: string
                example: error
                x-stoplight:
                  id: gria4ysjd9zhk
                default: error
              type:
                type: string
                x-stoplight:
                  id: 7mhtfljidnqcu
                example: invalid_request
                default: invalid_request
              code:
                type: string
                x-stoplight:
                  id: sy7ljpdy5wdes
                example: access_denied
                default: access_denied
              time_created:
                type: string
                x-stoplight:
                  id: 84d5biv9dfbc9
                format: date-time
                example: '2025-01-01T00:00:00Z'
            required:
              - object
              - type
              - code
          examples: {}
    '422':
      description: 422 Data not available
      content:
        application/json:
          schema:
            type: object
            x-examples:
              Example:
                object: error
                type: api_error
                live_mode: false
                time_created: '2022-01-24T14:15:22.003'
                code: country_code_missing
                message: Country code is required
            properties:
              object:
                type: string
                x-stoplight:
                  id: 8tu6jw6w7a4ds
                default: error
                example: error
              type:
                type: string
                x-stoplight:
                  id: pi73vu0gm23xz
                example: invalid_request
                default: invalid_request
              context:
                type: string
                x-stoplight:
                  id: 86mrnnt9y68p9
                example: api.price_get
              code:
                type: string
                x-stoplight:
                  id: yvmrv5mczcj3f
                example: no_tariff_connected
              message:
                type: string
                x-stoplight:
                  id: n8zx3cn5xogky
                example: No tariff connected for IMPORT direction
              time_created:
                type: string
                x-stoplight:
                  id: wffseagefabdy
                format: date-time
                example: '2025-01-01T00:00:00Z'
            required:
              - object
              - type
              - context
              - code
              - message
              - time_created
    '429':
      description: 429 Too many requests
      content:
        application/json:
          schema:
            type: object
            properties:
              object:
                type: string
                x-stoplight:
                  id: irkmp11gg6sjx
                example: error
                default: error
              type:
                type: string
                x-stoplight:
                  id: u0gq12cizam3d
                default: rate_limit
                example: rate_limit
              code:
                type: string
                x-stoplight:
                  id: uh7x9404d4w3q
                default: too_many_requests
                example: too_many_requests
              message:
                type: string
                x-stoplight:
                  id: 9z8h79l1coblc
                default: Too many requests. Please retry after a short delay.
                example: Too many requests. Please retry after a short delay.
              time_created:
                type: string
                x-stoplight:
                  id: ea7o3uvdojrtc
                format: date-time
                default: '2026-01-29T17:11:52Z'
                example: '2026-01-29T17:11:52Z'
            required:
              - object
              - type
              - code
              - message
    ScheduleByDuration:
      description: Response example
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ScheduleDuration'
  schemas:
    ScheduleDuration:
      type: object
      x-stoplight:
        id: r894wd71k1f6u
      x-examples: {}
      x-tags:
        - Rates
      title: ScheduleDuration
      description: This object is a container for tariff slots response.
      properties:
        id:
          type: string
          description: Flatpeak unique object `id`.
          example: std_65e42cdd73e9f861edda35d7
        object:
          type: string
          description: |-

            Represents the object's type.
          example: schedule_duration
        live_mode:
          type: boolean
          description: >-
            Has the value `true` if the object exists in live mode or the value
            false if the object exists in test mode.
        location_id:
          type: string
          description: The unique Flatpeak ID of the location.
          x-stoplight:
            id: 0grw6kx1kien5
          example: loc_65e42ce4d3b813479b252160
        location_timezone:
          type: string
          description: >-
            The timezone at the location, in 'tz database format'. I.e.
            'Europe/Berlin'.
          x-stoplight:
            id: qew0bifiwrkx7
          example: Europe/London
        currency_code:
          type: string
          description: Currency at the location in ISO 4217.
          x-stoplight:
            id: aomadeld01p2u
          example: EUR
        direction:
          type: string
          description: Direction of tariff. Supported options are `IMPORT` and `EXPORT`.
          x-stoplight:
            id: nwrbo35d5kqyt
          example: IMPORT
        next_update:
          type: string
          description: >-
            Time when we recommend fetching new rates. In the format of the
            request, e.g. UTC or time-offset.
          example: '2023-06-18T23:00:00Z'
        request:
          type: object
          x-stoplight:
            id: ufwxiuviuite9
          description: Your original request.
          required:
            - direction
            - segment
            - duration
            - start_time
            - end_time
          properties:
            direction:
              type: string
              x-stoplight:
                id: j0dqv9394h193
              description: Tariff direction you requested.
              example: IMPORT
            segment:
              type: string
              x-stoplight:
                id: 580cbvdtc49k7
              example: LOW
              description: Indicates HIGH or LOW segment that was requested.
            duration:
              type: number
              x-stoplight:
                id: 7v6itfcq1y44r
              example: 60
              description: Indicates the amount of time in minutes that was requested.
            start_time:
              type: string
              x-stoplight:
                id: weunc52x0el1a
              example: '2022-05-24T14:15:22Z'
              description: >-
                Time when data will start. In the format of the request, e.g.
                UTC or time-offset.
            end_time:
              type: string
              x-stoplight:
                id: 1edb75l8i8e1y
              description: >-
                Time when data will end. In the format of the request, e.g. UTC
                or time-offset.
              example: '2022-05-24T16:15:22Z'
        data:
          type: array
          description: Slots response data.
          items:
            type: object
            x-stoplight:
              id: atpz6bpok2p95
            properties:
              start_time:
                type: string
                x-stoplight:
                  id: zgvxy5p88qlr1
                description: >-
                  Time when slot period begins, in timezone of the original
                  request.
                example: '2024-05-20T00:00:00Z'
              end_time:
                type: string
                x-stoplight:
                  id: qeowyba4oeg0n
                description: >-
                  Time when slot period ends, in timezone of the original
                  request.
                example: '2024-05-20T05:30:00Z'
              tariff:
                type: object
                x-stoplight:
                  id: 46fm9lyt6zgpx
                description: The price object
                required:
                  - rate_avg
                  - confidence
                properties:
                  rate_avg:
                    type: number
                    x-stoplight:
                      id: l3web5o7pqcys
                    description: The average price, in large currency units.
                    example: 3.221
                  confidence:
                    type: number
                    x-stoplight:
                      id: vfh0oev33t7tc
                    description: >-
                      Estimated confidence of data where '1' is 100% accurate
                      and 0.1 is 10% accurate.
                    example: 1
            required:
              - start_time
              - end_time
              - tariff
        time_created:
          type: string
          description: Time when this response was calculated. In UTC.
          format: date-time
          example: '2024-05-23T15:14:22Z'
        account_id:
          type: string
          x-stoplight:
            id: js64f97p2gpks
          example: acc_661677911f2197045e6cf1b1
          description: Flatpeak account ID.
      required:
        - id
        - object
        - live_mode
        - location_id
        - location_timezone
        - currency_code
        - direction
        - next_update
        - request
        - data
        - time_created
        - account_id
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >-
        Authenticate with `bearer` you obtained from
        [authentication](/api-reference/anode/authentication) endpoint.

````