{
  "openapi": "3.1.0",
  "info": {
    "title": "CalcWorkBench Engineering, Trade & Financial Calculator API",
    "version": "1.0.0",
    "description": "High-precision, deterministic engineering and personal finance calculation API across 7 tools: 6 electrical engineering tools verified by Licensed Professional Engineers (Feeder Circuit Design, Ampacity & Voltage Drop, Conduit Fill, Box Fill, Ohm's Law, and CT Saturation ODE simulation) plus the Personal Finance Loan Payoff & Amortization Engine (Single Loan, Multi-Debt Avalanche/Snowball/Custom, and Debt-vs-Investment Comparator).",
    "contact": {
      "name": "CalcWorkBench Engineering & Standards Team",
      "url": "https://calcworkbench.com/ai-agent-access.html"
    }
  },
  "servers": [
    {
      "url": "https://calcworkbench.com/api/v1",
      "description": "Production Cloudflare Pages Edge"
    }
  ],
  "paths": {
    "/calculate": {
      "post": {
        "summary": "Execute Deterministic Engineering or Financial Calculation",
        "operationId": "executeCalculation",
        "description": "Executes one of the 7 deterministic tools (6 engineering + 1 personal finance). Requires Bearer API key or HTTP 402 payment.",
        "security": [
          { "BearerAuth": [] },
          { "MppPayment": [] }
        ],
        "parameters": [
          {
            "name": "tool",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "design_electrical_circuit",
                "calculate_wire_ampacity_voltage_drop",
                "calculate_conduit_cable_fill",
                "calculate_electrical_box_fill",
                "calculate_ohms_law_and_circuits",
                "simulate_ct_saturation",
                "calculate_loan_payoff"
              ],
              "default": "design_electrical_circuit"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "tool": { "type": "string" },
                  "inputs": { "type": "object" },
                  "include_submittal": { "type": "boolean", "default": false }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Successful calculation with 3-layer deliverable (JSON, Markdown report, HTML summary/submittal sheet).",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": { "type": "string" },
                    "tool": { "type": "string" },
                    "result": { "type": "object" },
                    "report_markdown": { "type": "string" },
                    "submittal_html": { "type": "string" },
                    "engineeringVerification": { "type": "object" },
                    "verification": { "type": "object" }
                  }
                }
              }
            }
          },
          "402": {
            "description": "Payment Required. Unauthenticated agent or insufficient credits."
          }
        }
      }
    },
    "/account": {
      "get": {
        "summary": "Check API Key Status & Remaining Credits",
        "operationId": "checkAccountStatus",
        "security": [{ "BearerAuth": [] }],
        "responses": {
          "200": { "description": "Key status and credit balance." }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Prepaid or Pro Subscription API key purchased at https://calcworkbench.com/ai-agent-access.html"
      },
      "MppPayment": {
        "type": "http",
        "scheme": "payment",
        "description": "Stripe Machine Payments Protocol (MPP) Shared Payment Token"
      }
    }
  }
}

