# COVID-GRAM critical illness

COVID-GRAM

Status: LIVE
Price: $0.005 USDC
`GET /api/calc/cgram`
HTML: https://magentlab.com/docs/covid-gram
Markdown: https://magentlab.com/docs/covid-gram.md

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

## What it computes

Compute the Liang 2020 COVID-GRAM logistic probability of critical illness (ICU admission, invasive ventilation, or death) among hospitalized COVID-19 from age, a caller-assigned chest radiograph abnormality, hemoptysis, dyspnea, unconsciousness, comorbidity count, cancer history, neutrophil-to-lymphocyte ratio, LDH, and direct bilirubin.

## When to use

When an agent already has admission-time age, a caller-assigned chest radiograph flag, symptoms, comorbidity count, cancer history, NLR, LDH in U/L, and direct bilirubin in umol/L, and needs the published Liang 2020 Table 3 probability, not 4C, PRIEST, CHOSEN, or VACO.

## When not to use

- Not a medical device and not a diagnosis. Not an ICU-allocation, triage, ventilation, or treatment order.
- magent does not read the chest radiograph or count comorbidities. chest_xray_abnormal and number_of_comorbidities are caller-assigned.
- Liang 2020 comorbidity count is COPD, diabetes, hypertension, cardiovascular disease, cerebrovascular disease, hepatitis B, cancer, chronic kidney disease, and immunodeficiency. Cancer history is a separate Table 3 term.
- Liang 2020 Table 3 prints odds ratios (constant 0.001). magent uses the matching logistic coefficients. The paper deliberately did not categorize low-, moderate-, and high-risk groups.
- Derivation used early-pandemic hospitalized patients in China. Liang 2020 publishes no later-wave recalibration.

## Formula

```
lp = 1.2205*chest_xray_abnormal + 0.0276*age + 1.5116*hemoptysis + 0.632*dyspnea + 1.5494*unconsciousness + 0.4668*number_of_comorbidities + 1.4037*cancer_history + 0.0562*nlr + 0.0024*ldh_u_l + 0.1376*direct_bilirubin_umol_l - 6.6127; probability = exp(lp)/(1+exp(lp)); Liang 2020 Table 3 logistic (printed ORs; intercept -6.6127 matches constant 0.001); critical illness = ICU, invasive ventilation, or death; LDH U/L; direct bilirubin umol/L; magent does not read the chest film or count comorbidities; Liang 2020 did not publish low/medium/high cutoffs
```

## Citation

