{
  "openapi": "3.1.0",
  "info": {
    "title": "Free Calculator public calculation API",
    "version": "1.0.0",
    "description": "Discover and run the published calculators on freecalculator.tech. Anonymous access, no API key required. Results are estimates for informational purposes and are not financial, medical or legal advice.",
    "license": {
      "name": "Free to use with attribution",
      "url": "https://freecalculator.tech/terms"
    }
  },
  "servers": [
    {
      "url": "https://freecalculator.tech"
    }
  ],
  "paths": {
    "/api/ai/tools": {
      "get": {
        "summary": "List published calculators available to AI systems",
        "operationId": "listTools",
        "responses": {
          "200": {
            "description": "Calculator catalogue",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ToolCatalogue"
                }
              }
            }
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    },
    "/api/ai/tools/{slug}": {
      "get": {
        "summary": "Describe one calculator, including its input and output schemas",
        "operationId": "getTool",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "mortgage-calculator"
          }
        ],
        "responses": {
          "200": {
            "description": "Calculator description",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Tool"
                }
              }
            }
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          }
        }
      }
    },
    "/api/tools/{slug}/calculate": {
      "post": {
        "summary": "Run a calculator and return a structured result",
        "operationId": "calculate",
        "parameters": [
          {
            "name": "slug",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "example": "mortgage-calculator"
          }
        ],
        "requestBody": {
          "required": true,
          "description": "An object whose keys are the calculator's input names, as published by GET /api/ai/tools/{slug}.",
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "additionalProperties": {
                  "type": [
                    "string",
                    "number",
                    "boolean"
                  ]
                }
              },
              "example": {
                "amount": 400000,
                "rate": 6.5,
                "years": 30
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Calculation result",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/Calculation"
                }
              }
            }
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "404": {
            "$ref": "#/components/responses/NotFound"
          },
          "413": {
            "$ref": "#/components/responses/TooLarge"
          },
          "429": {
            "$ref": "#/components/responses/RateLimited"
          },
          "503": {
            "$ref": "#/components/responses/Unavailable"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Error": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "field": {
                "type": "string"
              },
              "message": {
                "type": "string"
              }
            },
            "required": [
              "code",
              "message"
            ]
          }
        },
        "required": [
          "error"
        ]
      },
      "Input": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "label": {
            "type": "string"
          },
          "type": {
            "type": "string",
            "enum": [
              "number",
              "string",
              "boolean"
            ]
          },
          "required": {
            "type": "boolean"
          },
          "unit": {
            "type": "string"
          },
          "minimum": {
            "type": "number"
          },
          "maximum": {
            "type": "number"
          },
          "options": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "default": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "label",
          "type",
          "required"
        ]
      },
      "Tool": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          },
          "slug": {
            "type": "string"
          },
          "category": {
            "type": "string"
          },
          "description": {
            "type": "string"
          },
          "purpose": {
            "type": "string"
          },
          "url": {
            "type": "string",
            "format": "uri"
          },
          "calculate_endpoint": {
            "type": "string"
          },
          "inputs": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Input"
            }
          },
          "outputs": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "input_schema": {
            "type": "object"
          },
          "output_schema": {
            "type": "object"
          },
          "formula": {
            "type": [
              "string",
              "null"
            ]
          },
          "methodology": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "assumptions": {
            "type": [
              "string",
              "null"
            ]
          },
          "faqs": {
            "type": "array",
            "items": {
              "type": "object"
            }
          },
          "related_tools": {
            "type": "array",
            "items": {
              "type": "string"
            }
          },
          "tool_version": {
            "type": "string"
          },
          "updated_at": {
            "type": [
              "string",
              "null"
            ]
          },
          "disclaimer": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "slug",
          "url",
          "inputs"
        ]
      },
      "ToolCatalogue": {
        "type": "object",
        "properties": {
          "site": {
            "type": "string"
          },
          "generated_at": {
            "type": "string",
            "format": "date-time"
          },
          "count": {
            "type": "integer"
          },
          "tools": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Tool"
            }
          }
        },
        "required": [
          "tools"
        ]
      },
      "Calculation": {
        "type": "object",
        "properties": {
          "tool": {
            "type": "string"
          },
          "tool_slug": {
            "type": "string"
          },
          "tool_version": {
            "type": "string"
          },
          "calculation_timestamp": {
            "type": "string",
            "format": "date-time"
          },
          "result": {
            "type": "object",
            "additionalProperties": {
              "type": "string"
            }
          },
          "primary": {
            "type": "object"
          },
          "calculation": {
            "type": "object"
          },
          "disclaimer": {
            "type": "string"
          },
          "source_url": {
            "type": "string",
            "format": "uri"
          },
          "attribution": {
            "type": "string"
          }
        },
        "required": [
          "tool",
          "result",
          "source_url"
        ]
      }
    },
    "responses": {
      "BadRequest": {
        "description": "Invalid input",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "NotFound": {
        "description": "Calculator not found or not available to AI systems",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "TooLarge": {
        "description": "Request body too large",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "RateLimited": {
        "description": "Rate limit exceeded",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      },
      "Unavailable": {
        "description": "Service temporarily switched off",
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Error"
            }
          }
        }
      }
    }
  }
}