Environmental impact metrics callback for LiteLLM
Project description
litellm-impacts
Environmental impact metrics callback for LiteLLM. Calculates and exposes carbon footprint metrics (energy consumption, CO2 emissions, resource depletion) for LLM API calls using the EcoLogits library.
Installation
pip install litellm-impacts
Or with uv:
uv add litellm-impacts
Usage
With LiteLLM Proxy (config.yaml)
litellm_settings:
callbacks: custom_callbacks.impacts_callback
model_list:
- model_name: gpt-4
litellm_params:
model: openai/gpt-4
Create custom_callbacks.py in the same directory:
from litellm_impacts import ImpactsCallback
impacts_callback = ImpactsCallback()
With LiteLLM Python SDK
import litellm
from litellm_impacts import ImpactsCallback
litellm.callbacks = [ImpactsCallback()]
response = litellm.completion(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
Configuration Options
from litellm_impacts import ImpactsCallback
callback = ImpactsCallback(
prefix="litellm", # Metric name prefix (default: "litellm")
server_port=8000, # Prometheus HTTP server port (default: 8000)
start_server=True, # Start built-in HTTP server (default: True)
labels=["model", "key_alias"], # Metric labels (default)
)
Set start_server=False if you're already running a Prometheus HTTP server or want to use a different metrics exposition method.
Metrics
The callback exposes the following Prometheus metrics (all with min/max variants):
| Metric | Description |
|---|---|
{prefix}_energy_kwh_min/max |
Energy consumption in kWh |
{prefix}_gwp_kgco2eq_min/max |
Global warming potential in kg CO2 equivalent |
{prefix}_adpe_kgsbeq_min/max |
Abiotic depletion potential in kg Sb equivalent |
{prefix}_pe_mj_min/max |
Primary energy in megajoules |
Labels:
model: The LLM model namekey_alias: The LiteLLM API key alias (if using proxy)
Supported Providers
Models are automatically matched to EcoLogits providers:
- OpenAI (gpt-, o1, o3, o4, chatgpt-)
- Anthropic (claude-*)
- Google (gemini-*)
- Mistral AI (mistral-, codestral-, pixtral-*)
- Cohere (command-*)
Models can also be specified with explicit provider prefixes (e.g., openai/gpt-4, anthropic/claude-3-sonnet).
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file litellm_impacts-0.1.0.tar.gz.
File metadata
- Download URL: litellm_impacts-0.1.0.tar.gz
- Upload date:
- Size: 168.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fb0f1f2b10f4ae70b14ac19e3559cca19939d2e9a353145dcf68bc6a09d34844
|
|
| MD5 |
29f769afb7cedff5bed46d1f49e9c963
|
|
| BLAKE2b-256 |
e10a32ec40809ecc7076c4a61930a50115f675ef7647208700989de7b6f9617f
|
Provenance
The following attestation bundles were made for litellm_impacts-0.1.0.tar.gz:
Publisher:
publish.yml on 252afh/litellm-impacts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litellm_impacts-0.1.0.tar.gz -
Subject digest:
fb0f1f2b10f4ae70b14ac19e3559cca19939d2e9a353145dcf68bc6a09d34844 - Sigstore transparency entry: 850017087
- Sigstore integration time:
-
Permalink:
252afh/litellm-impacts@cca5b270ba1a4c6cdf479dadbf6d0977cbed3ba2 -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/252afh
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cca5b270ba1a4c6cdf479dadbf6d0977cbed3ba2 -
Trigger Event:
release
-
Statement type:
File details
Details for the file litellm_impacts-0.1.0-py3-none-any.whl.
File metadata
- Download URL: litellm_impacts-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
738f8b8fc9922d95f22f21c4fa3083904e1a6b1b48857940b2cc0a5cfb6bb36e
|
|
| MD5 |
1423d183263e38a2fa9106e5541f169e
|
|
| BLAKE2b-256 |
ecf66a97b15a5b8d602b0400ecd77ed9972f0b0ae03e879ad65da6d75cbcea4b
|
Provenance
The following attestation bundles were made for litellm_impacts-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on 252afh/litellm-impacts
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
litellm_impacts-0.1.0-py3-none-any.whl -
Subject digest:
738f8b8fc9922d95f22f21c4fa3083904e1a6b1b48857940b2cc0a5cfb6bb36e - Sigstore transparency entry: 850017090
- Sigstore integration time:
-
Permalink:
252afh/litellm-impacts@cca5b270ba1a4c6cdf479dadbf6d0977cbed3ba2 -
Branch / Tag:
refs/tags/0.0.1 - Owner: https://github.com/252afh
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@cca5b270ba1a4c6cdf479dadbf6d0977cbed3ba2 -
Trigger Event:
release
-
Statement type: