Degree days calculator
POST /api/degree-days-calcHeating, cooling and growing degree days from a daily temperature series you supply: daily means, or min/max pairs (the mean is their midpoint). Send POST /api/degree-days-calc with the required field days and pay $0.001 per call over x402 or MPP, or call it free by solving a proof-of-work challenge. It returns a JSON object with count, unit, base, growingBase, growingCap and 3 more.
Heating and cooling use one base (default 18 °C or 65 °F); growing degree days use their own base (default 10 °C or 50 °F) and an optional upper cutoff applied to each day's min and max. Returns the totals and each day's values, for up to 400 days.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
days | array | yes | 1-400 days: each a daily mean temperature (number), or { min, max }, or { mean } |
units | string | no | celsius (default) or fahrenheit |
base | number | no | Base for heating and cooling degree days (default 18 °C or 65 °F) |
growingBase | number | no | Base for growing degree days (default 10 °C or 50 °F) |
growingCap | number | no | Optional upper cutoff for growing degree days: each day's min and max are held at or below it |
Example request
curl -i -X POST https://agent402.tools/api/degree-days-calc \
-H "Content-Type: application/json" \
-d '{"days":[{"min":8,"max":19},{"min":12,"max":24},{"min":15,"max":29}],"base":18,"growingBase":10}'Without payment this returns HTTP 402 Payment Required with the exact price for degree-days-calc; any x402 v2 or MPP client pays it and retries.
Example response
{
"count": 3,
"unit": "°C",
"base": 18,
"growingBase": 10,
"growingCap": null,
"totals": {
"heatingDegreeDays": 4.5,
"coolingDegreeDays": 4,
"growingDegreeDays": 23.5
},
"days": [
{
"mean": 13.5,
"heating": 4.5,
"cooling": 0,
"growing": 3.5
},
{
"mean": 18,
"heating": 0,
"cooling": 0,
"growing": 8
},
{
"mean": 22,
"heating": 0,
"cooling": 4,
"growing": 12
}
],
"method": "Degree days per day: heating = max(0, base - mean), cooling = max(0, mean - base), growing = max(0, mean - growingBase); mean is (min + max) / 2 when a pair is given."
}| Field | Type | Always present | In the example |
|---|---|---|---|
count | number | yes | 3 |
unit | string | yes | °C |
base | number | yes | 18 |
growingBase | number | yes | 10 |
growingCap | null | no | null |
totals | object | yes | 3 fields: heatingDegreeDays, coolingDegreeDays, growingDegreeDays |
days | array of objects | yes | 3 items in the example |
method | string | yes | Degree days per day: heating = max(0, base - mean), cooling = max(0, mean - b... |
From an MCP client
catalog.call {
"slug": "degree-days-calc",
"params": {
"days": [
{
"min": 8,
"max": 19
},
{
"min": 12,
"max": 24
},
{
"min": 15,
"max": 29
}
],
"base": 18,
"growingBase": 10
}
}On the hosted connector at https://agent402.tools/mcp, catalog.call runs degree-days-calc free (rate-limited, no wallet). Local install: npx -y agent402-mcp@0.13.32.
Errors and behavior
daysis required. An input the tool rejects returns an HTTP 4xx whose body carrieserror,tool,expected,requiredandexample, so the caller can correct it.- A paid call that ends in any status of 400 or above is not charged over x402, MPP or a prepaid credits key: settlement runs after the tool and only on a successful response. The exception is a Tempo push credential, a transfer the buyer sent before the call: it settles before the tool runs, so if the tool then fails the payment is recorded as a refund owed to the paying wallet.
- Free tier: no outbound network call leaves the server for this tool, so proof-of-work (16 leading zero bits of sha256) pays for it.
- A
GETorHEADto /api/degree-days-calc returns the same 402 quote, so the price can be read without a body. - An
Idempotency-Keyheader makes a retried paid call replay the first 200 instead of charging again (an answer larger than 1 MB is not replayed).
Paid call (JavaScript agent)
import { wrapFetchWithPayment } from "@x402/fetch";
import { x402Client } from "@x402/core/client";
import { registerExactEvmScheme } from "@x402/evm/exact/client";
import { privateKeyToAccount } from "viem/accounts";
const client = new x402Client();
client.setSpendControls?.({ maxAmountPerPayment: "$0.001" }); // refuse any quote above this tool's price
registerExactEvmScheme(client, { signer: privateKeyToAccount(KEY) });
const payFetch = wrapFetchWithPayment(fetch, client);
const res = await payFetch("https://agent402.tools/api/degree-days-calc", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"days": [
{
"min": 8,
"max": 19
},
{
"min": 12,
"max": 24
},
{
"min": 15,
"max": 29
}
],
"base": 18,
"growingBase": 10
}),
});No wallet? Pay with compute
Fetch a challenge, solve the sha256 puzzle (16 leading zero bits, a fraction of a second of CPU), and resend with the X-Pow-Solution header:
import { createHash } from "node:crypto";
const lz = (b) => { let t = 0; for (const x of b) { if (!x) { t += 8; continue; } t += Math.clz32(x) - 24; break; } return t; };
const c = await (await fetch("https://agent402.tools/api/pow/challenge?slug=degree-days-calc")).json();
let n = 0;
while (lz(createHash("sha256").update(c.challenge + ":" + n).digest()) < c.difficulty) n++;
await fetch("https://agent402.tools/api/degree-days-calc", { method: "POST", headers: { "X-Pow-Solution": c.token + ":" + n, "Content-Type": "application/json" }, body: JSON.stringify({"days":[{"min":8,"max":19},{"min":12,"max":24},{"min":15,"max":29}],"base":18,"growingBase":10}) });Related tools
AQI calculator (US EPA)
US EPA Air Quality Index from the pollutant concentrations you supply: PM2.5 and PM10 (µg/m³, 24-hour), ozone (ppb.
Heat index and wind chill calculator
Heat index, wind chill, humidex, dew point and wet-bulb temperature from the temperature, humidity and wind you supply.
A2A Agent Card validate
Validate an A2A (Agent2Agent protocol) Agent Card: required fields, skill shape, transport names, capability flags.
Amortization schedule
Build the full per-period amortization schedule for a fully-amortizing loan.
Annuity present/future value
Present and future value of a level annuity (equal periodic payments).
Barcode / QR decode
Decode a barcode or QR code from an image.