# BAP-65

BAP-65

Status: LIVE
Price: $0.005 USDC
`GET /api/calc/bap_65`
HTML: https://magentlab.com/docs/bap-65
Markdown: https://magentlab.com/docs/bap-65.md

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

## What it computes

Apply Tabak 2009 BAP-65 and return class I–V from three caller-assigned main factors, using age >65 only to split class I from II when zero main factors are present.

## When to use

When an agent already has BUN, mental status, pulse, and age assigned as Tabak 2009 flags for an adult with acute exacerbation of COPD and needs the published BAP-65 class. magent does not compute GCS, BUN, or pulse.

## When not to use

- Not a medical device.
- Not a mechanical-ventilation, ICU-admission, or early-discharge order. magent does not diagnose COPD exacerbation.
- The caller assigns bun_gt_25, altered_mental_status, pulse_gt_109, and age_gt_65 as already determined. magent does not compute GCS, BUN, or pulse.
- Age >65 is not a fourth additive point. It splits class I from class II only when zero of the three main factors are present. Classes III–V ignore age.
- In-hospital mortality figures in Tabak 2009 are 0.3% for no factors and age ≤65 versus 13.1% (derivation) / 14.6% (validation) when all three main factors are present. Per-class percents for II–IV are not attached.

## Formula

```
class I = 0 main factors and age ≤65; II = 0 main factors and age >65; III = 1 main factor; IV = 2 main factors; V = 3 main factors (BUN >25 mg/dL, GCS <14 or disoriented/stupor/coma, pulse >109/min); age is not a 4th additive point
```

## Citation

