{
  "openapi": "3.1.0",
  "info": {
    "title": "MMM TradeCost + HS Code Helper API",
    "version": "2.0.0",
    "description": "Deterministic landed-cost calculations and AI-assisted preliminary HS6 suggestions."
  },
  "servers": [
    {
      "url": "https://mmm-engine-v2.opportunity-hunter.workers.dev"
    }
  ],
  "paths": {
    "/api/tradecost": {
      "post": {
        "operationId": "calculateLandedCost",
        "summary": "Calculate landed cost from user-supplied rates",
        "description": "Costs $0.005 USDC on Base per call. Deterministic arithmetic; not live tariff data.",
        "tags": [
          "trade",
          "finance",
          "calculator"
        ],
        "x-x402-price-usd": "0.005",
        "x-x402-network": "eip155:8453",
        "x-x402-asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
        "x-x402-pay-to": "0xeFD11F24cF9ec329c7345C3a3352f68d5c021C99",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "itemCost",
                  "dutyRatePct"
                ],
                "properties": {
                  "itemCost": {
                    "type": "number",
                    "minimum": 0
                  },
                  "shippingCost": {
                    "type": "number",
                    "minimum": 0,
                    "default": 0
                  },
                  "insuranceCost": {
                    "type": "number",
                    "minimum": 0,
                    "default": 0
                  },
                  "dutyRatePct": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 100
                  },
                  "vatRatePct": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 100,
                    "default": 0
                  },
                  "otherCosts": {
                    "type": "number",
                    "minimum": 0,
                    "default": 0
                  },
                  "quantity": {
                    "type": "integer",
                    "minimum": 1,
                    "default": 1
                  },
                  "targetMarginPct": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 99.99,
                    "default": 0
                  },
                  "currency": {
                    "type": "string",
                    "default": "USD"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result returned only after confirmed USDC settlement."
          },
          "402": {
            "description": "Payment required."
          },
          "422": {
            "description": "Invalid input rejected before payment."
          },
          "502": {
            "description": "Payment settlement not confirmed."
          },
          "503": {
            "description": "AI or payment verification unavailable; no result served."
          }
        }
      }
    },
    "/api/hs-code": {
      "post": {
        "operationId": "suggestHs6Classification",
        "summary": "Suggest a preliminary six-digit HS code",
        "description": "Costs $0.01 USDC on Base per call. AI-generated suggestion only; verify with official customs authority.",
        "tags": [
          "trade",
          "hs-code",
          "tariff-classification"
        ],
        "x-x402-price-usd": "0.01",
        "x-x402-network": "eip155:8453",
        "x-x402-asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
        "x-x402-pay-to": "0xeFD11F24cF9ec329c7345C3a3352f68d5c021C99",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "productDescription"
                ],
                "properties": {
                  "productDescription": {
                    "type": "string",
                    "minLength": 4,
                    "maxLength": 600
                  },
                  "countryOfImport": {
                    "type": "string",
                    "maxLength": 80
                  },
                  "material": {
                    "type": "string",
                    "maxLength": 200
                  },
                  "intendedUse": {
                    "type": "string",
                    "maxLength": 200
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Result returned only after confirmed USDC settlement."
          },
          "402": {
            "description": "Payment required."
          },
          "422": {
            "description": "Invalid input rejected before payment."
          },
          "502": {
            "description": "Payment settlement not confirmed."
          },
          "503": {
            "description": "AI or payment verification unavailable; no result served."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "TradeCostInput": {
        "type": "object",
        "required": [
          "itemCost",
          "dutyRatePct"
        ],
        "properties": {
          "itemCost": {
            "type": "number",
            "minimum": 0
          },
          "shippingCost": {
            "type": "number",
            "minimum": 0,
            "default": 0
          },
          "insuranceCost": {
            "type": "number",
            "minimum": 0,
            "default": 0
          },
          "dutyRatePct": {
            "type": "number",
            "minimum": 0,
            "maximum": 100
          },
          "vatRatePct": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "default": 0
          },
          "otherCosts": {
            "type": "number",
            "minimum": 0,
            "default": 0
          },
          "quantity": {
            "type": "integer",
            "minimum": 1,
            "default": 1
          },
          "targetMarginPct": {
            "type": "number",
            "minimum": 0,
            "maximum": 99.99,
            "default": 0
          },
          "currency": {
            "type": "string",
            "default": "USD"
          }
        }
      },
      "HsCodeInput": {
        "type": "object",
        "required": [
          "productDescription"
        ],
        "properties": {
          "productDescription": {
            "type": "string",
            "minLength": 4,
            "maxLength": 600
          },
          "countryOfImport": {
            "type": "string",
            "maxLength": 80
          },
          "material": {
            "type": "string",
            "maxLength": 200
          },
          "intendedUse": {
            "type": "string",
            "maxLength": 200
          }
        }
      }
    }
  }
}