DEV Community

Cover image for Carbon-Aware Inference in 5 Minutes: A CarbonLayer Quickstart
CarbonLayer
CarbonLayer

Posted on

Carbon-Aware Inference in 5 Minutes: A CarbonLayer Quickstart

If you read the last post on how CarbonLayer routes inference for lower carbon and water cost, here's the part that matters more: actually calling it.

1. Get an API key

Sign up, then generate a key from the dashboard's API Keys section. Keys are scoped per account — list, create, and revoke them anytime, nothing shared across teams unless you explicitly invite someone in.

2. Call the inference endpoint

curl -X POST https://carbonlayer.polsia.io/api/inference \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"prompt": "Your prompt here",
"model": "your-model-id"
}'
Or with fetch:

const res = await fetch("https://carbonlayer.polsia.io/api/inference", {
method: "POST",
headers: {
"Authorization": "Bearer YOUR_API_KEY",
"Content-Type": "application/json"
},
body: JSON.stringify({
prompt: "Your prompt here",
model: "your-model-id"
})
});
const data = await res.json();

3. Read the savings back

Every response carries the routing decision alongside the model output — which edge site served it, and what it saved versus a fixed-location baseline: savedCO2g, savedWaterMl, waterIntensityMlPerKwh.

4. Check cumulative impact

GET /api/usage — your own key's usage and savings over time
GET /api/network and GET /api/savings — aggregate numbers across the whole network
GET /api/grid-intensity — the live grid data feeding routing decisions, cached on a 5-minute window.

5. See it in the dashboard

Same numbers, visualized — no separate setup, it's live the moment your key starts making calls.

That's the whole loop: one API call, real routing, real numbers back. No separate SDK to install, no sustainability report to wait on.

Full reference at CarbonLayer's /docs.

Top comments (0)