Skip to main content

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 name
  • key_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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

litellm_impacts-0.1.0.tar.gz (168.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

litellm_impacts-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

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

Hashes for litellm_impacts-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fb0f1f2b10f4ae70b14ac19e3559cca19939d2e9a353145dcf68bc6a09d34844
MD5 29f769afb7cedff5bed46d1f49e9c963
BLAKE2b-256 e10a32ec40809ecc7076c4a61930a50115f675ef7647208700989de7b6f9617f

See more details on using hashes here.

Provenance

The following attestation bundles were made for litellm_impacts-0.1.0.tar.gz:

Publisher: publish.yml on 252afh/litellm-impacts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file litellm_impacts-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for litellm_impacts-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 738f8b8fc9922d95f22f21c4fa3083904e1a6b1b48857940b2cc0a5cfb6bb36e
MD5 1423d183263e38a2fa9106e5541f169e
BLAKE2b-256 ecf66a97b15a5b8d602b0400ecd77ed9972f0b0ae03e879ad65da6d75cbcea4b

See more details on using hashes here.

Provenance

The following attestation bundles were made for litellm_impacts-0.1.0-py3-none-any.whl:

Publisher: publish.yml on 252afh/litellm-impacts

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page