Inspiration
AI is a climate problem nobody prices. Training GPT-3 emitted 552 metric tons of CO2 — the equivalent of flying a jumbo jet across the Atlantic 300 times. A single ChatGPT query uses about 10 times the energy of a Google search. And here's the overlooked part: when and where you run that workload matters enormously. At 3 PM in West Virginia, the grid is 72% coal. At 3 AM in Washington state, it's 84% hydropower. Same workload, 30 times more carbon. No API gateway today checks this. We built one that does. What it does Carbon Trust Engine is a pollution-budgeted API gateway for AI workloads. Every US state gets a daily CO2 token budget derived from live EIA grid data. Users get a fair share via the Max-Min Fairness algorithm. Each API request costs tokens scaled by real-time grid intensity — a training call during a dirty hour costs three times more tokens than the same call on a clean hour. When a request is blocked, users don't just see a 429 error — they get live migration suggestions pointing them to cleaner states. This turns carbon from a filter into a market: dirty regions get priced out of AI compute, and clean regions become compute hubs.
What it does
Carbon Trust Engine is a pollution-budgeted API gateway for AI workloads. Every US state gets a daily CO2 token budget derived from live EIA grid data. Users get a fair share via the Max-Min Fairness algorithm. Each API request costs tokens scaled by real-time grid intensity — a training call during a dirty hour costs three times more tokens than the same call on a clean hour. When a request is blocked, users don't just see a 429 error — they get live migration suggestions pointing them to cleaner states. This turns carbon from a filter into a market: dirty regions get priced out of AI compute, and clean regions become compute hubs.
How we built it
The data layer uses the US EIA API v2, specifically the electricity/rto/fuel-type-data endpoint, which provides hourly generation mix for every balancing authority in the US. We hit this single endpoint three different ways: a daily Oracle that pulls a 24-hour window to set each state's token cap, an Intensity Cache that refreshes every 5 minutes for real-time per-request pricing, and an on-demand dashboard query for ranking states. Carbon intensity is computed from fuel mix using IPCC AR5 lifecycle emission factors — coal at 820 gCO2/kWh down to wind at 11. The backend is Flask with a SQLite ledger using WAL mode and atomic BEGIN IMMEDIATE transactions. We verified that 50 concurrent threads racing the same account never double-spend — token conservation holds under chaos. Token allocation uses Max-Min Fairness, the same algorithm TCP uses to share bandwidth across flows. The frontend is React with live progress rings, threshold alerts at 50%/80%/95%, spend velocity tracking, and a real-time bar chart of all 10 states.
Challenges we ran into
The biggest one was guaranteeing atomic token spend under concurrent load. A naive read-then-write approach silently allows double-spends. We solved it with SQLite's BEGIN IMMEDIATE isolation and wrote a stress test that spawns 50 threads all racing to spend from a 20-token account — exactly 20 must succeed, 30 must fail. It took several iterations to get right. The second was handling EIA's inconsistent publish lag. Different balancing authorities publish with different delays, sometimes 2 hours, sometimes 17. Our parser groups rows by period and picks the newest hour with at least 2 fuel types reported, degrading gracefully when data is stale. The third was designing fair resource allocation. Our first version was uniform-at-dawn, but it left idle users sitting on tokens while active users got blocked. Switching to Max-Min Fairness with bounded drip from a shared reserve solved it cleanly — and it's an algorithm with real academic backing.
Accomplishments that we're proud of
Live integration with real US government data powering every decision. 87 automated tests passing, including brutal concurrency tests that prove economic correctness. Full end-to-end flow: register → fair share grant → live-priced request → blocked with migration suggestions. React dashboard that updates every 5 seconds and shows the entire economic state of the system.
What we learned
Real-time energy data has deep nuances — imports across balancing authorities distort pure fuel-mix intensity calculations, battery discharge shows as negative MWh, some BAs publish nearly in real time while others lag by hours. Classic CS algorithms like Max-Min Fairness translate remarkably well from bandwidth to novel resources like carbon budgets. SQLite is far more capable than people give it credit for — WAL mode plus proper transaction isolation gives you real ACID guarantees in a single file.
What's next for The Carbon Tokenizer
Cloud deployment for public access. Proxying real ML workloads through the gateway as carbon-aware middleware. Multi-BA state support so California's CAISO, BPAT, and WALC regions are modeled accurately. And the most exciting one: an inter-state token market where clean-grid users can sell excess tokens to dirty-grid users at a premium, creating real economic pressure to migrate workloads.
Log in or sign up for Devpost to join the conversation.