Expand description
Electricity-footprint estimate for saved tokens.
This mirrors the website /metrics methodology (same J_PER_TOKEN) so a user’s local
“energy saved” figure and the community scoreboard always reconcile.
~0.4 J per saved token is a deliberately conservative midpoint of measured modern inference (Llama-3-70B FP8 on H100 + vLLM ≈ 0.39 J/token, John Snow Labs “Tokens per Joule”, 2025; query-level estimates such as Epoch AI’s ~0.3 Wh per GPT-4o query imply more). lean-ctx mostly removes cheaper prefill/context tokens, so we never overstate. Real figures vary by model and hardware — this is always surfaced as an estimate.
Constants§
- G_
CO2_ PER_ KWH - Grams of CO₂-equivalent per kWh of grid electricity. ~475 g/kWh is the global
average grid carbon intensity (IEA, ~2023) — a transparent, conservative
midpoint. Users on cleaner grids can override via
LEAN_CTX_GRID_CO2_G_PER_KWHso the local footprint reflects their actual electricity mix. - J_
PER_ TOKEN - Joules of inference compute avoided per token that lean-ctx kept out of the context.
- WH_
PER_ PHONE_ CHARGE - Watt-hours in a full smartphone charge — the relatable yardstick used in the UI.
Functions§
- co2_
grams_ for_ tokens - Grams of CO₂-equivalent avoided for a given number of saved tokens.
g = Wh / 1000 · gridIntensity. - format_
co2 - Human-readable CO₂ mass with adaptive units (
g/kg/t). - format_
co2_ for_ tokens - Convenience: formatted CO₂ string straight from a saved-token count.
- format_
for_ tokens - Convenience: formatted energy string straight from a saved-token count.
- format_
wh - Human-readable energy with adaptive units (
Wh/kWh/MWh). - grid_
co2_ g_ per_ kwh - Effective grid carbon intensity (g CO₂/kWh), honoring the
LEAN_CTX_GRID_CO2_G_PER_KWHoverride when it is a positive, finite number. - phone_
charges - Equivalent number of full smartphone charges for a given saved-token count.
- phone_
charges_ hint - Rounded phone-charge equivalent as a display string (e.g.
"≈ 117 phone charges"), orNonewhen the saving is too small to round to at least one charge. - wh_
for_ tokens - Energy (Wh) saved for a given number of saved tokens.
Wh = tokens · J/token / 3600.