CodeCarbon API¶
API mode
This mode uses the CodeCarbon API to upload the timeseries of your emissions on a central server.
Thanks to CleverCloud the use of API is free as soon as it remains under certain limits.


Before using it, you need to create an account on the CodeCarbon dashboard
Then login from your terminal:
codecarbon login
It will create an experiment_id for the default project and save it to
codecarbon.config
Then you can tell CodeCarbon to monitor your machine:
codecarbon monitor
Or use the API in your code:
from codecarbon import track_emissions
@track_emissions(save_to_api=True)
def train_model():
# GPU intensive training code goes here
if __name__ =="__main__":
train_model()
More options could be specified in @track_emissions or in
.codecarbon.config
The CodeCarbon dashboard use CodeCarbon API to get the data
The API do not have a nice web interface to create your own organization and project, you have to use OpenAPI interface for that.
And so on for your team, project and experiment.
You then have to set your experiment id in CodeCarbon, with two options:
In the code:
from codecarbon import track_emissions
@track_emissions(
measure_power_secs=30,
api_call_interval=4,
experiment_id="your experiment id",
save_to_api=True,
)
def train_model():
...
Or in the config file .codecarbon.config:
[codecarbon]
experiment_id = your experiment id
save_to_api = true