[Development and Validation of a Clinical Risk Score to Predict the Occurrence of Critical Illness in Hospitalized Patients With COVID-19](https://doi.org/10.1001/jamainternmed.2020.2033)
Liang W, Liang H, Ou L, Chen B, Chen A, Li C, et al.
JAMA Intern Med. 2020;180(8):1081-1089
DOI: [10.1001/jamainternmed.2020.2033](https://doi.org/10.1001/jamainternmed.2020.2033)

## Worked example

### Age 30, no flags, NLR 2.0, LDH 150, direct bilirubin 3.0

Given: `age=30, cancer_history=false, chest_xray_abnormal=false, direct_bilirubin_umol_l=3.0, dyspnea=false, hemoptysis=false, ldh_u_l=150, nlr=2.0, number_of_comorbidities=0, unconsciousness=false`

1. all flags false; comorbidities 0; age 30; nlr 2.0; ldh 150 U/L; direct bilirubin 3.0 umol/L
2. lp = 0.0276*30 + 0.0562*2.0 + 0.0024*150 + 0.1376*3.0 - 6.6127 = -4.8995
3. estimated_probability_percent = 100 * exp(lp)/(1+exp(lp)), 1 decimal


### Age 70, otherwise the age-30 example

Given: `age=70, cancer_history=false, chest_xray_abnormal=false, direct_bilirubin_umol_l=3.0, dyspnea=false, hemoptysis=false, ldh_u_l=150, nlr=2.0, number_of_comorbidities=0, unconsciousness=false`

1. same flags and labs as the age-30 example; age term 0.0276*70
2. lp = 0.0276*70 + 0.0562*2.0 + 0.0024*150 + 0.1376*3.0 - 6.6127 = -3.7955
3. estimated_probability_percent from the unrounded logit, 1 decimal


## Also searched as

- COVID-GRAM
- Liang COVID-19 risk score
- COVID critical illness score
- hospitalized COVID-19 GRAM
- Liang 2020 critical illness
- COVID-GRAM logistic

## Parameters

- `age` (integer, required): Age in years (integer 1-120). Liang 2020 Table 3: +0.0276 per year (OR 1.03 per year). Development cohort ages 1-95.
- `chest_xray_abnormal` (boolean, required): Chest radiograph abnormality as assigned by the caller (true or false). Liang 2020 Table 3: true adds 1.2205 (OR 3.39). magent does not read the film.
- `hemoptysis` (boolean, required): Hemoptysis as assigned by the caller (true or false). Liang 2020 Table 3: true adds 1.5116 (OR 4.53).
- `dyspnea` (boolean, required): Dyspnea (shortness of breath) as assigned by the caller (true or false). Liang 2020 Table 3: true adds 0.632 (OR 1.88).
- `unconsciousness` (boolean, required): Unconsciousness as assigned by the caller (true or false). Liang 2020 Table 3: true adds 1.5494 (OR 4.71).
- `number_of_comorbidities` (integer, required): Caller-assigned count of comorbidities as Liang 2020 defined (integer 0-10): COPD, diabetes, hypertension, cardiovascular disease, cerebrovascular disease, hepatitis B, cancer, chronic kidney disease, immunodeficiency. Table 3: +0.4668 per comorbidity (OR 1.60). magent does not count diagnoses.
- `cancer_history` (boolean, required): Cancer history as assigned by the caller (true or false). Liang 2020 Table 3: true adds 1.4037 (OR 4.07), separate from the comorbidity count.
- `nlr` (number, required): Neutrophil-to-lymphocyte ratio (0.01-200). Liang 2020 Table 3: +0.0562 per unit (OR 1.06). Caller assigns the ratio; magent does not compute it from counts.
- `ldh_u_l` (number, required): Lactate dehydrogenase in U/L (1-5000). Liang 2020 Table 3: +0.0024 per U/L (OR 1.002). magent does not convert other LDH units.
- `direct_bilirubin_umol_l` (number, required): Direct bilirubin in umol/L (0-200). Liang 2020 Table 3: +0.1376 per umol/L (OR 1.15). magent does not convert mg/dL.

## 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/cgram`
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": "30",
      "cancer_history": "false",
      "chest_xray_abnormal": "false",
      "direct_bilirubin_umol_l": "3.0",
      "dyspnea": "false",
      "hemoptysis": "false",
      "ldh_u_l": "150",
      "nlr": "2.0",
      "number_of_comorbidities": "0",
      "unconsciousness": "false"
    },
    {
      "age": "30",
      "cancer_history": "false",
      "chest_xray_abnormal": "false",
      "direct_bilirubin_umol_l": "3.0",
      "dyspnea": "false",
      "hemoptysis": "false",
      "ldh_u_l": "150",
      "nlr": "2.0",
      "number_of_comorbidities": "0",
      "unconsciousness": "false"
    }
  ]
}
```

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

Example 200:

```json
{
  "count": 2,
  "path": "/api/calc/cgram",
  "items": [
    {
      "age": 30,
      "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": "Liang W, Liang H, Ou L, Chen B, Chen A, Li C, et al.",
        "doi": "10.1001/jamainternmed.2020.2033",
        "id": "liang-2020-covid-gram",
        "pmid": "32396163",
        "source": "JAMA Intern Med. 2020;180(8):1081-1089",
        "title": "Development and Validation of a Clinical Risk Score to Predict the Occurrence of Critical Illness in Hospitalized Patients With COVID-19"
      },
      "formula": "covid_gram",
      "formula_expression": "lp = 1.2205*chest_xray_abnormal + 0.0276*age + 1.5116*hemoptysis + 0.632*dyspnea + 1.5494*unconsciousness + 0.4668*number_of_comorbidities + 1.4037*cancer_history + 0.0562*nlr + 0.0024*ldh_u_l + 0.1376*direct_bilirubin_umol_l - 6.6127; probability = exp(lp)/(1+exp(lp)); Liang 2020 Table 3 logistic (printed ORs; intercept -6.6127 matches constant 0.001); critical illness = ICU, invasive ventilation, or death; LDH U/L; direct bilirubin umol/L; magent does not read the chest film or count comorbidities; Liang 2020 did not publish low/medium/high cutoffs",
      "estimated_probability_percent": 0.7,
      "logit": -4.8995,
      "cancer_history": false,
      "chest_xray_abnormal": false,
      "direct_bilirubin_umol_l": 3.0,
      "dyspnea": false,
      "hemoptysis": false,
      "ldh_u_l": 150.0,
      "nlr": 2.0,
      "number_of_comorbidities": 0,
      "unconsciousness": false
    },
    {
      "age": 30,
      "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": "Liang W, Liang H, Ou L, Chen B, Chen A, Li C, et al.",
        "doi": "10.1001/jamainternmed.2020.2033",
        "id": "liang-2020-covid-gram",
        "pmid": "32396163",
        "source": "JAMA Intern Med. 2020;180(8):1081-1089",
        "title": "Development and Validation of a Clinical Risk Score to Predict the Occurrence of Critical Illness in Hospitalized Patients With COVID-19"
      },
      "formula": "covid_gram",
      "formula_expression": "lp = 1.2205*chest_xray_abnormal + 0.0276*age + 1.5116*hemoptysis + 0.632*dyspnea + 1.5494*unconsciousness + 0.4668*number_of_comorbidities + 1.4037*cancer_history + 0.0562*nlr + 0.0024*ldh_u_l + 0.1376*direct_bilirubin_umol_l - 6.6127; probability = exp(lp)/(1+exp(lp)); Liang 2020 Table 3 logistic (printed ORs; intercept -6.6127 matches constant 0.001); critical illness = ICU, invasive ventilation, or death; LDH U/L; direct bilirubin umol/L; magent does not read the chest film or count comorbidities; Liang 2020 did not publish low/medium/high cutoffs",
      "estimated_probability_percent": 0.7,
      "logit": -4.8995,
      "cancer_history": false,
      "chest_xray_abnormal": false,
      "direct_bilirubin_umol_l": 3.0,
      "dyspnea": false,
      "hemoptysis": false,
      "ldh_u_l": 150.0,
      "nlr": 2.0,
      "number_of_comorbidities": 0,
      "unconsciousness": false
    }
  ]
}
```

## Response fields

- `formula` (string): covid_gram
- `formula_expression` (string): Liang 2020 Table 3 logistic linear predictor and probability
- `age` (integer): Input age in years
- `chest_xray_abnormal` (boolean): Caller-assigned chest radiograph abnormality
- `hemoptysis` (boolean): Caller-assigned hemoptysis
- `dyspnea` (boolean): Caller-assigned dyspnea
- `unconsciousness` (boolean): Caller-assigned unconsciousness
- `number_of_comorbidities` (integer): Caller-assigned Liang 2020 comorbidity count
- `cancer_history` (boolean): Caller-assigned cancer history
- `nlr` (number): Input neutrophil-to-lymphocyte ratio
- `ldh_u_l` (number): Input LDH in U/L
- `direct_bilirubin_umol_l` (number): Input direct bilirubin in umol/L
- `logit` (number): Unrounded linear predictor, 4 decimals
- `estimated_probability_percent` (number): Critical-illness percent from the unrounded logit, 1 decimal. A probability, not an ICU order.
- `citation` (object): Liang 2020 COVID-GRAM citation
- `disclaimer` (string): Not-a-device notice

## Example JSON

Frozen fixture. Not a live lookup.

```json
{
  "age": 30,
  "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": "Liang W, Liang H, Ou L, Chen B, Chen A, Li C, et al.",
    "doi": "10.1001/jamainternmed.2020.2033",
    "id": "liang-2020-covid-gram",
    "pmid": "32396163",
    "source": "JAMA Intern Med. 2020;180(8):1081-1089",
    "title": "Development and Validation of a Clinical Risk Score to Predict the Occurrence of Critical Illness in Hospitalized Patients With COVID-19"
  },
  "formula": "covid_gram",
  "formula_expression": "lp = 1.2205*chest_xray_abnormal + 0.0276*age + 1.5116*hemoptysis + 0.632*dyspnea + 1.5494*unconsciousness + 0.4668*number_of_comorbidities + 1.4037*cancer_history + 0.0562*nlr + 0.0024*ldh_u_l + 0.1376*direct_bilirubin_umol_l - 6.6127; probability = exp(lp)/(1+exp(lp)); Liang 2020 Table 3 logistic (printed ORs; intercept -6.6127 matches constant 0.001); critical illness = ICU, invasive ventilation, or death; LDH U/L; direct bilirubin umol/L; magent does not read the chest film or count comorbidities; Liang 2020 did not publish low/medium/high cutoffs",
  "estimated_probability_percent": 0.7,
  "logit": -4.8995,
  "cancer_history": false,
  "chest_xray_abnormal": false,
  "direct_bilirubin_umol_l": 3.0,
  "dyspnea": false,
  "hemoptysis": false,
  "ldh_u_l": 150.0,
  "nlr": 2.0,
  "number_of_comorbidities": 0,
  "unconsciousness": false
}
```

## Errors

- HTTP 400 `invalid_covid_gram`: COVID-GRAM inputs must match Liang 2020 age, radiographic abnormality, symptoms, comorbidities, neutrophil-to-lymphocyte ratio, LDH, and direct bilirubin. 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

- [4C](https://magentlab.com/docs/4c) — Sum the Knight 2020 ISARIC 4C Mortality Score items and return the published Table 5 band (low, intermediate, high, or very high).
- [PRIEST](https://magentlab.com/docs/priest) — Sum the Goodacre 2021 PRIEST points from NEWS2 Chart 1 Scale 1 vitals, alertness, inspired oxygen, age, sex, and performance status, and return whether the total is ≤4.
- [CHOSEN](https://magentlab.com/docs/chosen) — Sum the Levine 2020 CHOSEN (COVID Home Safely Now) Figure 2 points from age, oxygen saturation, and serum albumin in g/dL, and return whether the total is at or above the printed cutpoint of 30.
- [VACO Index](https://magentlab.com/docs/vaco) — Compute the King 2020 VACO Index 30-day all-cause mortality probability from age, sex, a caller-assigned unadjusted Charlson comorbidity index, and history of myocardial infarction or peripheral vascular disease using Supplement S3 coefficients.

## 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. HTTP 402 never includes the tool JSON.
- 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.
