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

# Optimize by price limit

> Returns the intervals within the window whose price is below or above the threshold. Each window carries the solar forecast for its interval.



## OpenAPI

````yaml energy-api/reference/flatpeak-api-spec-energy-tariffs.json POST /devices/{device_id}/optimizations/limit
openapi: 3.0.3
info:
  description: >-
    The tariff functions of the Flatpeak Energy API: tariff connection, prices,
    forecasts and costs. Generated from the full Energy API spec by
    scripts/build-tariff-spec.py. Do not edit.
  version: 2027-01-01.busbar
  title: 'Flatpeak Energy API: Tariffs'
  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://energy-api.flatpeak.com
security:
  - bearerAuth: []
tags:
  - name: Authentication
    description: >-
      Exchange your account credentials for a bearer token to authenticate API
      requests.
  - name: Connect
    description: >-
      Create and retrieve Connect sessions. Connect drives the user journeys for
      tariff connection and [tariff error
      reporting](/energy-api/reference/connect/tariff/error-report). What
      happens in those journeys reaches your backend as [Connect
      webhooks](/energy-api/guides/platform/events).
  - name: Users
    description: Create, retrieve, update, delete, and list users.
  - name: Locations
    description: Create, retrieve, update, delete, and list locations.
  - name: Devices
    description: >-
      Create, retrieve, update, delete and list devices; submit and retrieve
      their state; read and write their shared settings.
  - name: Meters
    description: Submit meter records and check batch status.
  - name: Tariffs
    description: Create, retrieve, delete, and list tariffs.
  - name: Prices
    description: Retrieve and audit calculated energy prices.
  - name: Costs
    description: Calculate the monetary cost of imported or exported energy.
  - name: Optimizations
    description: >-
      Rank the connected tariff to find the best times to consume or export
      energy, as inputs to your own scheduling.
  - name: Events
    description: Retrieve and list account events.
externalDocs:
  description: Documentation
  url: https://docs.flatpeak.com
paths:
  /devices/{device_id}/optimizations/limit:
    parameters:
      - name: device_id
        in: path
        required: true
        schema:
          type: string
          example: dev_63a6087272941ef077a8fd3e
        description: Flatpeak Device ID.
    post:
      tags:
        - Optimizations
      summary: Optimize by price limit
      description: >-
        Returns the intervals within the window whose price is below or above
        the threshold. Each window carries the solar forecast for its interval.
      operationId: optimize-by-limit
      parameters: []
      requestBody:
        $ref: '#/components/requestBodies/OptimizeByLimitCreate'
      responses:
        '200':
          $ref: '#/components/responses/OptimizeByLimit'
        '400':
          $ref: '#/components/responses/400'
        '401':
          $ref: '#/components/responses/401'
        '403':
          $ref: '#/components/responses/403'
        '404':
          $ref: '#/components/responses/404'
        '422':
          $ref: '#/components/responses/422'
        '429':
          $ref: '#/components/responses/429'
        '500':
          $ref: '#/components/responses/500'
        '503':
          $ref: '#/components/responses/503'
