CarbonBench


A public leaderboard and open API ranking AI models, providers and regions by carbon per million tokens, next to cost and speed.

Status

Live at carbonbench.ai. Built in spring 2026, restored in November 2026; grid readings refresh every six hours. The findings are published in five essays.

RoleYearKindTry it
Concept, data design, engineering2026AI, climatecarbonbench.ai
46models on the live leaderboard
9cloud regions across the US, EU and Asia Pacific
4 vs 50+grams of CO2 per million tokens for the same model in two regions

The problem

The carbon cost of an AI inference call changes by an order of magnitude depending on where and when you make it. Pricing pages do not show this.

What I built

  • A leaderboard. Every model, provider and region ranked by carbon per million tokens, next to cost and speed. Each row opens a carbon curve for its region.
  • An open API. One endpoint answered one question: what is the lowest-carbon way to run this model right now? It returns the best option and four alternatives.
  • A scheduled pipeline. Every six hours a job pulls live grid data and recalculates every model, provider and region score.

How it is structured

Carbon per million tokens is energy per token multiplied by grid carbon intensity.

In the code

Private repository

These are short excerpts from Beach-Bum/CarbonBench, which is private.

rollup.ts
cleanup.ts
calculator.ts
electricity-maps.ts
ingest-hf-energy.ts
schema.prisma

This is a small codebase: about 600 lines of application code. Two pieces of it are worth reading.

The job that fixed the outage, and the bug I found in it. Readings older than seven days are folded into one row per region per day and the originals deleted, so storage stops growing. Re-reading it for this page, I saw the cutoff was "seven days before now", and the job runs at 03:00. So a day that straddled the cutoff was rolled up on two nights from two different sets of readings, and the second night's row replaced the first. Every daily figure was built without that day's readings from before 03:00.

The fix is one rule: the cutoff is always a midnight.

lib/rollup.ts
/**
 * Readings strictly before this instant are rolled up and pruned.
 *
 * It is always a UTC midnight. The old cutoff was `now - 7 days`, an instant
 * in the middle of a UTC day (03:00, when the job runs). That day was rolled
 * up on two consecutive nights from two disjoint sets of readings, and the
 * second write replaced the first. Cutting at midnight means a day is only
 * ever rolled up once all of it is older than the retention window.
 */
export function rollupCutoff(now: Date, retentionDays: number = RETENTION_DAYS): Date {
  return utcDayStart(new Date(now.getTime() - retentionDays * DAY_MS))
}

The job now takes one whole day at a time, oldest first, and writes that day's rows and deletes its readings together. It talks to storage through three methods, which is what lets the test below run the real logic with no database.

lib/rollup.ts
export async function runRollup(
  store: RollupStore,
  now: Date,
  retentionDays: number = RETENTION_DAYS
): Promise<{ cutoff: Date; rolledUp: number; pruned: number }> {
  const cutoff = rollupCutoff(now, retentionDays)
  let rolledUp = 0
  let pruned = 0

  for (;;) {
    const oldest = await store.oldestReadingBefore(cutoff)
    if (!oldest) break

    const dayStart = utcDayStart(oldest)
    const dayEnd = new Date(dayStart.getTime() + DAY_MS)
    // dayStart < cutoff and both are UTC midnights, so dayEnd <= cutoff:
    // the whole day is past retention.
    const readings = await store.readingsBetween(dayStart, dayEnd)
    if (readings.length === 0) break

    const { rows } = buildDailyRollups(readings, now, retentionDays)
    await store.commitDay(
      rows,
      readings.map((r) => r.id)
    )

    rolledUp += rows.length
    pruned += readings.length
  }

  return { cutoff, rolledUp, pruned }
}

The test runs the job on three consecutive nights over twelve days of readings and requires, each night, that every daily row equals the average, minimum and maximum of all four of that day's readings.

tests/rollup.test.ts
test('consecutive nights never produce a daily row from a partial day', async () => {
  const all = sixHourlyReadings('2026-03-01', 12) // 1 Mar .. 12 Mar
  const truth = truthByDay(all)
  const store = new MemoryStore([...all])

  const nights = ['2026-03-10T03:00:00.000Z', '2026-03-11T03:00:00.000Z', '2026-03-12T03:00:00.000Z']
  const expectedDaysAfter = [2, 3, 4] // 1-2 Mar, then 3 Mar, then 4 Mar

  for (let i = 0; i < nights.length; i++) {
    const now = new Date(nights[i])
    const { cutoff } = await runRollup(store, now)

    assertRowsMatchTruth(store, truth)
    assert.equal(store.daily.size, expectedDaysAfter[i] * REGIONS.length, `rows after night ${i + 1}`)

    // Nothing older than the cutoff is left, nothing newer was touched.
    assert.ok(store.readings.every((r) => r.recordedAt >= cutoff))
    assert.equal(store.readings.length, all.filter((r) => r.recordedAt >= cutoff).length)

    // No day is split between the two tables.
    for (const r of store.readings) {
      assert.ok(!store.daily.has(`${r.regionId}|${utcDayStart(r.recordedAt).toISOString()}`))
    }
  }
})

