# SBA Loan Portfolio Explorer API — 7(a) & 504 Rollups (`malonestar/sba-loan-portfolio-explorer`) Actor

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.

- **URL**: https://apify.com/malonestar/sba-loan-portfolio-explorer.md
- **Developed by:** [Kyle Maloney](https://apify.com/malonestar) (community)
- **Categories:** Lead generation, Developer tools, Agents
- **Stats:** 2 total users, 0 monthly users, 100.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

from $8.00 / 1,000 results

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/platform/actors/running/actors-in-store#pay-per-event

## What's an Apify Actor?

Actors are a software tools running on the Apify platform, for all kinds of web data extraction and automation use cases.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.
Actors are written with capital "A".

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.
The best way to integrate Actors is as follows.

In JavaScript/TypeScript projects, use official [JavaScript/TypeScript client](https://docs.apify.com/api/client/js.md):

```bash
npm install apify-client
```

In Python projects, use official [Python client library](https://docs.apify.com/api/client/python.md):

```bash
pip install apify-client
```

In shell scripts, use [Apify CLI](https://docs.apify.com/cli/docs.md):

````bash
# MacOS / Linux
curl -fsSL https://apify.com/install-cli.sh | bash
# Windows
irm https://apify.com/install-cli.ps1 | iex
```bash

In AI frameworks, you might use the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp.md).

If your project is in a different language, use the [REST API](https://docs.apify.com/api/v2.md).

For usage examples, see the [API](#api) section below.

For more details, see Apify documentation as [Markdown index](https://docs.apify.com/llms.txt) and [Markdown full-text](https://docs.apify.com/llms-full.txt).


# README

## SBA Loan Portfolio Explorer — 7(a) & 504 Loan Data API with Rollups

An **SBA loan data API** over the official **7(a) and 504 FOIA** loan-level
files. Do a **7(a) / 504 loan lookup** by state, NAICS industry, lender, fiscal
year, or amount — then **roll up by lender, industry, or geography** and get
**risk / outlier flags** (loan-amount-per-job outliers, charge-off/default
proxy, single-lender concentration). SBA ships this data only as multi-hundred-MB
bulk CSVs; this actor makes it queryable and adds the analytics layer.

### Who it's for
- **Fintech / small-business lenders & underwriters** benchmarking lender books.
- **KYB / due-diligence & fraud teams** screening SBA borrowers and lenders.
- **Economic-development & policy analysts** studying loans by industry/state.
- **Data & RevOps teams** enriching a CRM with SBA loan history.
- **AI agents** needing an "SBA loan lookup / portfolio rollup" tool.

### What it does
Queries the data.sba.gov CKAN DataStore for the selected program(s) and fiscal
year, **normalizes 7(a) and 504 loans into one snake_case schema** (dates →
`YYYY-MM-DD`, amounts numeric), applies your state / NAICS / lender / amount /
date filters, and then either:
- returns **loan-level rows** with per-loan `risk_flags` + `risk_score`, or
- returns a **rollup** — one aggregate row per **lender**, **NAICS industry**, or
  **state** (loan count, total & average approved $, charge-off/default proxy
  rate, jobs supported).

### Example input
```json
{
  "program": "7a",
  "fiscalYear": 2023,
  "state": "CA",
  "naicsPrefix": "72",
  "mode": "rollup-by-lender",
  "maxResults": 5000
}
````

### Output (per loan)

`program`, `subprogram`, `borrower_name`, `borrower_city`, `borrower_state`,
`project_state`, `lender_name`, `lender_state`, `gross_approval`,
`sba_guaranteed_approval`, `approval_date`, `approval_fiscal_year`,
`initial_interest_rate`, `term_in_months`, `naics_code`, `naics_description`,
`business_type`, `jobs_supported`, `loan_status`, `charged_off`, `paid_in_full`,
`charge_off_date`, `gross_charge_off_amount`, `amount_per_job`, `risk_flags[]`,
`risk_score`, `source_system`.

### Output (rollup row)

`rollup_dimension`, group key (`lender_name` / `naics_code` / `state`),
`loan_count`, `total_approved`, `avg_approved`, `total_guaranteed`,
`charged_off_count`, `charge_off_rate`, `total_charged_off_amount`,
`jobs_supported`, `avg_amount_per_job`.

### Use as an MCP tool

Available to AI agents via `mcp.apify.com` as an "SBA loan portfolio explorer"
tool — filter in, normalized SBA loan records or lender/industry/geo rollups out.

### FAQ

**Where's the data from?** The SBA's official 7(a) & 504 FOIA loan-level files on
`data.sba.gov`, queried through the keyless CKAN DataStore API.
**Is it keyless?** Yes — no API key or login.
**Does it include PPP?** Not in v1. PPP is published only as a multi-GB bulk
file; 7(a) and 504 are the reliable, queryable targets. PPP may be added later.
**How do I find risky lenders?** Use `mode: rollup-by-lender` and sort by
`charge_off_rate`, or run `mode: loans` and filter on `risk_flags`.
**Why a max-results cap?** The FOIA files are large; `maxResults` bounds cost and
runtime. Narrow with `state` / `naicsPrefix` / `fiscalYear` / `query` for
targeted pulls.

### Source

SBA **data.sba.gov 7(a)/504 FOIA** files via the CKAN DataStore
(`data.sba.gov/api/3/action/datastore_search`). Official, keyless.

### Pricing (Pay Per Result)

Billed per result row returned — one loan record OR one rollup row. Empty
searches cost nothing.

# Actor input Schema

## `program` (type: `string`):

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).

## `fiscalYear` (type: `integer`):

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` (type: `string`):

Filter to loans whose borrower OR project state equals this 2-letter code, e.g. 'CA', 'TX'. Empty = all states.

## `naicsPrefix` (type: `string`):

Keep only loans whose NAICS code starts with this prefix, e.g. '72' (accommodation & food services), '23' (construction). Empty = all industries.

## `lenderName` (type: `string`):

Substring match (case-insensitive) on the funding bank / lender name (7(a) BankName or 504 third-party lender). Empty = all lenders.

## `query` (type: `string`):

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` (type: `string`):

Only return loans with approval\_date on or after this date. Empty = no lower bound.

## `untilDate` (type: `string`):

Only return loans with approval\_date on or before this date. Empty = no upper bound.

## `minAmount` (type: `integer`):

Only return loans whose gross approval amount is at least this many dollars. Empty = no minimum.

## `mode` (type: `string`):

'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).

## `flagRisk` (type: `boolean`):

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.

## `maxResults` (type: `integer`):

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.

## `maxScanRows` (type: `integer`):

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.

## Actor input object example

```json
{
  "program": "504",
  "state": "TX",
  "mode": "loans",
  "flagRisk": true,
  "maxResults": 50,
  "maxScanRows": 500000
}
```

# Actor output Schema

## `results` (type: `string`):

Normalized SBA loans or portfolio rollups in the default dataset.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {
    "program": "504",
    "state": "TX",
    "mode": "loans",
    "maxResults": 50
};

// Run the Actor and wait for it to finish
const run = await client.actor("malonestar/sba-loan-portfolio-explorer").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {
    "program": "504",
    "state": "TX",
    "mode": "loans",
    "maxResults": 50,
}

# Run the Actor and wait for it to finish
run = client.actor("malonestar/sba-loan-portfolio-explorer").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print("💾 Check your data here: https://console.apify.com/storage/datasets/" + run["defaultDatasetId"])
for item in client.dataset(run["defaultDatasetId"]).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{
  "program": "504",
  "state": "TX",
  "mode": "loans",
  "maxResults": 50
}' |
apify call malonestar/sba-loan-portfolio-explorer --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "command": "npx",
            "args": [
                "mcp-remote",
                "https://mcp.apify.com/?tools=malonestar/sba-loan-portfolio-explorer",
                "--header",
                "Authorization: Bearer <YOUR_API_TOKEN>"
            ]
        }
    }
}

```

## OpenAPI specification

```json
{
    "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
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
```
