Getting started overview
The UK Carbon Intensity API provides programmatic access to a dataset detailing the carbon intensity of Great Britain's electricity system. This data includes real-time values, which are updated every 30 minutes, and forecasts extending up to 96 hours into the future, updated every 30 minutes. The API is designed for developers, researchers, and organizations that require insights into the environmental impact of electricity generation and consumption patterns in the UK.
Integrating with the UK Carbon Intensity API involves directly querying its endpoints. Unlike many APIs, it does not require an API key, account registration, or any form of authentication. This simplifies the onboarding process, allowing immediate data retrieval and integration into applications, dashboards, or research models. The API structure is RESTful, returning data in JSON format, which is a standard data interchange format for web services, making it compatible with most programming languages and development environments. For detailed information on available endpoints and data structure, consult the UK Carbon Intensity data API documentation.
The API is maintained by National Grid ESO in partnership with Environmental Defense Fund Europe and WWF. The project aims to provide transparent data to help reduce carbon emissions. The data reflects the carbon emissions associated with generating each unit of electricity consumed in Great Britain, calculated based on the generation mix at a given time.
Quick Reference Guide
| Step | What to do | Where |
|---|---|---|
| 1 | Review API documentation | UK Carbon Intensity Data API |
| 2 | Formulate your API request | Refer to API endpoints for real-time or forecasted data |
| 3 | Make a GET request |
Using curl, Python requests, JavaScript fetch, etc. |
| 4 | Process the JSON response | Parse the data in your application |
| 5 | Handle potential errors | Check HTTP status codes and response body for error messages |
Create an account and get keys
The UK Carbon Intensity API operates without user accounts or API keys. This means there is no registration process required to begin using the service. Developers can initiate requests to the API endpoints immediately upon identifying the data they need. This design choice removes common friction points associated with API onboarding, such as managing credentials, adhering to rate limits based on API keys, or handling authorization flows like OAuth 2.0. The absence of authentication simplifies the implementation of applications that consume carbon intensity data, as it eliminates the need for secure storage of API keys or complex access token management. This approach aligns with the project's goal of making carbon data widely accessible for public benefit and research.
While the API does not require keys, users are still expected to adhere to reasonable usage policies to ensure service availability for all. Although specific rate limits are not extensively documented given the non-authenticated nature, following standard API consumption best practices, such as implementing exponential backoff for retries and avoiding excessively rapid requests, is advisable. For applications requiring high-frequency data access or large-scale data processing, it is recommended to review the official UK Carbon Intensity documentation for any updates on usage guidelines or directly contact the project organizers if specific high-volume use cases are planned. This ensures continued access and responsible use of the public data resource.
Your first request
To make your first request to the UK Carbon Intensity API, you will target one of its public endpoints. We will demonstrate how to retrieve the current carbon intensity for Great Britain. This example uses curl, a common command-line tool for making HTTP requests.
Endpoint for Current Intensity
The endpoint for retrieving the current carbon intensity is /intensity. When queried, this endpoint provides the latest carbon intensity data for the entire Great Britain region.
Example Request (curl)
Open your terminal or command prompt and execute the following curl command:
curl -X GET "https://api.carbonintensity.org.uk/intensity"
This command sends an HTTP GET request to the specified URL. The -X GET flag explicitly sets the request method, though it's often optional for GET requests with curl.
Example Response
A successful response will return a JSON object containing an array of data, typically looking like this:
{
"data": [
{
"from": "2026-05-29T10:00Z",
"to": "2026-05-29T10:30Z",
"intensity": {
"forecast": 195,
"actual": 188,
"index": "moderate"
}
}
]
}
In this response:
fromandtoindicate the time window for the data.intensity.forecastis the predicted carbon intensity in grams of CO2 per kWh (gCO2/kWh).intensity.actualis the observed carbon intensity in gCO2/kWh.intensity.indexprovides a categorical description (e.g., "very low", "low", "moderate", "high", "very high").
Example Request (Python)
For Python developers, the requests library is a common choice for making HTTP requests:
import requests
import json
url = "https://api.carbonintensity.org.uk/intensity"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print(json.dumps(data, indent=2))
else:
print(f"Error: {response.status_code} - {response.text}")
This Python script fetches the current intensity data, parses the JSON response, and prints it in a human-readable format.
Example Request (JavaScript using fetch)
For client-side web applications or Node.js environments, the fetch API can be used:
fetch('https://api.carbonintensity.org.uk/intensity')
.then(response => {
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
return response.json();
})
.then(data => {
console.log(JSON.stringify(data, null, 2));
})
.catch(error => {
console.error('Fetch error:', error);
});
This JavaScript example demonstrates how to make an asynchronous request and handle the JSON response or any potential network errors. The fetch API is widely supported by modern web browsers and Node.js versions.
Common next steps
After successfully retrieving your first set of carbon intensity data, you can explore various ways to integrate this information into your projects. These steps often involve expanding your data queries, implementing data processing, and considering the application context.
-
Explore additional endpoints: The UK Carbon Intensity API offers more than just current data. You can retrieve forecasted data for specific regions, historical data, and data for different time periods. For instance, to get the carbon intensity for a specific region like the South East (SE), you could use an endpoint like
/intensity/regions/SE. Refer to the API documentation for a full list of available region codes and endpoints. -
Process and visualize data: Once you retrieve the JSON data, you'll need to parse it within your application. This often involves extracting specific values like
forecast,actual, andindex. You might then use this data to create visualizations (e.g., charts showing intensity over time), trigger actions based on intensity levels (e.g., delaying energy-intensive tasks during high carbon periods), or display the information in a user interface. -
Integrate with other services: Carbon intensity data can be combined with other APIs or services. For example, you might integrate it with an IoT platform to control smart devices based on real-time carbon emissions, or with a weather API to analyze correlations between weather patterns and energy demand/carbon intensity. Consider how this data can enrich existing applications or enable new environmentally-focused features.
-
Handle time series data: Many applications will benefit from querying historical or forecasted data over a range of time. The API supports queries for specific periods, such as
/intensity/2026-05-28T12:00Z/2026-05-28T14:00Zfor two hours of historical data. Understanding how to structure these time-based queries is crucial for building robust applications that track trends or plan future energy usage. -
Error handling and robustness: While the API is generally reliable, implement proper error handling in your code. This includes checking HTTP status codes (e.g.,
200 OKfor success,4xxfor client errors,5xxfor server errors) and gracefully handling cases where data might be missing or malformed. Implementing retry logic with an exponential backoff strategy can improve the resilience of your integration. -
Monitor for updates: The underlying data and the API itself may evolve. It's good practice to periodically check the official documentation or news from the UK Carbon Intensity project homepage for updates on new features, deprecations, or changes to data reporting methodology.
Troubleshooting the first call
Encountering issues during your first API call is common. Here's a guide to diagnosing and resolving typical problems when interacting with the UK Carbon Intensity API.
- Issue: 404 Not Found error
-
Cause: This usually means the endpoint you're trying to access does not exist or the URL is misspelled. It could also indicate an incorrect region code if you're querying regional data.
Solution: Double-check the URL against the official API documentation. Ensure correct capitalization and syntax. For regional data, confirm that the region code (e.g.,
SEfor South East) is valid and correctly placed in the URL path. - Issue: Network error or connection refused
-
Cause: Your client (e.g.,
curl, Python script) cannot establish a connection to the API server. This could be due to a lack of internet connectivity, a firewall blocking the request, or the API server being temporarily unavailable.Solution: Verify your internet connection. Check if any local firewalls or network proxies are interfering with outbound HTTP requests. You can try accessing the API URL directly in a web browser to see if it responds. If the issue persists, the API server might be experiencing downtime; monitor the UK Carbon Intensity project homepage for status updates.
- Issue: Unexpected JSON parsing errors
-
Cause: The API returned a response that is not valid JSON, or your parsing logic is incorrect. This can happen if the API returns an HTML error page instead of JSON, or if the data structure has changed.
Solution: Inspect the raw response body before attempting to parse it as JSON. In
curl, the raw response is printed directly. In Python, printresponse.text. In JavaScript, examineresponse.text(). If it’s not JSON, the response might be an error page. If it is JSON but still causing parsing issues, compare the structure against the documented response formats for any discrepancies. Update your parsing logic accordingly. - Issue: Data is not what was expected (e.g., old data, missing fields)
-
Cause: This could be due to caching issues, an incorrect time parameter in your request, or regional data being queried when national data was intended (or vice-versa).
Solution: Ensure your requests include correct and up-to-date time parameters if you are querying historical or forecasted data for specific time windows. Clear any local caches if you suspect cached responses. Re-verify which endpoint you are calling (e.g., national vs. regional) and that it aligns with the data you expect to retrieve. The API updates data every 30 minutes, so there might be a slight delay in real-time values appearing.
- Issue: No response from API (request times out)
-
Cause: This indicates that your request was sent, but the server did not respond within a reasonable timeframe. This can be caused by network congestion, an overloaded API server, or an incorrectly configured timeout in your client.
Solution: Increase the timeout duration in your HTTP client if possible. Implement retry mechanisms (e.g., exponential backoff) to handle transient network issues or server load. If timeouts are consistent, it might indicate a broader issue with the API service that you can check for on the project's official channels.