LIVE
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
- Title
- "Ideal" alveolar air and the analysis of ventilation-perfusion relationships in the lungs
- 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
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
x402 V2 curl
Expect HTTP 402 and a PAYMENT-REQUIRED
header until you retry with PAYMENT-SIGNATURE. Incomplete query params return HTTP
400 before any quote or charge. HTTP 503 after a signature: retry the same
PAYMENT-SIGNATURE
— that is not a new 402.
curl -i -H "Accept: application/json" "https://api.magentlab.com/api/calc/aa_gradient?paco2_mm_hg=40&pao2_mm_hg=95"
Cursor mcp.json
Intended config for @magent/mcp. This is not npm @x402/fetch
(a payment fetch wrapper).
{
"mcpServers": {
"magent": {
"args": [
"-y",
"@magent/mcp"
],
"command": "npx",
"env": {
"X402_PRIVATE_KEY": "0xYOUR_SPENDING_KEY"
}
}
}
}
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. Price is n times the GET unit. Invalid items return HTTP 400 before settlement.
- 1 to 25 items. Each item uses the same keys as the GET query parameters.
- 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.",
"aa_gradient_mm_hg": 4.7,
"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"
},
"fio2": 0.21,
"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,
"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.",
"aa_gradient_mm_hg": 4.7,
"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"
},
"fio2": 0.21,
"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,
"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.",
"aa_gradient_mm_hg": 4.7,
"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"
},
"fio2": 0.21,
"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,
"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
}
Errors
| 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. |
| 402 | payment_required |
Missing or invalid PAYMENT-SIGNATURE; decode the PAYMENT-REQUIRED header |
| 409 | payment_in_progress |
The same authorization nonce is already being settled; retry shortly |
| 429 | rate_limited |
Too many requests from this client |
| 503 | settlement_uncertain |
Settlement is unconfirmed; retry with the same PAYMENT-SIGNATURE |
| 503 | settle_failed |
Settlement failed; retry with the same PAYMENT-SIGNATURE shortly |
| 503 | facilitator_unavailable |
Payment facilitator unavailable |
| 503 | facilitator_misconfigured |
Payment facilitator is not configured |
| 503 | facilitator_unauthorized |
Payment facilitator rejected credentials |
| 503 | ledger_unavailable |
Payment ledger unavailable |
| 503 | payment_unavailable |
Payment processing unavailable |
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.
Also searched as
- A-a gradient
- A-a O2
- alveolar-arterial oxygen gradient
- alveolar gas equation
- PAO2 minus PaO2
- A-a O2 gradient
Payment
Required query parameters must be present and valid. 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.
Guarantees
- Invalid query parameters return HTTP 400 before settlement. You are not charged.
- Settlement finishes before the tool executes (paymentFlow upfront). 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.