Skip to content

Commit e3bb7b1

Browse files
authored
Merge pull request #1164 from hamza-mobeen/docs/co2-signal-token-403
docs: explain electricitymaps_api_token and query behaviour
2 parents 9c7b216 + 6d08798 commit e3bb7b1

1 file changed

Lines changed: 38 additions & 0 deletions

File tree

docs/how-to/configuration.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,44 @@ Yields attributes:
8484
which relies on the [INI
8585
syntax](https://docs.python.org/3/library/configparser.html#supported-ini-file-structure).
8686

87+
## Electricity Maps API Token
88+
89+
By default, CodeCarbon estimates carbon intensity using annual country-level
90+
averages from Our World in Data. Providing an `electricitymaps_api_token`
91+
upgrades this to **real-time carbon intensity** data from the
92+
[Electricity Maps API](https://api.electricitymaps.com), giving more accurate
93+
emissions figures — especially useful if your grid's energy mix varies
94+
throughout the day.
95+
96+
**Without a token:** CodeCarbon uses a static annual average for your country.
97+
98+
**With a token:** CodeCarbon queries the Electricity Maps API for the current
99+
carbon intensity of your grid. The query runs at the end of each tracking run,
100+
and also periodically during long runs (every
101+
`api_call_interval × measure_power_secs` seconds; default: every ~2 minutes).
102+
103+
The Electricity Maps API offers a free tier. You can sign up and get a token at
104+
[electricitymaps.com](https://app.electricitymaps.com/sign-up).
105+
106+
Set it in your config file:
107+
108+
``` ini
109+
[codecarbon]
110+
electricitymaps_api_token = your-token-here
111+
```
112+
113+
Or in code:
114+
115+
``` python
116+
EmissionsTracker(electricitymaps_api_token="your-token-here")
117+
```
118+
119+
!!! note "Deprecated parameter"
120+
121+
The old parameter name `co2_signal_api_token` still works for backward
122+
compatibility but is deprecated and will be removed in a future version.
123+
Use `electricitymaps_api_token` instead.
124+
87125
## Access internet through proxy server
88126

89127
If you need a proxy to access internet, which is needed to call a Web

0 commit comments

Comments
 (0)