{
  "openapi": "3.1.1",
  "info": {
    "title": "Price Per Everything API",
    "version": "1.0.0",
    "summary": "Compare products by price per gram, use, serving, hour or year of life.",
    "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://pricepereverything.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Compare products by price per gram, use, serving, hour or year of life.",
        "description": "Enter two or more products with their price and quantity (grams, uses, servings, hours or years). Price Per Everything normalises them to the same basis, accounts for waste, and ranks them from cheapest to most expensive per unit.\n\nMethodology:\n- Usable quantity = quantity × (1 − waste %).\n- Price per unit = price ÷ usable quantity, unrounded internally; displayed with 4 significant digits.\n- Products are ranked by price per unit; ties keep input order.",
        "tags": [
          "money"
        ],
        "x-mcp-tool": "price_per_everything",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PricePerEverythingInput"
              },
              "examples": {
                "example1": {
                  "summary": "Coffee: small vs. large bag",
                  "value": {
                    "basis": "unit",
                    "currency": "EUR",
                    "products": [
                      {
                        "name": "Coffee 250 g",
                        "price": 4.99,
                        "quantity": 250,
                        "unit": "g"
                      },
                      {
                        "name": "Coffee 1 kg",
                        "price": 15.49,
                        "quantity": 1000,
                        "unit": "g",
                        "wastePercent": 10
                      }
                    ]
                  }
                },
                "example2": {
                  "summary": "Shoes: cost per wear",
                  "value": {
                    "basis": "use",
                    "currency": "USD",
                    "products": [
                      {
                        "name": "Budget sneakers",
                        "price": 40,
                        "quantity": 120
                      },
                      {
                        "name": "Leather boots",
                        "price": 180,
                        "quantity": 900
                      }
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PricePerEverythingResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "PricePerEverythingInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "basis": {
            "title": "Compare by",
            "type": "string",
            "enum": [
              "unit",
              "use",
              "serving",
              "hour",
              "year"
            ],
            "default": "unit"
          },
          "currency": {
            "title": "Currency",
            "description": "Shown in results only; no conversion is performed.",
            "type": "string",
            "maxLength": 8,
            "default": "EUR"
          },
          "products": {
            "title": "Products",
            "description": "Quantity is in the chosen basis (e.g. 500 for 500 g, 30 for 30 uses). Waste % reduces the usable quantity.",
            "type": "array",
            "minItems": 2,
            "maxItems": 20,
            "items": {
              "type": "object",
              "additionalProperties": false,
              "properties": {
                "name": {
                  "title": "Product",
                  "type": "string"
                },
                "price": {
                  "title": "Price",
                  "type": "number",
                  "minimum": 0
                },
                "quantity": {
                  "title": "Quantity",
                  "type": "number",
                  "minimum": 0.000001
                },
                "unit": {
                  "title": "Unit label",
                  "type": "string"
                },
                "wastePercent": {
                  "title": "Waste %",
                  "type": "number",
                  "minimum": 0,
                  "maximum": 99,
                  "default": 0
                }
              },
              "required": [
                "name",
                "price",
                "quantity"
              ]
            }
          }
        },
        "required": [
          "products"
        ]
      },
      "PricePerEverythingResult": {
        "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": [
              "basis",
              "currency",
              "ranking",
              "cheapest",
              "savingsVsMostExpensivePercent"
            ],
            "properties": {
              "basis": {
                "type": "string"
              },
              "currency": {
                "type": "string"
              },
              "cheapest": {
                "type": "string"
              },
              "savingsVsMostExpensivePercent": {
                "type": "number"
              },
              "ranking": {
                "type": "array",
                "items": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": [
                    "rank",
                    "name",
                    "price",
                    "usableQuantity",
                    "pricePerUnit",
                    "unit",
                    "relativeToCheapest"
                  ],
                  "properties": {
                    "rank": {
                      "type": "integer"
                    },
                    "name": {
                      "type": "string"
                    },
                    "price": {
                      "type": "number"
                    },
                    "usableQuantity": {
                      "type": "number"
                    },
                    "pricePerUnit": {
                      "type": "number"
                    },
                    "unit": {
                      "type": "string"
                    },
                    "relativeToCheapest": {
                      "type": "number",
                      "description": "Price per unit divided by the cheapest price per unit."
                    }
                  }
                }
              }
            }
          },
          "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"
              }
            }
          }
        }
      }
    }
  }
}