# BeAM (bedtime minus AM glucose)

BeAM

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

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

## What it computes

Compute BeAM as bedtime glucose minus pre-breakfast (AM) glucose in mg/dL and return the Zisman 2016 analysis category (<0, 0-50, or >50).

## When to use

When an agent needs the published BeAM difference and must not invent a 45 or 55 mg/dL cutoff, order prandial insulin, or diagnose diabetes.

## When not to use

- Not a medical device. magent does not diagnose diabetes or order prandial insulin.
- Zisman 2016 analysis categories only: <0, 0-50, and >50 mg/dL. A 45–55 mg/dL range to consider additional intervention is not a hard cutoff in this tool.
- Glucose is caller-supplied. magent does not measure capillary or laboratory glucose.

## Formula

```
beam_mg_dl = bedtime_glucose_mg_dl - am_glucose_mg_dl; mmol/L × 18 → mg/dL; band <0 if beam_mg_dl < 0, 0-50 if 0 <= beam_mg_dl <= 50, >50 if beam_mg_dl > 50
```

## Citation

[BeAM value: an indicator of the need to initiate and intensify prandial therapy in patients with type 2 diabetes mellitus receiving basal insulin](https://doi.org/10.1136/bmjdrc-2015-000171)
Zisman A, Morales F, Stewart J, Stuhr A, Vlajnic A, Zhou R
BMJ Open Diabetes Res Care. 2016;4(1):e000171
DOI: [10.1136/bmjdrc-2015-000171](https://doi.org/10.1136/bmjdrc-2015-000171)

## Worked example

### Bedtime 180 mg/dL, AM 120 mg/dL

Given: `am_glucose_mg_dl=120, bedtime_glucose_mg_dl=180`

1. BeAM = 180 − 120 = 60.0 mg/dL
2. 60.0 > 50 → band >50. Not a prandial insulin order.


### Bedtime 10.0 mmol/L, AM 6.67 mmol/L

Given: `am_glucose_mmol_l=6.67, bedtime_glucose_mmol_l=10.0`

1. mg/dL = 10.0 × 18 = 180.0; 6.67 × 18 = 120.06
2. BeAM = 180.0 − 120.06 = 59.94 → 59.9 mg/dL, band >50


## Also searched as

- BeAM value
- bedtime minus AM glucose
- BeAM Zisman
- bedtime AM differential
- pre-breakfast glucose gap
- BeAM type 2 diabetes
- basal insulin BeAM

## Parameters

- `bedtime_glucose_mg_dl` (number, optional): Bedtime glucose in mg/dL (40-600). Provide this or bedtime_glucose_mmol_l, not both. Independent of the AM unit.
- `bedtime_glucose_mmol_l` (number, optional): Bedtime glucose in mmol/L (2.2-33.3). Converted as mg/dL = mmol/L × 18 (same factor as HOMA-IR). Provide this or bedtime_glucose_mg_dl, not both.
- `am_glucose_mg_dl` (number, optional): Pre-breakfast (AM) glucose in mg/dL (40-600). Provide this or am_glucose_mmol_l, not both. Independent of the bedtime unit.
- `am_glucose_mmol_l` (number, optional): Pre-breakfast (AM) glucose in mmol/L (2.2-33.3). Converted as mg/dL = mmol/L × 18. Provide this or am_glucose_mg_dl, 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/beam`
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": [
    {
      "am_glucose_mg_dl": "120",
      "bedtime_glucose_mg_dl": "180"
    },
    {
      "am_glucose_mg_dl": "120",
      "bedtime_glucose_mg_dl": "180"
    }
  ]
}
```

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

Example 200:

```json
{
  "count": 2,
  "path": "/api/calc/beam",
  "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": "Zisman A, Morales F, Stewart J, Stuhr A, Vlajnic A, Zhou R",
        "doi": "10.1136/bmjdrc-2015-000171",
        "id": "zisman-2016",
        "pmid": "27110368",
        "source": "BMJ Open Diabetes Res Care. 2016;4(1):e000171",
        "title": "BeAM value: an indicator of the need to initiate and intensify prandial therapy in patients with type 2 diabetes mellitus receiving basal insulin"
      },
      "formula": "beam",
      "formula_expression": "beam_mg_dl = bedtime_glucose_mg_dl - am_glucose_mg_dl; mmol/L × 18 → mg/dL; band <0 if beam_mg_dl < 0, 0-50 if 0 <= beam_mg_dl <= 50, >50 if beam_mg_dl > 50",
      "beam_band": ">50",
      "am_glucose_mg_dl": 120.0,
      "beam_mg_dl": 60.0,
      "bedtime_glucose_mg_dl": 180.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": "Zisman A, Morales F, Stewart J, Stuhr A, Vlajnic A, Zhou R",
        "doi": "10.1136/bmjdrc-2015-000171",
        "id": "zisman-2016",
        "pmid": "27110368",
        "source": "BMJ Open Diabetes Res Care. 2016;4(1):e000171",
        "title": "BeAM value: an indicator of the need to initiate and intensify prandial therapy in patients with type 2 diabetes mellitus receiving basal insulin"
      },
      "formula": "beam",
      "formula_expression": "beam_mg_dl = bedtime_glucose_mg_dl - am_glucose_mg_dl; mmol/L × 18 → mg/dL; band <0 if beam_mg_dl < 0, 0-50 if 0 <= beam_mg_dl <= 50, >50 if beam_mg_dl > 50",
      "beam_band": ">50",
      "am_glucose_mg_dl": 120.0,
      "beam_mg_dl": 60.0,
      "bedtime_glucose_mg_dl": 180.0
    }
  ]
}
```

## Response fields

- `formula` (string): beam
- `formula_expression` (string): Exact expression used
- `bedtime_glucose_mg_dl` (number): Bedtime glucose in mg/dL (mmol/L × 18 when supplied as mmol/L), 1 decimal
- `am_glucose_mg_dl` (number): Pre-breakfast glucose in mg/dL (mmol/L × 18 when supplied as mmol/L), 1 decimal
- `beam_mg_dl` (number): BeAM in mg/dL (bedtime minus AM), 1 decimal
- `beam_band` (string): Zisman 2016 analysis category: <0, 0-50, or >50 mg/dL. 0 and 50 are 0-50. Not a 45 or 55 cutoff.
- `citation` (object): Zisman et al. 2016 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": "Zisman A, Morales F, Stewart J, Stuhr A, Vlajnic A, Zhou R",
    "doi": "10.1136/bmjdrc-2015-000171",
    "id": "zisman-2016",
    "pmid": "27110368",
    "source": "BMJ Open Diabetes Res Care. 2016;4(1):e000171",
    "title": "BeAM value: an indicator of the need to initiate and intensify prandial therapy in patients with type 2 diabetes mellitus receiving basal insulin"
  },
  "formula": "beam",
  "formula_expression": "beam_mg_dl = bedtime_glucose_mg_dl - am_glucose_mg_dl; mmol/L × 18 → mg/dL; band <0 if beam_mg_dl < 0, 0-50 if 0 <= beam_mg_dl <= 50, >50 if beam_mg_dl > 50",
  "beam_band": ">50",
  "am_glucose_mg_dl": 120.0,
  "beam_mg_dl": 60.0,
  "bedtime_glucose_mg_dl": 180.0
}
```

## Errors

- HTTP 400 `invalid_beam`: BeAM needs bedtime and pre-breakfast glucose (each as mg/dL or mmol/L), as used in Zisman 2016. Returned before settlement; you are not charged.
- HTTP 400 `invalid_bedtime_glucose`: bedtime_glucose_mg_dl (40-600) or bedtime_glucose_mmol_l (2.2-33.3) is required. Returned before settlement; you are not charged.
- HTTP 400 `invalid_am_glucose`: am_glucose_mg_dl (40-600) or am_glucose_mmol_l (2.2-33.3) is required. 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

- [HOMA-IR](https://magentlab.com/docs/homa-ir) — Compute the Matthews 1985 HOMA-IR approximation from fasting plasma glucose and insulin.
- [A1C ↔ eAG](https://magentlab.com/docs/a1c-eag) — Convert A1C percent to estimated average glucose, or the reverse, using Nathan/ADAG.
- [Bang diabetes screening](https://magentlab.com/docs/ada-diabetes) — Sum the Bang 2009 Table 2 development screening score for undiagnosed diabetes and return high_risk when the total is ≥5.

## 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.
