CoolFace
Apppublic

Piloterra/ai-co2-estimation

sourceHugging Faceupdated 7mo agoView on Hugging Face
0likes
App README

AI CO2 Estimation API

Estimate the carbon footprint of AI/LLM usage and get tangible ADEME equivalences.

Built with FastAPI and ecologits.

Quick start (local)

bash
pip install -r requirements.txt
uvicorn app.main:app --reload --port 7860

Interactive docs are available at http://localhost:7860/docs.

Cloud deployment

The API is also available in the cloud at:

  • https://piloterra-ai-co2-estimation.hf.space/estimate

You can call the same POST /estimate endpoint on this URL without running anything locally.

API

POST /estimate

Estimate the carbon impact of a single LLM request.

Request body:

json
{
  "provider": "openai",
  "model": "gpt-4o",
  "output_tokens": 500,
  "request_latency": 1.2
}
FieldTypeRequiredDescription
providerstringyesLLM provider (openai, mistralai, anthropic...)
modelstringyesModel name as known by the provider
output_tokensintyesNumber of generated tokens (> 0)
request_latencyfloatyesRequest latency in seconds (> 0)

Response (200):

json
{
  "status": "ok",
  "data": {
    "gwp_avg_kgco2eq": 0.002,
    "gwp_min_kgco2eq": 0.001,
    "gwp_max_kgco2eq": 0.003,
    "gwp_gco2eq": 2.0,
    "energy_kwh": 0.015,
    "equivalences": {
      "car_km": 0.009132,
      "tgv_km": 0.682594,
      "water_liters": 0.006231,
      "smartphone": 0.000023
    }
  },
  "warnings": [],
  "errors": []
}

GET /health

Returns {"status": "ok"}.

Running tests

bash
pip install -r requirements.txt
pytest tests/ -v

Docker

bash
docker build -t ai-co2-estimation .
docker run -p 7860:7860 ai-co2-estimation

Equivalence ratios (ADEME)

Source: Impact CO2

EquivalenceRatio (per kgCO2eq)Source unit
Car4.566210 km219 gCO2/km
TGV341.296928 km2.93 gCO2/km
Tap water3.115265 L321 gCO2/L
Smartphone0.011643 units85.9 kgCO2/unit