# GAP index

GAP index

Status: LIVE
Price: $0.005 USDC
`GET /api/calc/gap_index`
HTML: https://magentlab.com/docs/gap-index
Markdown: https://magentlab.com/docs/gap-index.md

Not a medical device. Not a diagnosis, dose, or listing recommendation.

## What it computes

Sum Ley 2012 GAP index points from sex, age, FVC percent predicted, and DLCO percent predicted or cannot-perform.

## When to use

When an agent needs the published Ley 2012 GAP index total and stage and must not invent a transplant listing or a continuous GAP value.

## When not to use

- Not a medical device and not a transplant listing protocol. Stages follow Ley 2012 GAP index points (I 0-3 / II 4-5 / III 6-8).
- Ley 2012 reported 1-, 2-, and 3-year mortality by GAP stage in derivation and validation cohorts; those cohort proportions are not returned in the JSON body.
- Provide exactly one of dlco_percent_predicted or dlco_cannot_perform=true. FVC and DLCO percent predicted are caller-supplied; magent does not compute percent predicted from raw spirometry.

## Formula

```
GAP = sex_points + age_points + fvc_points + dlco_points; female 0 male 1; age <=60 -> 0, 61-65 -> 1, >65 -> 2; FVC% >75 -> 0, 50-75 -> 1, <50 -> 2; DLCO% >55 -> 0, 36-55 -> 1, <=35 -> 2, cannot perform -> 3; stages I 0-3 / II 4-5 / III 6-8; max 8
```

## Citation