A companion test keeps the old logic to show the defect: it builds 3 March from three of its four readings.

This is written and tested, 19 tests in all, and live since 12 November 2026. The daily rows written before then stay wrong: the readings they were built from are gone.

The assumption every number rests on. The energy benchmark reports one figure for a whole run of a thousand prompts. Turning that into energy per token needs a token count the dataset does not give.

scripts/ingest-hf-energy.ts
// The benchmark runs 1000 text generation prompts
// total_gpu_energy is in kWh for the full run
// Convert to Wh per 1000 tokens (approximate: ~100 tokens per prompt avg)
function energyToWhPer1000Tokens(totalGpuEnergyKwh: number): number {
  const totalTokensApprox = 1000 * 100 // 1000 prompts × ~100 tokens each
  const totalWh = totalGpuEnergyKwh * 1000
  return (totalWh / totalTokensApprox) * 1000 // Wh per 1000 tokens
}

Every published figure depends on that 100: double it and every figure halves. It moves all models together, so the ranking between regions holds, but the absolute grams are an estimate and should be read as one. The same change gives the number a name and says this next to it.

Where the numbers come from

InputSourceRefreshed
Energy per tokenTwo sources in the repository: an import of the Hugging Face AI Energy Score results (GPU energy for text generation), and a hand-entered table of figures from the ML.Energy leaderboard, papers and provider documents, on mixed hardwareWhen a script is run
Grid carbonElectricity Maps, the latest carbon intensity for each cloud region's grid zoneEvery six hours
PriceProvider price lists, entered by scriptBy hand. A weekly job was planned and never built

The calculation is one multiplication: watt-hours per thousand tokens times grams of CO2 per kilowatt-hour gives grams of CO2 per million tokens. The units cancel in that step. The conversion that matters is one step earlier, in the import shown above.

The data model

Next.js 14 with Prisma on Postgres. Eight tables. Models, their energy benchmarks, regions, grid readings, daily roll-ups of those readings, provider prices, the combined scores, and email sign-ups. There is exactly one score for each model, region and provider, and it is overwritten in place; that rule is the fix described under "What broke".

Two scheduled jobs run: grid readings every six hours, and the clean-up nightly at 03:00.

What the numbers leave out

  • Only the GPU. Cooling and the rest of the data centre are not counted, so real emissions are higher than these figures.
  • Reference hardware, not the provider's. Energy was measured once per model on reference chips. A provider running different ones will differ.
  • The recommend endpoint was looser than its name. It matched a model by family name, so asking for "llama" returned the smallest Llama, and the saving it quoted was against the fifth-cleanest option, not the dirtiest. The carbon curve returned a region's oldest hundred readings, not its newest. Both were corrected in the same change: an exact model match first, the saving measured against the true highest option, and the newest readings.
  • The grid's average, not the provider's contract. A region's figure is its grid zone at that hour. Renewable purchase agreements are not reflected.
  • A day of frozen readings. For 20 hours after the November restore the job ran on schedule, reported success, and stored the same reading every time. The web framework caches outgoing requests by default and that cache outlives a deployment, so only the first poll reached the grid data provider. The request now bypasses the cache, and a reading already stored for the same hour is skipped. Nothing was watching for a reading that stops changing; that check is still missing.
  • Thin tests. 19, on the roll-up, the recommendation rule and the job's access check. None runs against a database. The findings are only as good as the three inputs above.

These limits change the absolute numbers. They do not change the finding, because every model in a region is affected the same way: where and when a model runs moves its carbon cost more than which model it is.

What the data showed

  • Region beats model. Llama 3.1 8B on Google Cloud in the Netherlands: about 4 grams of CO2 per million tokens. The same model in Virginia at peak: over 50. A 70B model on a clean grid can beat an 8B model on a dirty one.
  • Price and carbon are decoupled. Providers charge the same per token regardless of region. Routing for carbon is close to free.
  • Time matters. Grid intensity swings 30 to 50% over a day. Batch work that can wait can run at the clean hours.
  • It is an indirect emission. Every API call is an emission the customer cannot see. Activity-based accounting needs exactly these conversion factors.

Open questions

More

The leaderboard

46 models across nine cloud regions, ranked by carbon, cost and speed.

Open ↗
The five essays
Open ↗
Project notes on the weblog
Open ↗