{
  "openapi": "3.1.1",
  "info": {
    "title": "Ledgerly Rent vs Buy Calculator API",
    "version": "1.0.0",
    "summary": "Rent or buy? Break-even year, net worth over time, scenarios and a sensitivity table.",
    "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://ledgerlyrentvsbuy.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Rent or buy? Break-even year, net worth over time, scenarios and a sensitivity table.",
        "description": "Simulates buying and renting month by month: mortgage schedule, buying and selling costs, property tax, maintenance, insurance, rent increases and the return the renter earns by investing the down payment and every monthly difference. Shows the break-even year, net worth on both sides, home-price scenarios and a sensitivity table. Part of Ledgerly’s Reality Check.\n\nMethodology:\n- The mortgage is a monthly annuity built with the same schedule engine as the Loan Amortization Calculator (integer cents, interest rounded per month).\n- Buying needs the down payment plus buying costs in cash; the renter invests exactly that amount instead. Each month the side with the lower costs invests the difference, so both sides spend the same money.\n- Owner costs: mortgage payment, property tax and maintenance (percent of the home value at the start of each year), insurance and other fees (growing with the cost increase). Renter costs: rent (growing with the rent increase) and renter’s insurance.\n- Net worth in year N: buyer = home value − selling costs − tax on the sale gain − remaining mortgage + invested surplus after tax; renter = invested savings after tax on the gains. The break-even year is the first year buying is ahead; “not stable” means it falls behind again later.\n- Scenarios move the home price growth by ± the scenario step; the sensitivity table varies price growth (rows, ±2 steps) and the investment return (columns, ±2 percentage points).\n\nA model, not advice: house prices, rents and returns are uncertain, and local taxes and subsidies differ. Change the inputs to match your offer and check the sensitivity table before deciding.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "ledgerly_rent_vs_buy",
        "x-owner-app": "ledgerly",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LedgerlyRentVsBuyInput"
              },
              "examples": {
                "example1": {
                  "summary": "€380k flat vs €1,450 rent, 20 % down, 30 years",
                  "value": {
                    "currency": "EUR",
                    "homePrice": 380000,
                    "downPaymentPercent": 20,
                    "buyingCostsPercent": 10,
                    "mortgageRatePercent": 3.6,
                    "mortgageYears": 30,
                    "rentPerMonth": 1450,
                    "horizonYears": 30
                  }
                },
                "example2": {
                  "summary": "US house: $450k, 10 % down, property tax 1.1 %",
                  "value": {
                    "currency": "USD",
                    "homePrice": 450000,
                    "downPaymentPercent": 10,
                    "buyingCostsPercent": 3,
                    "mortgageRatePercent": 6.5,
                    "mortgageYears": 30,
                    "propertyTaxPercent": 1.1,
                    "maintenancePercent": 1,
                    "ownerInsurancePerYear": 1800,
                    "appreciationPercent": 3,
                    "sellingCostsPercent": 6,
                    "rentPerMonth": 2400,
                    "rentIncreasePercent": 3,
                    "investmentReturnPercent": 6,
                    "investmentTaxPercent": 15,
                    "horizonYears": 15
                  }
                },
                "example3": {
                  "summary": "Short stay: selling again after 5 years",
                  "value": {
                    "homePrice": 300000,
                    "downPaymentPercent": 25,
                    "buyingCostsPercent": 9,
                    "mortgageRatePercent": 3.8,
                    "rentPerMonth": 1100,
                    "horizonYears": 5
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LedgerlyRentVsBuyResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "LedgerlyRentVsBuyInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "currency": {
            "title": "Currency",
            "description": "ISO code used for the labels, e.g. EUR, USD, CHF.",
            "type": "string",
            "maxLength": 3,
            "default": "EUR"
          },
          "homePrice": {
            "title": "Purchase price of the home",
            "type": "number",
            "minimum": 1000,
            "maximum": 100000000,
            "default": 380000
          },
          "downPaymentPercent": {
            "title": "Down payment (% of the price)",
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "default": 20
          },
          "buyingCostsPercent": {
            "title": "Buying costs (% of the price)",
            "description": "Transfer tax, notary, land registry and agent fee, paid in cash on top of the down payment.",
            "type": "number",
            "minimum": 0,
            "maximum": 30,
            "default": 10
          },
          "mortgageRatePercent": {
            "title": "Mortgage interest rate (% per year)",
            "type": "number",
            "minimum": 0,
            "maximum": 25,
            "default": 3.6
          },
          "mortgageYears": {
            "title": "Mortgage term (years)",
            "type": "integer",
            "minimum": 1,
            "maximum": 40,
            "default": 30
          },
          "propertyTaxPercent": {
            "title": "Property tax (% of the home value per year)",
            "type": "number",
            "minimum": 0,
            "maximum": 5,
            "default": 0.3
          },
          "maintenancePercent": {
            "title": "Maintenance (% of the home value per year)",
            "type": "number",
            "minimum": 0,
            "maximum": 10,
            "default": 1
          },
          "ownerInsurancePerYear": {
            "title": "Home insurance per year",
            "type": "number",
            "minimum": 0,
            "maximum": 1000000,
            "default": 600
          },
          "ownerFeesPerMonth": {
            "title": "Other owner costs per month",
            "description": "For example service charges or a home-owners association fee that is not maintenance.",
            "type": "number",
            "minimum": 0,
            "maximum": 100000,
            "default": 0
          },
          "appreciationPercent": {
            "title": "Home price growth (% per year)",
            "type": "number",
            "minimum": -10,
            "maximum": 15,
            "default": 2
          },
          "sellingCostsPercent": {
            "title": "Selling costs at the end (% of the value)",
            "type": "number",
            "minimum": 0,
            "maximum": 20,
            "default": 6
          },
          "saleGainTaxPercent": {
            "title": "Tax on the gain when selling (%)",
            "description": "Often 0 for an owner-occupied home; enter your local rate if a gain is taxed.",
            "type": "number",
            "minimum": 0,
            "maximum": 70,
            "default": 0
          },
          "rentPerMonth": {
            "title": "Rent per month (comparable home)",
            "type": "number",
            "minimum": 0,
            "maximum": 1000000,
            "default": 1450
          },
          "rentIncreasePercent": {
            "title": "Rent increase (% per year)",
            "type": "number",
            "minimum": -10,
            "maximum": 20,
            "default": 2.5
          },
          "renterInsurancePerYear": {
            "title": "Renter’s insurance per year",
            "type": "number",
            "minimum": 0,
            "maximum": 100000,
            "default": 150
          },
          "costIncreasePercent": {
            "title": "Increase of insurance and fees (% per year)",
            "type": "number",
            "minimum": -10,
            "maximum": 20,
            "default": 2
          },
          "investmentReturnPercent": {
            "title": "Return on invested savings (% per year)",
            "description": "The opportunity cost: what the down payment and every monthly difference would earn if invested instead.",
            "type": "number",
            "minimum": -10,
            "maximum": 20,
            "default": 5
          },
          "investmentTaxPercent": {
            "title": "Tax on investment gains (%)",
            "type": "number",
            "minimum": 0,
            "maximum": 70,
            "default": 25
          },
          "horizonYears": {
            "title": "Years to compare",
            "type": "integer",
            "minimum": 1,
            "maximum": 40,
            "default": 30
          },
          "scenarioStepPercent": {
            "title": "Scenario step for home price growth (percentage points)",
            "type": "number",
            "minimum": 0.25,
            "maximum": 5,
            "default": 1
          }
        },
        "required": []
      },
      "LedgerlyRentVsBuyResult": {
        "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": [
              "currency",
              "horizonYears",
              "loanAmount",
              "monthlyPayment",
              "upfrontCash",
              "priceToRentRatio",
              "breakEvenYear",
              "staysAhead",
              "atHorizon",
              "firstYearMonthly",
              "totals",
              "scenarios",
              "sensitivity",
              "years"
            ],
            "properties": {
              "currency": {
                "type": "string"
              },
              "horizonYears": {
                "type": "integer"
              },
              "loanAmount": {
                "type": "number"
              },
              "monthlyPayment": {
                "type": "number"
              },
              "upfrontCash": {
                "type": "number"
              },
              "priceToRentRatio": {
                "type": [
                  "number",
                  "null"
                ]
              },
              "breakEvenYear": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "staysAhead": {
                "type": "boolean"
              },
              "atHorizon": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "buyerNetWorth",
                  "renterNetWorth",
                  "advantageOfBuying"
                ],
                "properties": {
                  "buyerNetWorth": {
                    "type": "number"
                  },
                  "renterNetWorth": {
                    "type": "number"
                  },
                  "advantageOfBuying": {
                    "type": "number"
                  }
                }
              },
              "firstYearMonthly": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "ownerCash",
                  "ownerUnrecoverable",
                  "renterCash"
                ],
                "properties": {
                  "ownerCash": {
                    "type": "number"
                  },
                  "ownerUnrecoverable": {
                    "type": "number"
                  },
                  "renterCash": {
                    "type": "number"
                  }
                }
              },
              "totals": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "interest",
                  "ownerCosts",
                  "renterCosts",
                  "saleCosts",
                  "saleTax"
                ],
                "properties": {
                  "interest": {
                    "type": "number"
                  },
                  "ownerCosts": {
                    "type": "number"
                  },
                  "renterCosts": {
                    "type": "number"
                  },
                  "saleCosts": {
                    "type": "number"
                  },
                  "saleTax": {
                    "type": "number"
                  }
                }
              },
              "scenarios": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "label",
                    "appreciationPercent",
                    "breakEvenYear",
                    "staysAhead",
                    "advantageAtHorizon"
                  ],
                  "properties": {
                    "label": {
                      "type": "string"
                    },
                    "appreciationPercent": {
                      "type": "number"
                    },
                    "breakEvenYear": {
                      "type": [
                        "integer",
                        "null"
                      ]
                    },
                    "staysAhead": {
                      "type": "boolean"
                    },
                    "advantageAtHorizon": {
                      "type": "number"
                    }
                  }
                }
              },
              "sensitivity": {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "appreciationPercent",
                  "investmentReturnPercent",
                  "breakEvenYear"
                ],
                "properties": {
                  "appreciationPercent": {
                    "type": "array",
                    "items": {
                      "type": "number"
                    }
                  },
                  "investmentReturnPercent": {
                    "type": "array",
                    "items": {
                      "type": "number"
                    }
                  },
                  "breakEvenYear": {
                    "type": "array",
                    "items": {
                      "type": "array",
                      "items": {
                        "type": [
                          "integer",
                          "null"
                        ]
                      }
                    }
                  }
                }
              },
              "years": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "year",
                    "homeValue",
                    "mortgageBalance",
                    "ownerCosts",
                    "interestPaid",
                    "renterCosts",
                    "buyerPortfolio",
                    "renterPortfolio",
                    "buyerNetWorth",
                    "renterNetWorth",
                    "advantage"
                  ],
                  "properties": {
                    "year": {
                      "type": "integer"
                    },
                    "homeValue": {
                      "type": "number"
                    },
                    "mortgageBalance": {
                      "type": "number"
                    },
                    "ownerCosts": {
                      "type": "number"
                    },
                    "interestPaid": {
                      "type": "number"
                    },
                    "renterCosts": {
                      "type": "number"
                    },
                    "buyerPortfolio": {
                      "type": "number"
                    },
                    "renterPortfolio": {
                      "type": "number"
                    },
                    "buyerNetWorth": {
                      "type": "number"
                    },
                    "renterNetWorth": {
                      "type": "number"
                    },
                    "advantage": {
                      "type": "number"
                    }
                  }
                }
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}