Respiratory · LIVE
Alveolar–arterial oxygen gradient (A-a O2)
A-a O2 gradient
Compute the alveolar–arterial oxygen gradient from arterial blood-gas values using the simplified ideal alveolar-gas equation.
Markdown: /docs/aa-gradient.md · Canonical: https://magentlab.com/docs/aa-gradient
Not a medical device. Not a diagnosis, dose, or listing recommendation.
What it computes
Compute the alveolar–arterial oxygen gradient from arterial blood-gas values using the simplified ideal alveolar-gas equation.
When to use
When an agent needs PAO2 minus PaO2 from FiO2, barometric pressure, PaCO2, and PaO2 and must not invent an A-a gradient or an age-expected rule of thumb.
When not to use
- Not a diagnosis. Uses the simplified alveolar-gas equation with PH2O = 47 mm Hg at body temperature.
- Does not apply age-expected A-a rules of thumb.
- FiO2 is a fraction (0.21–1.0), not a percent.
Formula
PAO2_mm_hg = fio2 * (pb_mm_hg - 47) - paco2_mm_hg / rq; aa_gradient_mm_hg = PAO2_mm_hg - pao2_mm_hg
Citation
- Authors
- Riley RL, Cournand A
- Source
- J Appl Physiol. 1949;1(12):825-847
Worked example
Room air, PaCO2 40, PaO2 95
Given:
paco2_mm_hg=40pao2_mm_hg=95
- PAO2 = 0.21 × (760 − 47) − 40 / 0.8 = 0.21 × 713 − 50 = 149.73 − 50 = 99.73 → 99.7
- A-a = 99.7 − 95 = 4.7
Also searched as
- A-a gradient
- A-a O2
- alveolar-arterial oxygen gradient
- alveolar gas equation
- PAO2 minus PaO2
- A-a O2 gradient
Try
Opens the live endpoint. Unpaid browser requests show the paywall; agents should send Accept: application/json.
/api/calc/aa_gradient?paco2_mm_hg=40&pao2_mm_hg=95
Full URL: https://api.magentlab.com/api/calc/aa_gradient?paco2_mm_hg=40&pao2_mm_hg=95
Call
Expect HTTP 402 until you retry with PAYMENT-SIGNATURE. Incomplete query params
return HTTP 400 before any quote or charge.
curl -i -H "Accept: application/json" "https://api.magentlab.com/api/calc/aa_gradient?paco2_mm_hg=40&pao2_mm_hg=95"
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
paco2_mm_hg |
number | required | Arterial PCO2 in mm Hg (8-80). |
pao2_mm_hg |
number | required | Arterial PO2 in mm Hg (20-700). |
fio2 |
number | optional | Inspired oxygen as a fraction (0.21-1.0), not a percent. Omitted uses 0.21 (room air). |
pb_mm_hg |
number | optional | Barometric pressure in mm Hg (500-800). Omitted uses 760. |
rq |
number | optional | Respiratory exchange ratio R (0.7-1.0). Omitted uses 0.8. |
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.
- 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 (fixture)
{
"items": [
{
"paco2_mm_hg": "40",
"pao2_mm_hg": "95"
},
{
"paco2_mm_hg": "40",
"pao2_mm_hg": "95"
}
]
}
Opens a two-item fixture on the API host. Unpaid browsers get the same MetaMask paywall as GET; Pay retries POST with those items.
Example 200 (fixture)
{
"count": 2,
"path": "/api/calc/aa_gradient",
"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": "Riley RL, Cournand A",
"doi": "10.1152/jappl.1949.1.12.825",
"id": "riley-cournand-1949",
"source": "J Appl Physiol. 1949;1(12):825-847",
"title": "\"Ideal\" alveolar air and the analysis of ventilation-perfusion relationships in the lungs"
},
"formula": "aa_gradient",
"formula_expression": "PAO2_mm_hg = fio2 * (pb_mm_hg - 47) - paco2_mm_hg / rq; aa_gradient_mm_hg = PAO2_mm_hg - pao2_mm_hg",
"paco2_mm_hg": 40.0,
"aa_gradient_mm_hg": 4.7,
"fio2": 0.21,
"pao2_alveolar_mm_hg": 99.7,
"pao2_mm_hg": 95.0,
"pb_mm_hg": 760.0,
"rq": 0.8,
"water_vapor_mm_hg": 47.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": "Riley RL, Cournand A",
"doi": "10.1152/jappl.1949.1.12.825",
"id": "riley-cournand-1949",
"source": "J Appl Physiol. 1949;1(12):825-847",
"title": "\"Ideal\" alveolar air and the analysis of ventilation-perfusion relationships in the lungs"
},
"formula": "aa_gradient",
"formula_expression": "PAO2_mm_hg = fio2 * (pb_mm_hg - 47) - paco2_mm_hg / rq; aa_gradient_mm_hg = PAO2_mm_hg - pao2_mm_hg",
"paco2_mm_hg": 40.0,
"aa_gradient_mm_hg": 4.7,
"fio2": 0.21,
"pao2_alveolar_mm_hg": 99.7,
"pao2_mm_hg": 95.0,
"pb_mm_hg": 760.0,
"rq": 0.8,
"water_vapor_mm_hg": 47.0
}
]
}
Response
| Field | Type | Description |
|---|---|---|
formula |
string | aa_gradient |
formula_expression |
string | Exact expression used |
fio2 |
number | Inspired oxygen fraction used (0.21 when omitted) |
pb_mm_hg |
number | Barometric pressure used (760 when omitted) |
water_vapor_mm_hg |
number | Water-vapor pressure at body temperature, always 47 |
rq |
number | Respiratory exchange ratio used (0.8 when omitted) |
paco2_mm_hg |
number | Arterial PCO2 used |
pao2_mm_hg |
number | Arterial PO2 used |
pao2_alveolar_mm_hg |
number | Ideal alveolar PO2 in mm Hg, 1 decimal |
aa_gradient_mm_hg |
number | Alveolar minus arterial PO2 in mm Hg, 1 decimal |
citation |
object | Riley and Cournand 1949 citation |
disclaimer |
string | Not-a-device notice |
Example JSON
Machine form of the same example. Frozen fixture. Not a live lookup.
{
"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": "Riley RL, Cournand A",
"doi": "10.1152/jappl.1949.1.12.825",
"id": "riley-cournand-1949",
"source": "J Appl Physiol. 1949;1(12):825-847",
"title": "\"Ideal\" alveolar air and the analysis of ventilation-perfusion relationships in the lungs"
},
"formula": "aa_gradient",
"formula_expression": "PAO2_mm_hg = fio2 * (pb_mm_hg - 47) - paco2_mm_hg / rq; aa_gradient_mm_hg = PAO2_mm_hg - pao2_mm_hg",
"paco2_mm_hg": 40.0,
"aa_gradient_mm_hg": 4.7,
"fio2": 0.21,
"pao2_alveolar_mm_hg": 99.7,
"pao2_mm_hg": 95.0,
"pb_mm_hg": 760.0,
"rq": 0.8,
"water_vapor_mm_hg": 47.0
}
Client errors (HTTP 400)
Invalid params return 400 without charge. Shared HTTP 402 and 503 meanings: Payments.
| HTTP | Code | When |
|---|---|---|
| 400 | invalid_paco2 |
paco2_mm_hg must be a number from 8 to 80. Returned before settlement; you are not charged. |
| 400 | invalid_pao2 |
pao2_mm_hg must be a number from 20 to 700. Returned before settlement; you are not charged. |
| 400 | invalid_fio2 |
fio2 must be a fraction from 0.21 to 1.0. Returned before settlement; you are not charged. |
| 400 | invalid_barometric_pressure |
pb_mm_hg must be a number from 500 to 800. Returned before settlement; you are not charged. |
| 400 | invalid_rq |
rq must be a number from 0.7 to 1.0. Returned before settlement; you are not charged. |
| 400 | invalid_alveolar_po2 |
computed alveolar PO2 would be negative; check FiO2, PB, PaCO2, and RQ. Returned before settlement; you are not charged. |
| 400 | invalid_items |
POST body must be a JSON object with only an items array Returned before settlement; you are not charged. |
| 400 | invalid_item_count |
items must be an array of 1 to 25 objects Returned before settlement; you are not charged. |
| 400 | invalid_item |
each items entry must be a JSON object Returned before settlement; you are not charged. |
Related tools
- MAP — Compute conventional estimated mean arterial pressure from cuff systolic and diastolic pressures.
- Oxygenation index — Compute the oxygenation index from inspired oxygen fraction, mean airway pressure in cm H2O, and arterial PO2.
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. Unpaid valid requests return HTTP 402 with a base64
PAYMENT-REQUIRED
header. HTTP 503 is not a new quote: retry the same PAYMENT-SIGNATURE. Full handshake
and shared payment errors: Payments.
Stdio MCP: /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.