mlco2/ecologits-api 是一个托管在 GitHub 上的开源项目,主要使用 Python 编写,采用 GNU Affero General Public License v3.0 许可证,目前获得 11 个 Star、1 次 Fork。
仓库全名
mlco2/ecologits-api
README 摘要
Ecologits API An API to estimate the environmental impacts of LLM generation requests. Part of EcoLogits, maintained by the Code Carbon non-profit. Live docs: api.ecologits.ai/docs Local compute? See CodeCarbon. GenAI API calls? Use pip install ecologits instead. Quick try The API uses EcoLogits 0.11.3 and exposes estimation and catalog routes under /v1beta. Use GET /health for a lightweight health check; it returns…
The API uses EcoLogits 0.11.3 and exposes estimation and catalog routes under /v1beta. Use GET /health for a lightweight health check; it returns HTTP 200 with {"status":"ok"} when the API is running.
Run API without Docker
Requires Python 3.11 or newer.
Install the project’s locked dependencies using uv (uv sync --locked --no-dev)
Start the app using the following command: uv run --locked --no-dev fastapi dev app/main.py
The image runs as a non-root user (UID/GID 10001) and listens on 0.0.0.0:8000. Python logs are unbuffered. It includes application code and runtime dependencies; uv, Ruff, pytest, and local .env files are excluded. Pass configuration with Docker’s -e or --env-file options.
Use published image
Start container with: docker run -p 8000:8000 ghcr.io/mlco2/ecologits-api:latest
Expect HTTP 200 with {"status":"ok"}. This unversioned endpoint confirms the API is responding without running an estimation or calling external services. Configure your platform’s HTTP probe to use /health on container port 8000.
Deploy on your own infrastructure
See the deployment guide for a simple guide to running the API on your company’s infrastructure.
Estimating environmental impacts
Use the /v1beta/estimations endpoint to estimate the environmental impacts of your LLM generation requests by providing:
Provider name (e.g., “openai”)
Model name (e.g., “gpt-4o-mini”)
Output token count
Request latency (optional)
Electricity mix zone (optional, defaults to “WOR”)
Install the project’s locked dependencies, including Ruff and pytest: uv sync --locked --group dev.
Run all tests: uv run --locked --no-sync pytest.
Check a locally built Docker image: bash .github/scripts/check-container.sh ecologits-api.
CI runs the tests on Python 3.11 and 3.13, lints the Dockerfile with Hadolint, and builds and checks the production container on pull requests and pushes to main. Release tags run the same checks before publishing images for linux/amd64 and linux/arm64. Clever Cloud deployment follows successful checks on main.
评论