{
  "openapi": "3.0.1",
  "info": {
    "title": "SBA Loan Portfolio Explorer API — 7(a) & 504 Rollups",
    "description": "SBA loan data API over the 7(a) and 504 FOIA loan-level files. Look up loans by state, NAICS industry, lender, fiscal year and amount; roll up by lender / industry / geography; and flag risk outliers (amount-per-job, charge-offs, lender concentration). Keyless.",
    "version": "1.0",
    "x-build-id": "EnkhoMAeRgwdVOEq7"
  },
  "servers": [
    {
      "url": "https://api.apify.com/v2"
    }
  ],
  "paths": {
    "/acts/malonestar~sba-loan-portfolio-explorer/run-sync-get-dataset-items": {
      "post": {
        "operationId": "run-sync-get-dataset-items-malonestar-sba-loan-portfolio-explorer",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for its completion, and returns Actor's dataset items in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/acts/malonestar~sba-loan-portfolio-explorer/runs": {
      "post": {
        "operationId": "runs-sync-malonestar-sba-loan-portfolio-explorer",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor and returns information about the initiated run in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/runsResponseSchema"
                }
              }
            }
          }
        }
      }
    },
    "/acts/malonestar~sba-loan-portfolio-explorer/run-sync": {
      "post": {
        "operationId": "run-sync-malonestar-sba-loan-portfolio-explorer",
        "x-openai-isConsequential": false,
        "summary": "Executes an Actor, waits for completion, and returns the OUTPUT from Key-value store in response.",
        "tags": [
          "Run Actor"
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/inputSchema"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Enter your Apify token here"
          }
        ],
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "inputSchema": {
        "type": "object",
        "properties": {
          "program": {
            "title": "Loan program",
            "enum": [
              "all",
              "7a",
              "504"
            ],
            "type": "string",
            "description": "Which SBA loan program to query: '7a' (7(a) guaranteed loans), '504' (504/CDC loans), or 'all' for both. PPP is not included in v1 (PPP ships only as a multi-GB bulk file).",
            "default": "all"
          },
          "fiscalYear": {
            "title": "Approval fiscal year",
            "minimum": 1990,
            "maximum": 2100,
            "type": "integer",
            "description": "Restrict to loans approved in this SBA fiscal year (Oct 1-Sep 30). Also routes the query to only the FOIA file that covers this year. Leave empty for all years the selected files cover."
          },
          "state": {
            "title": "State (2-letter)",
            "type": "string",
            "description": "Filter to loans whose borrower OR project state equals this 2-letter code, e.g. 'CA', 'TX'. Empty = all states."
          },
          "naicsPrefix": {
            "title": "NAICS industry prefix",
            "type": "string",
            "description": "Keep only loans whose NAICS code starts with this prefix, e.g. '72' (accommodation & food services), '23' (construction). Empty = all industries."
          },
          "lenderName": {
            "title": "Lender name contains",
            "type": "string",
            "description": "Substring match (case-insensitive) on the funding bank / lender name (7(a) BankName or 504 third-party lender). Empty = all lenders."
          },
          "query": {
            "title": "Free-text prefilter",
            "type": "string",
            "description": "Optional CKAN full-text search sent to data.sba.gov to prefilter rows before client-side filtering (e.g. a borrower or bank name). Speeds up narrow lender/borrower lookups over the large files. Empty = scan all rows up to the max."
          },
          "sinceDate": {
            "title": "Approved on/after (YYYY-MM-DD)",
            "type": "string",
            "description": "Only return loans with approval_date on or after this date. Empty = no lower bound."
          },
          "untilDate": {
            "title": "Approved on/before (YYYY-MM-DD)",
            "type": "string",
            "description": "Only return loans with approval_date on or before this date. Empty = no upper bound."
          },
          "minAmount": {
            "title": "Minimum gross approval ($)",
            "minimum": 0,
            "type": "integer",
            "description": "Only return loans whose gross approval amount is at least this many dollars. Empty = no minimum."
          },
          "mode": {
            "title": "Output mode",
            "enum": [
              "loans",
              "rollup-by-lender",
              "rollup-by-naics",
              "rollup-by-state"
            ],
            "type": "string",
            "description": "'loans' emits one normalized loan row per result (with risk flags). 'rollup-by-lender', 'rollup-by-naics', and 'rollup-by-state' instead emit one aggregate row per lender / NAICS industry / state (loan count, total & avg approved $, charge-off/default proxy rate, jobs supported).",
            "default": "loans"
          },
          "flagRisk": {
            "title": "Add risk flags (loans mode)",
            "type": "boolean",
            "description": "In 'loans' mode, compute per-loan risk_flags and risk_score over the result set: high loan-amount-per-job outliers, charged-off/default loans, and single-lender concentration. Ignored in rollup modes.",
            "default": true
          },
          "maxResults": {
            "title": "Max results",
            "minimum": 1,
            "maximum": 200000,
            "type": "integer",
            "description": "Hard cap on the number of loan records fetched and scanned (the source files are large — this bounds cost and runtime). In rollup modes, rollups are computed over the loans fetched under this cap.",
            "default": 1000
          },
          "maxScanRows": {
            "title": "Max rows to scan per file",
            "minimum": 1000,
            "maximum": 5000000,
            "type": "integer",
            "description": "Upper bound on how many CSV rows are scanned per FOIA file before stopping. Raise for exhaustive rollups over the full loan history; lower for faster, cheaper sampling. Only matters when filters match few rows.",
            "default": 500000
          }
        }
      },
      "runsResponseSchema": {
        "type": "object",
        "properties": {
          "data": {
            "type": "object",
            "properties": {
              "id": {
                "type": "string"
              },
              "actId": {
                "type": "string"
              },
              "userId": {
                "type": "string"
              },
              "startedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "finishedAt": {
                "type": "string",
                "format": "date-time",
                "example": "2025-01-08T00:00:00.000Z"
              },
              "status": {
                "type": "string",
                "example": "READY"
              },
              "meta": {
                "type": "object",
                "properties": {
                  "origin": {
                    "type": "string",
                    "example": "API"
                  },
                  "userAgent": {
                    "type": "string"
                  }
                }
              },
              "stats": {
                "type": "object",
                "properties": {
                  "inputBodyLen": {
                    "type": "integer",
                    "example": 2000
                  },
                  "rebootCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "restartCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "resurrectCount": {
                    "type": "integer",
                    "example": 0
                  },
                  "computeUnits": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "options": {
                "type": "object",
                "properties": {
                  "build": {
                    "type": "string",
                    "example": "latest"
                  },
                  "timeoutSecs": {
                    "type": "integer",
                    "example": 300
                  },
                  "memoryMbytes": {
                    "type": "integer",
                    "example": 1024
                  },
                  "diskMbytes": {
                    "type": "integer",
                    "example": 2048
                  }
                }
              },
              "buildId": {
                "type": "string"
              },
              "defaultKeyValueStoreId": {
                "type": "string"
              },
              "defaultDatasetId": {
                "type": "string"
              },
              "defaultRequestQueueId": {
                "type": "string"
              },
              "buildNumber": {
                "type": "string",
                "example": "1.0.0"
              },
              "containerUrl": {
                "type": "string"
              },
              "usage": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "integer",
                    "example": 1
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              },
              "usageTotalUsd": {
                "type": "number",
                "example": 0.00005
              },
              "usageUsd": {
                "type": "object",
                "properties": {
                  "ACTOR_COMPUTE_UNITS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATASET_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "KEY_VALUE_STORE_WRITES": {
                    "type": "number",
                    "example": 0.00005
                  },
                  "KEY_VALUE_STORE_LISTS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_READS": {
                    "type": "integer",
                    "example": 0
                  },
                  "REQUEST_QUEUE_WRITES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_INTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "DATA_TRANSFER_EXTERNAL_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_RESIDENTIAL_TRANSFER_GBYTES": {
                    "type": "integer",
                    "example": 0
                  },
                  "PROXY_SERPS": {
                    "type": "integer",
                    "example": 0
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}