[A multidimensional index and staging system for idiopathic pulmonary fibrosis](https://doi.org/10.7326/0003-4819-156-10-201205150-00004)
Ley B, Ryerson CJ, Vittinghoff E, et al.
Ann Intern Med. 2012;156(10):684-691
DOI: [10.7326/0003-4819-156-10-201205150-00004](https://doi.org/10.7326/0003-4819-156-10-201205150-00004)

## Worked example

### All 0-point bands (stage I)

Given: `age=55, dlco_percent_predicted=60, fvc_percent_predicted=80, sex=female`

1. Female → 0; age 55 ≤60 → 0; FVC 80% >75 → 0; DLCO 60% >55 → 0
2. Score = 0; stage 1


### Maximum points (stage III)

Given: `age=70, dlco_cannot_perform=true, fvc_percent_predicted=40, sex=male`

1. Male → 1; age 70 >65 → 2; FVC 40% <50 → 2; DLCO cannot perform → 3
2. Score = 8; stage 3


## Also searched as

- GAP index
- GAP score
- Ley GAP
- IPF GAP
- gender age physiology
- idiopathic pulmonary fibrosis staging
- GAP stage

## Parameters

- `sex` (string, required): Sex (female or male). Ley 2012: female scores 0; male scores 1.
- `age` (integer, required): Age in years (integer 18-120). Ley 2012: <=60 scores 0; 61-65 scores 1; >65 scores 2.
- `fvc_percent_predicted` (number, required): FVC percent predicted (10-150). Ley 2012: >75 scores 0; 50-75 scores 1; <50 scores 2. 75.0 scores 1.
- `dlco_percent_predicted` (number, optional): DLCO percent predicted (1-150). Provide this or dlco_cannot_perform=true, not both. Ley 2012: >55 scores 0; 36-55 scores 1; <=35 scores 2.
- `dlco_cannot_perform` (boolean, optional): true when DLCO cannot be performed (Ley 2012 scores 3). Provide this or dlco_percent_predicted, not both.

## Bulk (POST)

POST the same path with a JSON items array. The first item is the GET unit; each additional item is $0.002. Invalid items return HTTP 400 before settlement.

Method: `POST /api/calc/gap_index`
Max items: 25
Price: unit_amount + extra_item_amount * (n - 1) (unit 5000 atomic, extra 2000 atomic)
Status: PREVIEW

- 1 to 25 items. Each item uses the same keys as the GET query parameters.
- POST of 1 item costs the same as GET. Lists longer than 25: chunk into multiple POSTs. Extra items still execute; do not pad dummy rows.
- The first invalid item fails the whole request (index in the 400 JSON). You are not charged.
- HTTP 200 is {count, path, items}. Each items[i] is the GET 200 body for that row.
- Catalog misses (empty matches, found=false) stay paid 200s inside that slot.
- x402 resource URL is this path plus n and body_sha256. Browsers that prefer text/html get the same paywall as GET; Pay retries POST with the same items.

Example request:

```json
{
  "items": [
    {
      "age": "55",
      "dlco_percent_predicted": "60",
      "fvc_percent_predicted": "80",
      "sex": "female"
    },
    {
      "age": "55",
      "dlco_percent_predicted": "60",
      "fvc_percent_predicted": "80",
      "sex": "female"
    }
  ]
}
```

Human paywall (two-item fixture): https://api.magentlab.com/paywall/bulk/gap-index

Example 200:

```json
{
  "count": 2,
  "path": "/api/calc/gap_index",
  "items": [
    {
      "components": [
        {
          "value": "female",
          "factor": "sex",
          "points": 0,
          "present": false
        },
        {
          "value": 55,
          "factor": "age",
          "points": 0,
          "present": false
        },
        {
          "value": 80.0,
          "factor": "fvc",
          "points": 0,
          "present": false
        },
        {
          "value": 60.0,
          "factor": "dlco",
          "points": 0,
          "present": false
        }
      ],
      "disclaimer": "Not a medical device. Deterministic published-formula or published-code output for autonomous agents. A licensed clinician remains responsible for patient care and billing submissions.",
      "citation": {
        "authors": "Ley B, Ryerson CJ, Vittinghoff E, et al.",
        "doi": "10.7326/0003-4819-156-10-201205150-00004",
        "id": "ley-2012",
        "pmid": "22586007",
        "source": "Ann Intern Med. 2012;156(10):684-691",
        "title": "A multidimensional index and staging system for idiopathic pulmonary fibrosis"
      },
      "formula": "gap_index",
      "formula_expression": "GAP = sex_points + age_points + fvc_points + dlco_points; female 0 male 1; age <=60 -> 0, 61-65 -> 1, >65 -> 2; FVC% >75 -> 0, 50-75 -> 1, <50 -> 2; DLCO% >55 -> 0, 36-55 -> 1, <=35 -> 2, cannot perform -> 3; stages I 0-3 / II 4-5 / III 6-8; max 8",
      "max_score": 8,
      "score": 0,
      "age_years": 55,
      "sex": "female",
      "dlco_cannot_perform": false,
      "dlco_percent_predicted": 60.0,
      "fvc_percent_predicted": 80.0,
      "gap_stage": 1
    },
    {
      "components": [
        {
          "value": "female",
          "factor": "sex",
          "points": 0,
          "present": false
        },
        {
          "value": 55,
          "factor": "age",
          "points": 0,
          "present": false
        },
        {
          "value": 80.0,
          "factor": "fvc",
          "points": 0,
          "present": false
        },
        {
          "value": 60.0,
          "factor": "dlco",
          "points": 0,
          "present": false
        }
      ],
      "disclaimer": "Not a medical device. Deterministic published-formula or published-code output for autonomous agents. A licensed clinician remains responsible for patient care and billing submissions.",
      "citation": {
        "authors": "Ley B, Ryerson CJ, Vittinghoff E, et al.",
        "doi": "10.7326/0003-4819-156-10-201205150-00004",
        "id": "ley-2012",
        "pmid": "22586007",
        "source": "Ann Intern Med. 2012;156(10):684-691",
        "title": "A multidimensional index and staging system for idiopathic pulmonary fibrosis"
      },
      "formula": "gap_index",
      "formula_expression": "GAP = sex_points + age_points + fvc_points + dlco_points; female 0 male 1; age <=60 -> 0, 61-65 -> 1, >65 -> 2; FVC% >75 -> 0, 50-75 -> 1, <50 -> 2; DLCO% >55 -> 0, 36-55 -> 1, <=35 -> 2, cannot perform -> 3; stages I 0-3 / II 4-5 / III 6-8; max 8",
      "max_score": 8,
      "score": 0,
      "age_years": 55,
      "sex": "female",
      "dlco_cannot_perform": false,
      "dlco_percent_predicted": 60.0,
      "fvc_percent_predicted": 80.0,
      "gap_stage": 1
    }
  ]
}
```

## Response fields

- `formula` (string): gap_index
- `formula_expression` (string): Exact Ley 2012 GAP index expression
- `score` (integer): GAP index points 0-8
- `max_score` (integer): Always 8
- `gap_stage` (integer): Ley 2012 stage 1 (0-3), 2 (4-5), or 3 (6-8). Not a transplant listing.
- `sex` (string): female or male used
- `age_years` (integer): Age in years used
- `fvc_percent_predicted` (number): FVC percent predicted used
- `dlco_percent_predicted` (number): DLCO percent predicted used, or null when cannot perform
- `dlco_cannot_perform` (boolean): true when Ley 2012 cannot-perform DLCO (3 points) was used
- `components` (array): Per-factor points for sex, age, fvc, and dlco
- `citation` (object): Ley et al. Ann Intern Med 2012 citation
- `disclaimer` (string): Not-a-device notice

## Example JSON

Frozen fixture. Not a live lookup.

```json
{
  "components": [
    {
      "value": "female",
      "factor": "sex",
      "points": 0,
      "present": false
    },
    {
      "value": 55,
      "factor": "age",
      "points": 0,
      "present": false
    },
    {
      "value": 80.0,
      "factor": "fvc",
      "points": 0,
      "present": false
    },
    {
      "value": 60.0,
      "factor": "dlco",
      "points": 0,
      "present": false
    }
  ],
  "disclaimer": "Not a medical device. Deterministic published-formula or published-code output for autonomous agents. A licensed clinician remains responsible for patient care and billing submissions.",
  "citation": {
    "authors": "Ley B, Ryerson CJ, Vittinghoff E, et al.",
    "doi": "10.7326/0003-4819-156-10-201205150-00004",
    "id": "ley-2012",
    "pmid": "22586007",
    "source": "Ann Intern Med. 2012;156(10):684-691",
    "title": "A multidimensional index and staging system for idiopathic pulmonary fibrosis"
  },
  "formula": "gap_index",
  "formula_expression": "GAP = sex_points + age_points + fvc_points + dlco_points; female 0 male 1; age <=60 -> 0, 61-65 -> 1, >65 -> 2; FVC% >75 -> 0, 50-75 -> 1, <50 -> 2; DLCO% >55 -> 0, 36-55 -> 1, <=35 -> 2, cannot perform -> 3; stages I 0-3 / II 4-5 / III 6-8; max 8",
  "max_score": 8,
  "score": 0,
  "age_years": 55,
  "sex": "female",
  "dlco_cannot_perform": false,
  "dlco_percent_predicted": 60.0,
  "fvc_percent_predicted": 80.0,
  "gap_stage": 1
}
```

## Errors

- HTTP 400 `invalid_age`: age must be an integer from 18 to 120 Returned before settlement; you are not charged.
- HTTP 400 `invalid_sex`: sex must be female or male Returned before settlement; you are not charged.
- HTTP 400 `invalid_fvc_percent`: fvc_percent_predicted must be a number from 10 to 150. Returned before settlement; you are not charged.
- HTTP 400 `invalid_dlco_percent`: dlco_percent_predicted must be a number from 1 to 150. Returned before settlement; you are not charged.
- HTTP 400 `invalid_gap_dlco`: provide dlco_percent_predicted or dlco_cannot_perform=true, not both (Ley 2012). Returned before settlement; you are not charged.
- HTTP 400 `invalid_items`: POST body must be a JSON object with only an items array Returned before settlement; you are not charged.
- HTTP 400 `invalid_item_count`: items must be an array of 1 to 25 objects Returned before settlement; you are not charged.
- HTTP 400 `invalid_item`: each items entry must be a JSON object Returned before settlement; you are not charged.

Shared HTTP 402 and 503: https://magentlab.com/docs/payments

## Related tools

- [BODE](https://magentlab.com/docs/bode) — Sum Celli 2004 BODE points from BMI, FEV1 percent predicted, MMRC dyspnea, and 6-minute walk distance.
- [PaO2/FiO2 ratio](https://magentlab.com/docs/pf-ratio) — Compute the PaO2/FiO2 ratio as arterial PO2 in mm Hg divided by inspired oxygen fraction.
- [Peak expiratory flow](https://magentlab.com/docs/peak-expiratory-flow) — Compute Nunn and Gregg 1989 predicted peak expiratory flow in L/min from age, sex, and height.

## Payment

Unpaid requests return HTTP 402 even if query parameters or POST items are missing or invalid, so CDP and agents can index the path. After a PAYMENT-SIGNATURE, invalid params return HTTP 400 JSON before settlement. magent does not charge. Fix the params, then request a new 402 quote for that complete URL. Catalog misses (empty matches, found=false) are valid paid 200s.

- GET the tool with Accept: application/json (do not send Accept: text/html unless you want the human paywall).
- HTTP 402 means you have not paid. Decode the base64 PAYMENT-REQUIRED header. HTTP 503 is not a new quote.
- Sign accepts[0] (exact, EIP-3009) with validBefore = now + maxTimeoutSeconds (600 seconds), or accepts[1] (batch-settlement deposit/voucher) on product GET. Ping and POST {items} stay exact. Magent retries transient facilitator 429/5xx before answering.
- Retry the same URL with PAYMENT-SIGNATURE (base64 JSON echoing accepted, payload, and extensions when present).
- Success is HTTP 200 JSON plus PAYMENT-RESPONSE. exact settles before the tool. batch-settlement verifies (and deposit-settles) before the tool and commits the charge after HTTP 2xx. HTTP 503: retry the same PAYMENT-SIGNATURE. Mint a new exact nonce only after a new HTTP 402.

- offered `exact` on eip155:8453: Fixed-price USDC on Base. The buyer authorizes the advertised amount (EIP-3009). magent settles before the tool runs (paymentFlow upfront). extra.assetTransferMethod=eip3009 extra.paymentFlow=upfront.
- offered `batch-settlement` on eip155:8453: Payment-channel vouchers claimed later in batches. Exact stays accepts[0]. Same-path POST {items} is still exact. extra.assetTransferMethod=eip3009 extra.paymentFlow=authorization.

- not offered `upto`: Not offered. Usage-based: buyer authorizes a ceiling, seller settles the actual amount after work. Reserved for a future metered tool. Not for current calculators or code search.

Same-path POST {items} is still scheme exact: one EIP-3009 authorization for GET unit plus $0.002 per extra item. That is not x402 batch-settlement (payment channels / vouchers).

Shared HTTP 402 and 503 table: https://magentlab.com/docs/payments

Stdio MCP (one process per host): https://magentlab.com/docs/mcp

## Guarantees

- HTTP 402 is unpaid, including a missing query. After PAYMENT-SIGNATURE, invalid parameters return HTTP 400 before settlement. You are not charged.
- exact: settlement finishes before the tool (paymentFlow upfront). batch-settlement: verify/deposit before the tool; chargedCumulativeAmount commits after HTTP 2xx. Uncertain or failed settlement fails closed (HTTP 503). Retry the same PAYMENT-SIGNATURE.
- HTTP 402 is unpaid only. Do not sign a second authorization because of a 503.
- Execution is timeout-bounded and concurrency-capped.
- Calculator inputs are stored encrypted for allowlisted operators (Magent Console). They are not in public logs, SSH lookups, catalog, or rollups. Request logs store path without query.