components:
  requestBodies:
    OptimizeByLimitCreate:
      content:
        application/json:
          schema:
            type: object
            additionalProperties: false
            properties:
              start_time:
                type: string
                description: >-
                  RFC 3339 timestamp marking the start of the data window, for
                  example 2026-06-15T09:00:00Z or 2026-06-15T08:00:00+01:00. Use
                  either UTC or a time offset. If offsets differ, end_time takes
                  precedence.
                example: '2026-06-15T09:00:00Z'
                format: date-time
              end_time:
                type: string
                description: >-
                  RFC 3339 end of the window, for example
                  `2026-06-15T13:00:00Z`. At most 3 days after `start_time`.
                example: '2026-06-16T09:00:00Z'
                format: date-time
              import:
                type: object
                description: Import optimization request.
                properties:
                  segment:
                    type: string
                    description: >-
                      `HIGH` returns the most expensive segment, `LOW` the
                      cheapest.
                    enum:
                      - HIGH
                      - LOW
                    example: HIGH
                  threshold_type:
                    type: string
                    example: RELATIVE
                    description: >-
                      Threshold type: `RELATIVE` for a value between 0.01
                      (lowest tariff) and 1 (highest tariff), `ABSOLUTE` for a
                      price in large currency units.
                    enum:
                      - ABSOLUTE
                      - RELATIVE
                  threshold:
                    type: number
                    example: 0.25
                    description: >-
                      Threshold value. `RELATIVE`: between 0.01 (lowest tariff)
                      and 1 (highest tariff). `ABSOLUTE`: a price in large
                      currency units.
                required:
                  - threshold_type
                  - threshold
              export:
                type: object
                description: Export optimization request.
                properties:
                  segment:
                    type: string
                    description: >-
                      `HIGH` returns the most expensive segment, `LOW` the
                      cheapest.
                    example: LOW
                  threshold_type:
                    type: string
                    example: RELATIVE
                    description: >-
                      Threshold type: `RELATIVE` for a value between 0.01
                      (lowest tariff) and 1 (highest tariff), `ABSOLUTE` for a
                      price in large currency units.
                    enum:
                      - ABSOLUTE
                      - RELATIVE
                  threshold:
                    type: number
                    example: 0.8
                    description: >-
                      Threshold value. `RELATIVE`: between 0.01 (lowest tariff)
                      and 1 (highest tariff). `ABSOLUTE`: a price in large
                      currency units.
                required:
                  - threshold_type
                  - threshold
            required:
              - start_time
              - end_time
      required: true
  responses:
    '400':
      description: >-
        400 Bad Request: the request was malformed or a required field is
        missing or invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    '401':
      description: '401 Unauthorized: authentication credentials are missing or invalid.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    '403':
      description: '403 Forbidden: you do not have permission to access this resource.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    '404':
      description: '404 Not Found: the requested resource does not exist.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    '422':
      description: >-
        422 Unprocessable Entity: the request is well-formed but cannot be
        processed, for example missing required data.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    '429':
      description: '429 Too Many Requests: the rate limit has been exceeded.'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    '500':
      description: >-
        500 Internal Server Error: an unexpected error occurred. Safe to retry
        with backoff.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    '503':
      description: >-
        503 Service Unavailable: the service is temporarily down for
        maintenance. Retry after the indicated delay.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    OptimizeByLimit:
      description: Optimization by limit response.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/OptimizationLimit'
  schemas:
    OptimizationLimit:
      type: object
      title: OptimizationLimit
      description: Tariff rate segments.
      properties:
        id:
          type: string
          description: Flatpeak Optimization ID.
          example: opt_65e42cdd73e9f861edda35d7
        object:
          type: string
          description: Object type.
          example: optimization_limit
          enum:
            - optimization_limit
        live_mode:
          type: boolean
          description: '`true` for live data, `false` for test data.'
        device_id:
          type: string
          description: Flatpeak Device ID.
          example: dev_63a6087272941ef077a8fd3e
        location_id:
          type: string
          description: Flatpeak Location ID.
          example: loc_65e42ce4d3b813479b252160
        timezone:
          type: string
          description: Timezone at the location, tz database name such as `Europe/Berlin`.
          example: Europe/London
        currency_code:
          type: string
          description: Currency at the location in ISO 4217.
          example: EUR
          pattern: ^[A-Z]{3}$
        data:
          type: array
          items:
            $ref: '#/components/schemas/PriceWindow'
          description: The price windows of the optimization, in time order.
        account_id:
          type: string
          example: acc_661677911f2197045e6cf1b1
          description: Flatpeak Account ID.
        time_created:
          type: string
          description: Time when this response was calculated. In UTC.
          format: date-time
          example: '2026-05-24T15:15:22Z'
      required:
        - id
        - object
        - live_mode
        - device_id
        - location_id
        - timezone
        - currency_code
        - data
        - account_id
        - time_created
    Error:
      type: object
      description: Standard error envelope returned by every non-2xx response.
      required:
        - object
        - type
        - code
        - message
      properties:
        object:
          type: string
          enum:
            - error
          default: error
          description: Object type.
        type:
          type: string
          description: High-level error category.
          example: invalid_request
        code:
          type: string
          description: Machine-readable error code, safe to branch on.
          example: not_found
        message:
          type: string
          description: Human-readable description of the error.
          example: The requested resource could not be found.
        context:
          type: string
          description: Optional originating context, for example `api.price_get`.
          example: api.price_get
        live_mode:
          type: boolean
          description: Whether the error occurred against live or test data.
        time_created:
          type: string
          format: date-time
          description: Time the error was generated (RFC 3339).
          example: '2026-01-01T00:00:00Z'
    PriceWindow:
      type: object
      title: PriceWindow
      properties:
        start_time:
          type: string
          description: Segment start.
          example: '2026-05-20T00:00:00Z'
          format: date-time
        end_time:
          type: string
          description: Segment end.
          example: '2026-05-20T05:30:00Z'
          format: date-time
        price:
          type: object
          description: >-
            Average energy price for the window: the tariff price at which
            energy settles during it.
          properties:
            value:
              type: number
              description: >-
                The average price per kWh, in the location's currency (large
                units, for example 0.31 for 31 pence).
              example: 0.032
            confidence:
              type: number
              description: >-
                Estimated confidence of the data: `1` is 100% accurate, `0.1` is
                10%.
              example: 1
        solar:
          type: object
          nullable: true
          description: >-
            Solar forecast for the window. `null` when the device has no PV
            block or forecasts are off.
          properties:
            energy_kwh:
              type: number
              example: 1.41
              description: Forecast generation over the interval, in kWh.
            power_kw:
              type: number
              example: 2.82
              description: Average forecast generation over the interval, in kW.
            confidence:
              type: number
              minimum: 0
              maximum: 1
              example: 0.66
              description: Confidence of the forecast, `1` is certain.
      required:
        - start_time
        - end_time
        - price
        - solar
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token obtained from POST /auth/tokens.

````

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