{
  "openapi": "3.1.1",
  "info": {
    "title": "Energy Time Planner API",
    "version": "1.0.0",
    "summary": "Schedule flexible appliances against 24 hourly prices and a parallel-device limit.",
    "description": "Every endpoint performs the same calculation as the human page and returns inputs, result, units, assumptions, sources, warnings and computedAt. MCP endpoint: /mcp."
  },
  "servers": [
    {
      "url": "https://ledgerlyenergyschedule.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Schedule flexible appliances against 24 hourly prices and a parallel-device limit.",
        "description": "Schedule appliances against hourly or quarter-hourly prices, with deadlines, parallel-device and modeled power constraints plus a baseline comparison.\n\nMethodology:\n- 24 hourly or 96 quarter-hourly fixed slots. Device times align with the price interval; uninterrupted constant-power jobs, up to six appliances, negative prices supported.\n- The power constraint uses average kWh/duration, not transient starting currents. The baseline places appliances in input order at the earliest feasible time; it is not a measured bill.\n- Branch-and-bound stops after 200,000 nodes and reports whether optimality was proven. This planner does not control appliances or assess an electrical installation.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "ledgerly_energy_schedule",
        "x-owner-app": "ledgerly",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LedgerlyEnergyScheduleInput"
              },
              "examples": {
                "example1": {
                  "summary": "Try an example",
                  "value": {}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LedgerlyEnergyScheduleResult"
                }
              }
            }
          },
          "400": {
            "description": "Malformed JSON body.",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "422": {
            "description": "Invalid input (see errors[]).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          },
          "429": {
            "description": "Rate limit exceeded (see Retry-After).",
            "content": {
              "application/problem+json": {
                "schema": {
                  "$ref": "#/components/schemas/Problem"
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/tool": {
      "get": {
        "operationId": "getToolDefinition",
        "summary": "Inputs, output schema and examples for this tool",
        "responses": {
          "200": {
            "description": "Tool definition.",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Problem": {
        "type": "object",
        "description": "RFC 9457 problem details. 422 responses include per-field `errors`.",
        "required": [
          "type",
          "title",
          "status",
          "detail"
        ],
        "properties": {
          "type": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "status": {
            "type": "integer"
          },
          "detail": {
            "type": "string"
          },
          "code": {
            "type": "string"
          },
          "errors": {
            "type": "array",
            "items": {
              "type": "object",
              "required": [
                "field",
                "message"
              ],
              "properties": {
                "field": {
                  "type": "string"
                },
                "message": {
                  "type": "string"
                }
              }
            }
          }
        }
      },
      "LedgerlyEnergyScheduleInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "prices": {
            "title": "24 hourly or 96 quarter-hourly prices per kWh",
            "type": "string",
            "maxLength": 3000,
            "default": "0.15, 0.15, 0.15, 0.15, 0.15, 0.15, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35"
          },
          "parallel": {
            "title": "Maximum appliances at once",
            "type": "number",
            "minimum": 1,
            "maximum": 6,
            "default": 1
          },
          "maxKw": {
            "title": "Maximum modeled power (kW, 0 = no limit)",
            "type": "number",
            "minimum": 0,
            "maximum": 1000,
            "default": 0
          },
          "devices": {
            "title": "Appliances",
            "type": "array",
            "minItems": 1,
            "maxItems": 6,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "name": {
                  "title": "Appliance",
                  "type": "string",
                  "maxLength": 100000
                },
                "earliest": {
                  "title": "Earliest start hour",
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000
                },
                "deadline": {
                  "title": "Finish by hour",
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000
                },
                "duration": {
                  "title": "Running hours",
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000
                },
                "kwh": {
                  "title": "Total kWh",
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000
                }
              },
              "required": [
                "name",
                "earliest",
                "deadline",
                "duration",
                "kwh"
              ]
            },
            "default": [
              {
                "name": "Washer",
                "earliest": 0,
                "deadline": 8,
                "duration": 2,
                "kwh": 1
              },
              {
                "name": "Dishwasher",
                "earliest": 0,
                "deadline": 8,
                "duration": 3,
                "kwh": 1.5
              }
            ]
          }
        },
        "required": []
      },
      "LedgerlyEnergyScheduleResult": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "schemaVersion",
          "tool",
          "computedAt",
          "inputs",
          "summary",
          "result",
          "units",
          "assumptions",
          "sources",
          "warnings",
          "presentation",
          "links"
        ],
        "properties": {
          "schemaVersion": {
            "type": "string",
            "const": "1.0"
          },
          "tool": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "id",
              "name",
              "version"
            ],
            "properties": {
              "id": {
                "type": "string"
              },
              "name": {
                "type": "string"
              },
              "version": {
                "type": "string"
              }
            }
          },
          "computedAt": {
            "type": "string",
            "format": "date-time"
          },
          "inputs": {
            "type": "object",
            "description": "Normalised inputs actually used, including applied defaults."
          },
          "summary": {
            "type": "string"
          },
          "result": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "schedule",
              "cost",
              "optimal",
              "searchNodes",
              "intervalMinutes",
              "baselineCost",
              "savings",
              "peakKw",
              "hourly",
              "svg"
            ],
            "properties": {
              "schedule": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "name",
                    "start",
                    "end",
                    "cost",
                    "kwh",
                    "kw"
                  ],
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "start": {
                      "type": "number"
                    },
                    "end": {
                      "type": "number"
                    },
                    "cost": {
                      "type": "number"
                    },
                    "kwh": {
                      "type": "number"
                    },
                    "kw": {
                      "type": "number"
                    }
                  }
                }
              },
              "cost": {
                "type": "number"
              },
              "optimal": {
                "type": "boolean"
              },
              "searchNodes": {
                "type": "number"
              },
              "intervalMinutes": {
                "type": "number"
              },
              "baselineCost": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "savings": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "peakKw": {
                "type": "number"
              },
              "hourly": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "hour",
                    "price",
                    "kw"
                  ],
                  "properties": {
                    "hour": {
                      "type": "number"
                    },
                    "price": {
                      "type": "number"
                    },
                    "kw": {
                      "type": "number"
                    }
                  }
                }
              },
              "svg": {
                "type": "string"
              }
            }
          },
          "units": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "sources": {
            "type": "array",
            "items": {
              "type": "object",
              "additionalProperties": false,
              "required": [
                "title"
              ],
              "properties": {
                "title": {
                  "type": "string"
                },
                "url": {
                  "type": "string"
                },
                "publisher": {
                  "type": "string"
                },
                "retrievedAt": {
                  "type": "string"
                },
                "note": {
                  "type": "string"
                }
              }
            }
          },
          "warnings": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "presentation": {
            "type": "array",
            "items": {
              "type": "object"
            },
            "description": "Display blocks used by the human page (same data)."
          },
          "links": {
            "type": "object",
            "additionalProperties": false,
            "required": [
              "human",
              "api",
              "openapi",
              "methodology"
            ],
            "properties": {
              "human": {
                "type": "string",
                "format": "uri"
              },
              "api": {
                "type": "string",
                "format": "uri"
              },
              "openapi": {
                "type": "string",
                "format": "uri"
              },
              "methodology": {
                "type": "string",
                "format": "uri"
              }
            }
          }
        }
      }
    }
  }
}