Skip to content

Tutorial

The 🌱 EcoLogits library tracks the energy consumption and environmental impacts of generative AI models accessed through APIs and their official client libraries.

It achieves this by patching the Python client libraries, ensuring that each API request is wrapped with an impact calculation function. This function computes the environmental impact based on several request features, such as the chosen model, the number of tokens generated, and the request's latency. The resulting data is then encapsulated in an Impacts object, which is added to the response, containing the environmental impacts for a specific request.

  • Set up in 5 minutes


    Install ecologits with pip and get up and running in minutes.

    Getting started

  • Environmental impacts


    Understand what environmental impacts and phases are reported.

    Tutorial

  • Supported providers


    List of providers and tutorials on how to make requests.

    Providers

  • Methodology


    Understand how we estimate environmental impacts.

    Methodology

Initialization of EcoLogits

To use EcoLogits in your projects, you will need to initialize the client tracers that are used internally to intercept and enrich responses. The default initialization will use default parameters and enable tracking of all available providers. To change that behaviour, read along on how to configure EcoLogits.

from ecologits import EcoLogits

# Default initialization method
EcoLogits.init()

Configure providers

You can select which provider to enable with EcoLogits using the providers parameter.

Default behavior is to enable all available providers.

Select a providers to enable
from ecologits import EcoLogits

# Examples on how to enable one or multiple providers
EcoLogits.init(providers="openai")
EcoLogits.init(providers=["anthropic", "mistralai"])
Disabling a provider at runtime is not supported

It is currently not possible to dynamically activate and deactivate a provider at runtime. Each time that EcoLogits is re-initialized with another providers, the latter will be added to the list of already initialized providers. If you think that un-initializing a provider could be necessary for your use case, please open an issue ."

Configure electricity mix

You can change the electricity mix for server-side computation depending on a specific location. EcoLogits will automatically change the default impact factors for electricity consumption according to the selected zone.

Available zones are listed in the electricity_mixes.csv file and are based on the ISO 3166-1 alpha-3 convention with some extras like WOR for World or EEE for Europe.

Electricity mixes for each geographic zone are sourced from the ADEME Base Empreinte® database and are based on yearly averages.

Default electricity mix zone is WOR for World.

Select a different electricity mix
from ecologits import EcoLogits

# Select the electricity mix of France
EcoLogits.init(electricity_mix_zone="FRA")