[Mortality and need for mechanical ventilation in acute exacerbations of chronic obstructive pulmonary disease: development and validation of a simple risk score](https://doi.org/10.1001/archinternmed.2009.270)
Tabak YP, Sun X, Johannes RS, Gupta V, Shorr AF
Arch Intern Med. 2009;169(17):1595-1602
DOI: [10.1001/archinternmed.2009.270](https://doi.org/10.1001/archinternmed.2009.270)

## Worked example

### No main factors, age ≤65 (class I)

Given: `age_gt_65=false, altered_mental_status=false, bun_gt_25=false, pulse_gt_109=false`

1. All three main factors false; age_gt_65 false
2. main_factor_count = 0 and age ≤65 → class I


### All three main factors present (class V)

Given: `age_gt_65=false, altered_mental_status=true, bun_gt_25=true, pulse_gt_109=true`

1. BUN >25, altered mental status, and pulse >109 all true
2. main_factor_count = 3; age ignored → class V


## Also searched as

- BAP-65
- BAP65
- Tabak BAP-65
- COPD exacerbation BAP-65
- BUN altered mental status pulse 65
- BAP 65 score
- acute exacerbation COPD BAP-65

## Parameters

- `bun_gt_25` (boolean, required): BUN >25 mg/dL (strict greater than; 25 does not meet). true or false as assigned by the caller. magent does not compute BUN.
- `altered_mental_status` (boolean, required): GCS <14 or physician designation of disoriented, stupor, or coma (Tabak 2009). true or false as assigned by the caller. magent does not compute GCS.
- `pulse_gt_109` (boolean, required): Pulse >109/min (strict greater than; 109 does not meet). true or false as assigned by the caller. magent does not compute pulse.
- `age_gt_65` (boolean, required): Age >65 years (strict greater than). Used only when zero of the three main factors are present, to split class I from II. true or false as assigned by the caller. magent does not compute age.

## 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/bap_65`
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_gt_65": "false",
      "altered_mental_status": "false",
      "bun_gt_25": "false",
      "pulse_gt_109": "false"
    },
    {
      "age_gt_65": "false",
      "altered_mental_status": "false",
      "bun_gt_25": "false",
      "pulse_gt_109": "false"
    }
  ]
}
```

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

Example 200:

```json
{
  "count": 2,
  "path": "/api/calc/bap_65",
  "items": [
    {
      "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": "Tabak YP, Sun X, Johannes RS, Gupta V, Shorr AF",
        "doi": "10.1001/archinternmed.2009.270",
        "id": "tabak-2009",
        "pmid": "19786679",
        "source": "Arch Intern Med. 2009;169(17):1595-1602",
        "title": "Mortality and need for mechanical ventilation in acute exacerbations of chronic obstructive pulmonary disease: development and validation of a simple risk score"
      },
      "formula": "bap_65",
      "formula_expression": "class I = 0 main factors and age ≤65; II = 0 main factors and age >65; III = 1 main factor; IV = 2 main factors; V = 3 main factors (BUN >25 mg/dL, GCS <14 or disoriented/stupor/coma, pulse >109/min); age is not a 4th additive point",
      "criteria": [
        {
          "factor": "bun_gt_25",
          "met": false
        },
        {
          "factor": "altered_mental_status",
          "met": false
        },
        {
          "factor": "pulse_gt_109",
          "met": false
        },
        {
          "factor": "age_gt_65",
          "met": false
        }
      ],
      "bap65_class": "I",
      "main_factor_count": 0
    },
    {
      "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": "Tabak YP, Sun X, Johannes RS, Gupta V, Shorr AF",
        "doi": "10.1001/archinternmed.2009.270",
        "id": "tabak-2009",
        "pmid": "19786679",
        "source": "Arch Intern Med. 2009;169(17):1595-1602",
        "title": "Mortality and need for mechanical ventilation in acute exacerbations of chronic obstructive pulmonary disease: development and validation of a simple risk score"
      },
      "formula": "bap_65",
      "formula_expression": "class I = 0 main factors and age ≤65; II = 0 main factors and age >65; III = 1 main factor; IV = 2 main factors; V = 3 main factors (BUN >25 mg/dL, GCS <14 or disoriented/stupor/coma, pulse >109/min); age is not a 4th additive point",
      "criteria": [
        {
          "factor": "bun_gt_25",
          "met": false
        },
        {
          "factor": "altered_mental_status",
          "met": false
        },
        {
          "factor": "pulse_gt_109",
          "met": false
        },
        {
          "factor": "age_gt_65",
          "met": false
        }
      ],
      "bap65_class": "I",
      "main_factor_count": 0
    }
  ]
}
```

## Response fields

- `formula` (string): bap_65
- `formula_expression` (string): Tabak 2009: class I/II from zero main factors plus age; III/IV/V from 1/2/3 main factors
- `bap65_class` (string): Tabak 2009 class I, II, III, IV, or V. A class, not a ventilation or ICU-admission order.
- `main_factor_count` (integer): Count of the three main factors (BUN >25, altered mental status, pulse >109). 0-3. Age is not counted.
- `criteria` (array): Per-factor rows with factor and met for bun_gt_25, altered_mental_status, pulse_gt_109, and age_gt_65
- `citation` (object): Tabak 2009 Arch Intern Med citation
- `disclaimer` (string): Not-a-device notice

## Example JSON

Frozen fixture. Not a live lookup.

```json
{
  "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": "Tabak YP, Sun X, Johannes RS, Gupta V, Shorr AF",
    "doi": "10.1001/archinternmed.2009.270",
    "id": "tabak-2009",
    "pmid": "19786679",
    "source": "Arch Intern Med. 2009;169(17):1595-1602",
    "title": "Mortality and need for mechanical ventilation in acute exacerbations of chronic obstructive pulmonary disease: development and validation of a simple risk score"
  },
  "formula": "bap_65",
  "formula_expression": "class I = 0 main factors and age ≤65; II = 0 main factors and age >65; III = 1 main factor; IV = 2 main factors; V = 3 main factors (BUN >25 mg/dL, GCS <14 or disoriented/stupor/coma, pulse >109/min); age is not a 4th additive point",
  "criteria": [
    {
      "factor": "bun_gt_25",
      "met": false
    },
    {
      "factor": "altered_mental_status",
      "met": false
    },
    {
      "factor": "pulse_gt_109",
      "met": false
    },
    {
      "factor": "age_gt_65",
      "met": false
    }
  ],
  "bap65_class": "I",
  "main_factor_count": 0
}
```

## Errors

- HTTP 400 `invalid_flag`: boolean clinical flags must be true or false 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

- [DECAF](https://magentlab.com/docs/decaf) — Sum Steer 2012 DECAF points from extended MRC dyspnoea, eosinophils, chest radiograph consolidation, arterial pH, and atrial fibrillation.
- [NEWS](https://magentlab.com/docs/news) — Compute the RCP 2012 National Early Warning Score from respiratory rate, SpO2, supplemental oxygen, temperature, systolic BP, heart rate, and caller-assigned AVPU.
- [MEWS](https://magentlab.com/docs/mews) — Compute the Subbe 2001 modified Early Warning Score from systolic BP, heart rate, respiratory rate, temperature, and caller-assigned AVPU.

## 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 of accepted and payload). Magent attaches canonical extensions.bazaar on CDP verify/settle; echoing 402 bazaar is optional.
- 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.
