{
  "openapi": "3.1.1",
  "info": {
    "title": "Personal Price Memory API",
    "version": "1.0.0",
    "summary": "Compare your own purchases by unit price, package size and price history.",
    "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://ledgerlypricememory.usefulweb.app"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Compare your own purchases by unit price, package size and price history.",
        "description": "Track your own purchase history by product and currency, normalize units and compare pack changes, shops and unit-price trends.\n\nMethodology:\n- Products are grouped by trimmed case-insensitive name, compatible unit and three-letter currency code. Currency is never converted; older project rows without a code use EUR.\n- Same-date entries retain input order. History points represent entered purchases, not observations on unrecorded dates. The browser chart can switch product groups; the default API chart shows the first group. Dates use a true time axis; connecting lines are visual guides, not interpolated observations. These are personal reference prices, not a market-wide best price.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "ledgerly_price_memory",
        "x-owner-app": "ledgerly",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/LedgerlyPriceMemoryInput"
              },
              "examples": {
                "example1": {
                  "summary": "Try an example",
                  "value": {}
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/LedgerlyPriceMemoryResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "LedgerlyPriceMemoryInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "purchases": {
            "title": "Purchases",
            "type": "array",
            "minItems": 1,
            "maxItems": 500,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "product": {
                  "title": "Product",
                  "type": "string",
                  "maxLength": 100000
                },
                "shop": {
                  "title": "Shop",
                  "type": "string",
                  "maxLength": 100000
                },
                "day": {
                  "title": "Purchase date",
                  "type": "string",
                  "format": "date"
                },
                "quantity": {
                  "title": "Pack quantity",
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000
                },
                "unit": {
                  "title": "Unit",
                  "type": "string",
                  "enum": [
                    "g",
                    "kg",
                    "ml",
                    "l",
                    "item"
                  ]
                },
                "price": {
                  "title": "Price",
                  "type": "number",
                  "minimum": -1000000000,
                  "maximum": 1000000000
                },
                "currency": {
                  "title": "Currency",
                  "type": "string",
                  "maxLength": 3,
                  "default": "EUR"
                }
              },
              "required": [
                "product",
                "day",
                "quantity",
                "unit",
                "price"
              ]
            },
            "default": [
              {
                "product": "Coffee",
                "shop": "Shop A",
                "day": "2026-10-01",
                "quantity": 500,
                "unit": "g",
                "price": 6,
                "currency": "EUR"
              },
              {
                "product": "Coffee",
                "shop": "Shop B",
                "day": "2026-11-01",
                "quantity": 450,
                "unit": "g",
                "price": 6,
                "currency": "EUR"
              }
            ]
          }
        },
        "required": []
      },
      "LedgerlyPriceMemoryResult": {
        "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": [
              "purchases",
              "products",
              "history",
              "svg"
            ],
            "properties": {
              "purchases": {
                "type": "number"
              },
              "products": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "product",
                    "unit",
                    "currency",
                    "count",
                    "latest",
                    "lowest",
                    "highest",
                    "median",
                    "changePercent",
                    "packageChangePercent",
                    "lastDay",
                    "totalSpent",
                    "latestShop"
                  ],
                  "properties": {
                    "product": {
                      "type": "string"
                    },
                    "unit": {
                      "type": "string"
                    },
                    "currency": {
                      "type": "string"
                    },
                    "count": {
                      "type": "number"
                    },
                    "latest": {
                      "type": "number"
                    },
                    "lowest": {
                      "type": "number"
                    },
                    "highest": {
                      "type": "number"
                    },
                    "median": {
                      "type": "number"
                    },
                    "changePercent": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "packageChangePercent": {
                      "type": [
                        "number",
                        "null"
                      ]
                    },
                    "lastDay": {
                      "type": "string"
                    },
                    "totalSpent": {
                      "type": "number"
                    },
                    "latestShop": {
                      "type": "string"
                    }
                  }
                }
              },
              "history": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "index",
                    "product",
                    "shop",
                    "day",
                    "currency",
                    "unit",
                    "quantity",
                    "price",
                    "unitPrice"
                  ],
                  "properties": {
                    "index": {
                      "type": "number"
                    },
                    "product": {
                      "type": "string"
                    },
                    "shop": {
                      "type": "string"
                    },
                    "day": {
                      "type": "string"
                    },
                    "currency": {
                      "type": "string"
                    },
                    "unit": {
                      "type": "string"
                    },
                    "quantity": {
                      "type": "number"
                    },
                    "price": {
                      "type": "number"
                    },
                    "unitPrice": {
                      "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"
              }
            }
          }
        }
      }
    }
  }
}