# Website Carbon Calculator API

> Estimate CO2e per page view of a URL or byte count with the Sustainable Web Design model v4 (CO2.js): page weight, A+–F rating, yearly total, fixes.

- Endpoint: `GET | POST https://apibox.io.vn/v1/web-carbon`
- Category: Web & SEO
- HTML docs: https://apibox.io.vn/docs/web-carbon/ (Vietnamese: https://apibox.io.vn/vi/docs/web-carbon/)
- Online tool: https://apibox.io.vn/tools/web-carbon/
- Authentication: `Authorization: Bearer <API key>` or `X-API-Key: <API key>` (free key: https://apibox.io.vn/dashboard/#signup)

Give a `url` and the API loads the page like a first visit: the HTML, stylesheets, scripts, non-lazy images, preloads, icons, iframes and the web fonts referenced by same-site CSS (up to `max_resources`, default 40, max 80), and adds up the bytes sent over the network (Content-Length, or a gzip estimate for compressed responses without it). Or skip the crawl and send `bytes` yourself, e.g. the transfer size from DevTools, WebPageTest or `har-tools`.

Emissions use the Sustainable Web Design model version 4 as implemented by CO2.js (Green Web Foundation): energy per gigabyte for data centres, networks and user devices, operational plus embodied, multiplied by grid carbon intensity — the world average (494 g/kWh) by default, or a country's average with `country=VN` (or per segment: `device_country`, `network_country`, `datacenter_country`). The result is grams CO2e per view, the SWD digital carbon rating from A+ (≤ 0.040 g) to F (> 0.359 g), and monthly / yearly totals with `views` (per month). `green=true` applies the green-hosting factor when your host runs on verified renewable energy (check it at thegreenwebfoundation.org; the API does not look it up).

The page report lists bytes by type, third-party bytes, the largest files and concrete suggestions: oversized images, JPEG / PNG that could be WebP / AVIF, heavy web fonts, third-party and total JavaScript, text files served without compression. It is an estimate: only static HTML is read (no JavaScript execution), so tag managers, lazy-loaded content and video streams are not counted.

## Parameters

| Name | In | Type | Required | Default | Description |
|---|---|---|---|---|---|
| `url` | query | string | yes |  | Page to measure (or send `bytes`). |
| `bytes` | query | number | no |  | Transfer size in bytes instead of crawling a URL. |
| `views` | query | number | no |  | Page views per month: adds monthly and yearly kg CO2e. |
| `green` | query | boolean | no | `false` | `true` when the site runs on verified green hosting. |
| `country` | query | string | no |  | Grid intensity of a country for all segments (ISO alpha-2 or alpha-3, e.g. `VN`); or `device_country`, `network_country`, `datacenter_country`. |
| `max_resources` | query | number | no | `40` | Maximum sub-resources fetched (0–80). |
| `green_hosting_factor` | query | number | no |  | Advanced (0–1): share of data-centre energy that is renewable. Also `first_visit_ratio`, `return_visit_ratio`, `data_reload_ratio`. |

## Example request

```bash
curl "https://apibox.io.vn/v1/web-carbon?bytes=2000000&views=10000&country=VN" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

## Example response

```json
{
  "bytes": 2000000,
  "green_hosting": false,
  "green_hosting_source": "default (not green; pass green=true if your host is verified green, e.g. at thegreenwebfoundation.org)",
  "co2e_grams_per_view": 0.2933,
  "co2e_grams_per_page_load": 0.2933,
  "rating": "E",
  "rating_scale": {
    "A+": "≤ 0.040 g",
    "A": "≤ 0.079 g",
    "B": "≤ 0.145 g",
    "C": "≤ 0.209 g",
    "D": "≤ 0.278 g",
    "E": "≤ 0.359 g",
    "F": "> 0.359 g"
  },
  "views_per_month": 10000,
  "co2e_kg_per_month": 2.933,
  "co2e_kg_per_year": 35.196,
  "variables": {
    "grid_intensity_g_per_kwh": {
      "device": {
        "country": "VNM",
        "value": 486.13
      },
      "dataCenter": {
        "country": "VNM",
        "value": 486.13
      },
      "network": {
        "country": "VNM",
        "value": 486.13
      }
    },
    "first_visit_ratio": 1,
    "return_visit_ratio": 0,
    "data_reload_ratio": 0,
    "green_hosting_factor": 0
  },
  "model": "Sustainable Web Design model v4 (CO2.js 0.19 by the Green Web Foundation, Apache-2.0; grid intensity data from Ember, CC BY 4.0)",
  "disclaimer": "Estimate only: models average energy per byte; real emissions depend on networks, devices and hosting."
}
```

## Use cases

- Add page CO2e and an A+–F rating to ESG or sustainability reports
- Compare a redesign against the old site before launch
- Show agencies' clients the effect of image and font optimisation
- Track page weight and emissions of key pages every week

## FAQ

### How accurate is it?

It is a model, not a measurement: SWD v4 uses average energy per byte. It is good for comparing pages and tracking change, not for exact carbon accounting.

### Does it check green hosting?

Not automatically. Look your host up in the Green Web Foundation directory and pass green=true if it is verified; by default the grid average is used.

### Why is my page lighter than in DevTools?

The crawler does not run JavaScript, so scripts loaded later by tag managers, lazy images and videos are missing. Send the DevTools transfer size as bytes for a full figure.
