{
  "openapi": "3.1.1",
  "info": {
    "title": "Favorlane Favour Balance API",
    "version": "1.0.0",
    "summary": "Who helped whom? Time-bank balances and the fewest favours that even them out.",
    "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://favorlanefavourbalance.usefulweb.site"
    }
  ],
  "paths": {
    "/api/v1/calculate": {
      "post": {
        "operationId": "calculate",
        "summary": "Who helped whom? Time-bank balances and the fewest favours that even them out.",
        "description": "Adds up a list of favours (who helped whom, in hours, points or simply favours) like a time bank: what each person gave and received, the balance between every pair, and the shortest list of favours to return so that everyone is even. Deterministic and exact to two decimals.\n\nMethodology:\n- Each line is one favour: the helper gave and the helped person received the amount (1 when none is given). Amounts are summed in hundredths, so results are exact to two decimals.\n- Balance = given − received. The balances always add up to zero: what some gave more, others received more.\n- To even out, the person who received most above what they gave returns favours to the person who gave most, repeatedly (largest first, ties by name). This needs at most one return favour fewer than there are people with an open balance.\n- Like a time bank, every hour counts the same no matter what kind of help it was.",
        "tags": [
          "apps"
        ],
        "x-mcp-tool": "favorlane_favour_balance",
        "x-owner-app": "favorlane",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FavorlaneFavourBalanceInput"
              },
              "examples": {
                "example1": {
                  "summary": "Neighbours swapping help",
                  "value": {
                    "exchanges": "Ana -\u003e Ben 2 (carried boxes)\nBen -\u003e Ana 1 (fixed the laptop)\nCleo -\u003e Ana 3 (babysitting)\nAna -\u003e Dev 1.5 (garden)\nDev -\u003e Cleo 1 (marmalade swap)",
                    "unit": "hours"
                  }
                },
                "example2": {
                  "summary": "Simple favour count",
                  "value": {
                    "exchanges": "Mia -\u003e Jon\nMia -\u003e Jon\nJon -\u003e Sam\nSam -\u003e Mia",
                    "unit": "favours"
                  }
                },
                "example3": {
                  "summary": "CSV from a spreadsheet",
                  "value": {
                    "exchanges": "from,to,amount\nKarin,Olaf,4\nOlaf,Pia,2\nPia,Karin,1\nPia,Olaf,2",
                    "unit": "points"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result envelope.",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/FavorlaneFavourBalanceResult"
                }
              }
            }
          },
          "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"
                }
              }
            }
          }
        }
      },
      "FavorlaneFavourBalanceInput": {
        "type": "object",
        "additionalProperties": false,
        "properties": {
          "exchanges": {
            "title": "Favours (one per line: helper -\u003e helped amount)",
            "description": "For example “Ana -\u003e Ben 2 (carried boxes)” = Ana helped Ben for 2 hours. Without an amount a line counts 1. CSV with from,to,amount works too.",
            "type": "string",
            "maxLength": 200000,
            "default": "Ana -\u003e Ben 2 (carried boxes)\nBen -\u003e Ana 1 (fixed the laptop)\nCleo -\u003e Ana 3 (babysitting)\nAna -\u003e Dev 1.5 (garden)\nDev -\u003e Cleo 1 (marmalade swap)"
          },
          "unit": {
            "title": "Amounts are",
            "type": "string",
            "enum": [
              "hours",
              "points",
              "favours"
            ],
            "default": "hours"
          }
        },
        "required": []
      },
      "FavorlaneFavourBalanceResult": {
        "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",
            "required": [
              "unit",
              "total",
              "people",
              "pairs",
              "settle"
            ],
            "properties": {
              "unit": {
                "enum": [
                  "hours",
                  "points",
                  "favours"
                ]
              },
              "total": {
                "type": "number"
              },
              "exchanges": {
                "type": "integer"
              },
              "people": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "name": {
                      "type": "string"
                    },
                    "given": {
                      "type": "number"
                    },
                    "received": {
                      "type": "number"
                    },
                    "net": {
                      "type": "number"
                    }
                  }
                }
              },
              "pairs": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "a": {
                      "type": "string"
                    },
                    "b": {
                      "type": "string"
                    },
                    "aToB": {
                      "type": "number"
                    },
                    "bToA": {
                      "type": "number"
                    },
                    "net": {
                      "type": "number"
                    }
                  }
                }
              },
              "settle": {
                "type": "array",
                "items": {
                  "type": "object",
                  "properties": {
                    "from": {
                      "type": "string"
                    },
                    "to": {
                      "type": "string"
                    },
                    "amount": {
                      "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"
              }
            }
          }
        }
      }
    }
  }
}