Calculate Plan Pricing

Price a plan at a specific usage level or generate a price chart across a range of usage values.

Price at a Specific Usage

Use the calculate endpoint when a user enters their exact monthly usage and you need a precise price:

JavaScript
// Price plan at 1,250 kWh
const planId = "507f1f77bcf86cd799439011";
const usage = 1250;

const response = await fetch(
  `https://pricing.api.comparepower.com/api/plans/${planId}/calculate/${usage}`
);
const result = await response.json();

// result is an array with the plan + calculated expected_prices
const plan = result[0];
const pricePerKwh = plan.expected_prices[0].price;
console.log(`${(pricePerKwh * 100).toFixed(1)}¢/kWh at ${usage} kWh`);

The calculate endpoint returns the price as cents per kWh (e.g., 0.136 = 13.6¢/kWh). The usage parameter must be a whole number (integer).

Generate a Price Chart

Use the chart endpoint to get prices across a range of usage levels. This is useful for plotting price curves that show how per-kWh cost changes with usage:

JavaScript
// Get prices from 500 to 2000 kWh in 100 kWh steps
const planId = "507f1f77bcf86cd799439011";

const response = await fetch(
  `https://pricing.api.comparepower.com/api/plans/${planId}/chart/500/2000/100`
);
const result = await response.json();

// result[0].expected_prices contains a data point for each step
const dataPoints = result[0].expected_prices;
dataPoints.forEach(p => {
  console.log(`${p.usage} kWh: ${(p.price * 100).toFixed(1)}¢/kWh`);
});

Keep data points reasonable

Large ranges with small steps produce very large responses. Keep (usage_end - usage_start) / step under 100 data points.

Which Pricing Method to Use

ScenarioEndpointWhy
Comparison tableGET /api/plans with display_usageOne request returns all plans with prices at your usage tiers.
Custom usage calculatorGET /api/plans/{id}/calculate/{usage}User types their exact usage, you show one price.
Price-per-kWh chartGET /api/plans/{id}/chart/{...}Visual chart showing how price changes across usage range.

Most integrations only need expected_prices

For plan comparison tables, passing display_usage to GET /api/plans gives you prices for all plans in a single request. The calculate and chart endpoints are only needed for per-plan deep-dives.

Want to earn commissions when users sign up through your integration? Apply as a partner — it's free and takes about 5 minutes.