Solar PV Power Forecasting API Quickstart Codes
Complete end-to-end examples for renewable energy developers: add PV systems, then fetch solar power forecasts.
Replace YOUR_API_KEY with the key shown on the API Docs page after sign-in.
1. Get solar PV forecast for a single system
POST /v1/systems to register the site, wait briefly, then
GET /v1/systems/{system_id}/forecast (or look up by identifier).
import time
import requests
API_KEY = "YOUR_API_KEY"
BASE = "https://api.solar-forecast.com"
# 1) Add a system (forecast usually ready within ~1 minute)
system_body = {
"latitude": 42.56,
"longitude": -84.6,
"identifier": "lansing_site",
"inverter_comp": "Enphase",
"inverter_capacity_kw": 10.0,
"array_0": {
"orientation": 180,
"tilt": 32,
"panel_age": 5,
"panel_capacity_kw": 6.45,
},
}
created = requests.post(
f"{BASE}/v1/systems",
params={"api_key": API_KEY},
json=system_body,
timeout=60,
).json()
assert created.get("status") == "success", created
system_id = created["system_id"]
print("Created", system_id)
# 2) Wait, then fetch the forecast
time.sleep(60)
forecast = requests.get(
f"{BASE}/v1/systems/{system_id}/forecast",
params={"api_key": API_KEY},
timeout=60,
).json()
print(list(forecast["kWatt"].items())[:3])
const API_KEY = "YOUR_API_KEY";
const BASE = "https://api.solar-forecast.com";
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// 1) Add a system (forecast usually ready within ~1 minute)
const createdResp = await fetch(`${BASE}/v1/systems?api_key=${encodeURIComponent(API_KEY)}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
latitude: 42.56,
longitude: -84.6,
identifier: "lansing_site",
inverter_comp: "Enphase",
inverter_capacity_kw: 10.0,
array_0: {
orientation: 180,
tilt: 32,
panel_age: 5,
panel_capacity_kw: 6.45,
},
}),
});
const created = await createdResp.json();
if (created.status !== "success") throw new Error(JSON.stringify(created));
const systemId = created.system_id;
console.log("Created", systemId);
// 2) Wait, then fetch the forecast
await sleep(60_000);
const forecastResp = await fetch(
`${BASE}/v1/systems/${encodeURIComponent(systemId)}/forecast?api_key=${encodeURIComponent(API_KEY)}`
);
const forecast = await forecastResp.json();
console.log(Object.entries(forecast.kWatt).slice(0, 3));
# 1) Add a system
curl -s -X POST "https://api.solar-forecast.com/v1/systems?api_key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"latitude": 42.56,
"longitude": -84.6,
"identifier": "lansing_site",
"inverter_comp": "Enphase",
"inverter_capacity_kw": 10.0,
"array_0": {
"orientation": 180,
"tilt": 32,
"panel_age": 5,
"panel_capacity_kw": 6.45
}
}'
# Response includes "system_id", e.g. "user_0001"
# 2) Wait ~1 minute, then fetch the forecast (replace SYSTEM_ID)
sleep 60
curl -G "https://api.solar-forecast.com/v1/systems/SYSTEM_ID/forecast" \
--data-urlencode "api_key=YOUR_API_KEY"
<?php
$apiKey = "YOUR_API_KEY";
$base = "https://api.solar-forecast.com";
function api_request($method, $url, $body = null) {
$opts = ["http" => [
"method" => $method,
"header" => "Content-Type: application/json\r\n",
"ignore_errors" => true,
]];
if ($body !== null) $opts["http"]["content"] = json_encode($body);
return json_decode(file_get_contents($url, false, stream_context_create($opts)), true);
}
// 1) Add a system
$created = api_request("POST", "$base/v1/systems?api_key=" . urlencode($apiKey), [
"latitude" => 42.56,
"longitude" => -84.6,
"identifier" => "lansing_site",
"inverter_comp" => "Enphase",
"inverter_capacity_kw" => 10.0,
"array_0" => [
"orientation" => 180,
"tilt" => 32,
"panel_age" => 5,
"panel_capacity_kw" => 6.45,
],
]);
if (($created["status"] ?? null) !== "success") {
throw new Exception(json_encode($created));
}
$systemId = $created["system_id"];
echo "Created $systemId\n";
// 2) Wait, then fetch the forecast
sleep(60);
$forecast = api_request(
"GET",
"$base/v1/systems/" . rawurlencode($systemId) . "/forecast?api_key=" . urlencode($apiKey)
);
print_r(array_slice($forecast["kWatt"], 0, 3, true));
2. Get solar PV forecasts for multiple systems (< 20)
POST /v1/systems/bulk to register several sites, wait for the next forecast run
(~15 minutes), then GET /v1/forecast/bulk with the returned system_ids.
import time
import requests
API_KEY = "YOUR_API_KEY"
BASE = "https://api.solar-forecast.com"
# 1) Add several systems in one call
payload = {
"systems": [
{
"latitude": 42.56,
"longitude": -84.6,
"identifier": "lansing_site",
"array_0": {
"orientation": 180, "tilt": 32,
"panel_age": 5, "panel_capacity_kw": 6.45,
},
},
{
"latitude": 52.52,
"longitude": 13.40,
"identifier": "berlin_site",
"array_0": {
"orientation": 160, "tilt": 30,
"panel_age": 2, "panel_capacity_kw": 8.2,
},
},
{
"latitude": 40.71,
"longitude": -74.01,
"identifier": "nyc_site",
"array_0": {
"orientation": 185, "tilt": 25,
"panel_age": 3, "panel_capacity_kw": 7.0,
},
},
]
}
created = requests.post(
f"{BASE}/v1/systems/bulk",
params={"api_key": API_KEY},
json=payload,
timeout=120,
).json()
assert created.get("status") == "success", created
system_ids = [s["system_id"] for s in created["systems"]]
print("Created", system_ids)
# 2) Bulk-added forecasts arrive after the next run (~15 min)
time.sleep(15 * 60)
# 3) Fetch all forecasts in one bulk call
by_system = requests.get(
f"{BASE}/v1/forecast/bulk",
params=[("api_key", API_KEY)] + [("system_ids", sid) for sid in system_ids],
timeout=120,
).json()
for sid, forecast in by_system.items():
print(sid, len(forecast.get("kWatt", {})))
const API_KEY = "YOUR_API_KEY";
const BASE = "https://api.solar-forecast.com";
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// 1) Add several systems in one call
const createdResp = await fetch(`${BASE}/v1/systems/bulk?api_key=${encodeURIComponent(API_KEY)}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
systems: [
{
latitude: 42.56, longitude: -84.6, identifier: "lansing_site",
array_0: { orientation: 180, tilt: 32, panel_age: 5, panel_capacity_kw: 6.45 },
},
{
latitude: 52.52, longitude: 13.40, identifier: "berlin_site",
array_0: { orientation: 160, tilt: 30, panel_age: 2, panel_capacity_kw: 8.2 },
},
{
latitude: 40.71, longitude: -74.01, identifier: "nyc_site",
array_0: { orientation: 185, tilt: 25, panel_age: 3, panel_capacity_kw: 7.0 },
},
],
}),
});
const created = await createdResp.json();
if (created.status !== "success") throw new Error(JSON.stringify(created));
const systemIds = created.systems.map((s) => s.system_id);
console.log("Created", systemIds);
// 2) Bulk-added forecasts arrive after the next run (~15 min)
await sleep(15 * 60_000);
// 3) Fetch all forecasts in one bulk call
const url = new URL(`${BASE}/v1/forecast/bulk`);
url.searchParams.set("api_key", API_KEY);
for (const sid of systemIds) url.searchParams.append("system_ids", sid);
const bySystem = await (await fetch(url)).json();
for (const [sid, forecast] of Object.entries(bySystem)) {
console.log(sid, Object.keys(forecast.kWatt || {}).length);
}
# 1) Add several systems
curl -s -X POST "https://api.solar-forecast.com/v1/systems/bulk?api_key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"systems": [
{
"latitude": 42.56, "longitude": -84.6, "identifier": "lansing_site",
"array_0": {"orientation": 180, "tilt": 32, "panel_age": 5, "panel_capacity_kw": 6.45}
},
{
"latitude": 52.52, "longitude": 13.40, "identifier": "berlin_site",
"array_0": {"orientation": 160, "tilt": 30, "panel_age": 2, "panel_capacity_kw": 8.2}
},
{
"latitude": 40.71, "longitude": -74.01, "identifier": "nyc_site",
"array_0": {"orientation": 185, "tilt": 25, "panel_age": 3, "panel_capacity_kw": 7.0}
}
]
}'
# Note the returned system_id values
# 2) Wait for the next forecast run (~15 minutes)
sleep 900
# 3) Fetch forecasts (replace with your system_ids)
curl -G "https://api.solar-forecast.com/v1/forecast/bulk" \
--data-urlencode "api_key=YOUR_API_KEY" \
--data-urlencode "system_ids=user_0001" \
--data-urlencode "system_ids=user_0002" \
--data-urlencode "system_ids=user_0003"
<?php
$apiKey = "YOUR_API_KEY";
$base = "https://api.solar-forecast.com";
function api_request($method, $url, $body = null) {
$opts = ["http" => [
"method" => $method,
"header" => "Content-Type: application/json\r\n",
"ignore_errors" => true,
]];
if ($body !== null) $opts["http"]["content"] = json_encode($body);
return json_decode(file_get_contents($url, false, stream_context_create($opts)), true);
}
// 1) Add several systems
$created = api_request("POST", "$base/v1/systems/bulk?api_key=" . urlencode($apiKey), [
"systems" => [
[
"latitude" => 42.56, "longitude" => -84.6, "identifier" => "lansing_site",
"array_0" => ["orientation" => 180, "tilt" => 32, "panel_age" => 5, "panel_capacity_kw" => 6.45],
],
[
"latitude" => 52.52, "longitude" => 13.40, "identifier" => "berlin_site",
"array_0" => ["orientation" => 160, "tilt" => 30, "panel_age" => 2, "panel_capacity_kw" => 8.2],
],
[
"latitude" => 40.71, "longitude" => -74.01, "identifier" => "nyc_site",
"array_0" => ["orientation" => 185, "tilt" => 25, "panel_age" => 3, "panel_capacity_kw" => 7.0],
],
],
]);
if (($created["status"] ?? null) !== "success") {
throw new Exception(json_encode($created));
}
$systemIds = array_column($created["systems"], "system_id");
echo "Created ", implode(", ", $systemIds), "\n";
// 2) Wait for the next forecast run (~15 minutes)
sleep(15 * 60);
// 3) Fetch forecasts
$params = ["api_key" => $apiKey];
foreach ($systemIds as $sid) $params["system_ids"][] = $sid;
$bySystem = api_request("GET", "$base/v1/forecast/bulk?" . http_build_query($params));
foreach ($bySystem as $sid => $forecast) {
echo $sid, " ", count($forecast["kWatt"] ?? []), "\n";
}
3. Get solar PV forecasts for a large number of systems (> 20)
Add systems in batches of up to 50 via POST /v1/systems/bulk, wait for the
forecast run, then fetch forecasts in matching /v1/forecast/bulk batches.
import time
import requests
API_KEY = "YOUR_API_KEY"
BASE = "https://api.solar-forecast.com"
BATCH = 50
# Example: build > 20 system definitions (replace with your fleet)
sites = [
{
"latitude": 42.0 + i * 0.01,
"longitude": -84.0 - i * 0.01,
"identifier": f"site_{i:03d}",
"array_0": {
"orientation": 180, "tilt": 30,
"panel_age": 4, "panel_capacity_kw": 6.0,
},
}
for i in range(75) # 75 systems → two bulk-add batches
]
def post_bulk(systems):
resp = requests.post(
f"{BASE}/v1/systems/bulk",
params={"api_key": API_KEY},
json={"systems": systems},
timeout=180,
).json()
assert resp.get("status") == "success", resp
return [s["system_id"] for s in resp["systems"]]
# 1) Add all systems in batches of 50
system_ids = []
for i in range(0, len(sites), BATCH):
system_ids.extend(post_bulk(sites[i : i + BATCH]))
print(f"Created {len(system_ids)} systems")
# 2) Wait for the next forecast run (~15 minutes)
time.sleep(15 * 60)
# 3) Fetch forecasts in batches of 50
def get_bulk(ids):
return requests.get(
f"{BASE}/v1/forecast/bulk",
params=[("api_key", API_KEY)] + [("system_ids", sid) for sid in ids],
timeout=180,
).json()
all_forecasts = {}
for i in range(0, len(system_ids), BATCH):
all_forecasts.update(get_bulk(system_ids[i : i + BATCH]))
print(f"Fetched forecasts for {len(all_forecasts)} systems")
const API_KEY = "YOUR_API_KEY";
const BASE = "https://api.solar-forecast.com";
const BATCH = 50;
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// Example: build > 20 system definitions (replace with your fleet)
const sites = Array.from({ length: 75 }, (_, i) => ({
latitude: 42.0 + i * 0.01,
longitude: -84.0 - i * 0.01,
identifier: `site_${String(i).padStart(3, "0")}`,
array_0: { orientation: 180, tilt: 30, panel_age: 4, panel_capacity_kw: 6.0 },
}));
async function postBulk(systems) {
const resp = await fetch(`${BASE}/v1/systems/bulk?api_key=${encodeURIComponent(API_KEY)}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ systems }),
});
const data = await resp.json();
if (data.status !== "success") throw new Error(JSON.stringify(data));
return data.systems.map((s) => s.system_id);
}
// 1) Add all systems in batches of 50
const systemIds = [];
for (let i = 0; i < sites.length; i += BATCH) {
systemIds.push(...(await postBulk(sites.slice(i, i + BATCH))));
}
console.log(`Created ${systemIds.length} systems`);
// 2) Wait for the next forecast run (~15 minutes)
await sleep(15 * 60_000);
// 3) Fetch forecasts in batches of 50
async function getBulk(ids) {
const url = new URL(`${BASE}/v1/forecast/bulk`);
url.searchParams.set("api_key", API_KEY);
for (const sid of ids) url.searchParams.append("system_ids", sid);
return (await fetch(url)).json();
}
const allForecasts = {};
for (let i = 0; i < systemIds.length; i += BATCH) {
Object.assign(allForecasts, await getBulk(systemIds.slice(i, i + BATCH)));
}
console.log(`Fetched forecasts for ${Object.keys(allForecasts).length} systems`);
# 1) Add first batch (up to 50 systems)
curl -s -X POST "https://api.solar-forecast.com/v1/systems/bulk?api_key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"systems":[ /* systems 1-50 */ ]}'
# Add next batch if you have more than 50
curl -s -X POST "https://api.solar-forecast.com/v1/systems/bulk?api_key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"systems":[ /* systems 51-75 */ ]}'
# 2) Wait for the next forecast run
sleep 900
# 3) Fetch forecasts in matching batches of up to 50 system_ids
curl -G "https://api.solar-forecast.com/v1/forecast/bulk" \
--data-urlencode "api_key=YOUR_API_KEY" \
--data-urlencode "system_ids=user_0001" \
--data-urlencode "system_ids=user_0002"
# ... up to 50 ids, then repeat for the next batch ...
<?php
$apiKey = "YOUR_API_KEY";
$base = "https://api.solar-forecast.com";
$batch = 50;
function api_request($method, $url, $body = null) {
$opts = ["http" => [
"method" => $method,
"header" => "Content-Type: application/json\r\n",
"ignore_errors" => true,
]];
if ($body !== null) $opts["http"]["content"] = json_encode($body);
return json_decode(file_get_contents($url, false, stream_context_create($opts)), true);
}
// Example: build > 20 system definitions
$sites = [];
for ($i = 0; $i < 75; $i++) {
$sites[] = [
"latitude" => 42.0 + $i * 0.01,
"longitude" => -84.0 - $i * 0.01,
"identifier" => sprintf("site_%03d", $i),
"array_0" => [
"orientation" => 180, "tilt" => 30,
"panel_age" => 4, "panel_capacity_kw" => 6.0,
],
];
}
// 1) Add all systems in batches of 50
$systemIds = [];
for ($i = 0; $i < count($sites); $i += $batch) {
$chunk = array_slice($sites, $i, $batch);
$created = api_request("POST", "$base/v1/systems/bulk?api_key=" . urlencode($apiKey), [
"systems" => $chunk,
]);
if (($created["status"] ?? null) !== "success") {
throw new Exception(json_encode($created));
}
foreach ($created["systems"] as $s) $systemIds[] = $s["system_id"];
}
echo "Created ", count($systemIds), " systems\n";
// 2) Wait for the next forecast run (~15 minutes)
sleep(15 * 60);
// 3) Fetch forecasts in batches of 50
$allForecasts = [];
for ($i = 0; $i < count($systemIds); $i += $batch) {
$ids = array_slice($systemIds, $i, $batch);
$params = ["api_key" => $apiKey];
foreach ($ids as $sid) $params["system_ids"][] = $sid;
$part = api_request("GET", "$base/v1/forecast/bulk?" . http_build_query($params));
$allForecasts = array_merge($allForecasts, $part);
}
echo "Fetched forecasts for ", count($allForecasts), " systems\n";
4. Get personalised solar PV forecasts for multiple systems
Requires the personalised forecast add-on. Add systems, upload inverter generation history
with POST /v1/systems/{system_id}/generation (UTC timestamps → kWh), wait for the
personalised model to train, then read personalised_kWatt from
/v1/forecast/bulk.
import time
import requests
API_KEY = "YOUR_API_KEY"
BASE = "https://api.solar-forecast.com"
# 1) Add systems
created = requests.post(
f"{BASE}/v1/systems/bulk",
params={"api_key": API_KEY},
json={
"systems": [
{
"latitude": 42.56, "longitude": -84.6, "identifier": "lansing_site",
"array_0": {
"orientation": 180, "tilt": 32,
"panel_age": 5, "panel_capacity_kw": 6.45,
},
},
{
"latitude": 52.52, "longitude": 13.40, "identifier": "berlin_site",
"array_0": {
"orientation": 160, "tilt": 30,
"panel_age": 2, "panel_capacity_kw": 8.2,
},
},
]
},
timeout=120,
).json()
assert created.get("status") == "success", created
systems = created["systems"] # [{identifier, system_id, arrays}, ...]
# 2) Upload generation history (UTC → inverter energy kWh) for each system
# Use real measured history from your monitoring system.
sample_generation = {
"2024-06-01T12:00:00Z": 1.2,
"2024-06-01T13:00:00Z": 1.8,
"2024-06-01T14:00:00Z": 2.1,
"2024-06-01T15:00:00Z": 1.5,
}
for s in systems:
sid = s["system_id"]
resp = requests.post(
f"{BASE}/v1/systems/{sid}/generation",
params={"api_key": API_KEY},
json=sample_generation,
timeout=60,
).json()
print(sid, resp)
# 3) Wait for the base forecast (~15 min after bulk add) and personalised model training.
# personalised_kWatt appears once a model has been trained for that system.
time.sleep(15 * 60)
# 4) Fetch bulk forecasts and collect personalised series
system_ids = [s["system_id"] for s in systems]
by_system = requests.get(
f"{BASE}/v1/forecast/bulk",
params=[("api_key", API_KEY)] + [("system_ids", sid) for sid in system_ids],
timeout=120,
).json()
personalised = {}
for sid, forecast in by_system.items():
series = forecast.get("personalised_kWatt")
if series:
personalised[sid] = series
else:
print(f"{sid}: personalised_kWatt not ready yet — check generation history / training")
print(f"{len(personalised)} systems with personalised_kWatt")
const API_KEY = "YOUR_API_KEY";
const BASE = "https://api.solar-forecast.com";
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// 1) Add systems
const created = await (
await fetch(`${BASE}/v1/systems/bulk?api_key=${encodeURIComponent(API_KEY)}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
systems: [
{
latitude: 42.56, longitude: -84.6, identifier: "lansing_site",
array_0: { orientation: 180, tilt: 32, panel_age: 5, panel_capacity_kw: 6.45 },
},
{
latitude: 52.52, longitude: 13.40, identifier: "berlin_site",
array_0: { orientation: 160, tilt: 30, panel_age: 2, panel_capacity_kw: 8.2 },
},
],
}),
})
).json();
if (created.status !== "success") throw new Error(JSON.stringify(created));
const systems = created.systems;
// 2) Upload generation history (UTC → inverter energy kWh)
const sampleGeneration = {
"2024-06-01T12:00:00Z": 1.2,
"2024-06-01T13:00:00Z": 1.8,
"2024-06-01T14:00:00Z": 2.1,
"2024-06-01T15:00:00Z": 1.5,
};
for (const s of systems) {
const resp = await fetch(
`${BASE}/v1/systems/${encodeURIComponent(s.system_id)}/generation?api_key=${encodeURIComponent(API_KEY)}`,
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(sampleGeneration),
}
);
console.log(s.system_id, await resp.json());
}
// 3) Wait for forecast run + personalised model training
await sleep(15 * 60_000);
// 4) Fetch bulk forecasts and collect personalised series
const url = new URL(`${BASE}/v1/forecast/bulk`);
url.searchParams.set("api_key", API_KEY);
for (const s of systems) url.searchParams.append("system_ids", s.system_id);
const bySystem = await (await fetch(url)).json();
const personalised = {};
for (const [sid, forecast] of Object.entries(bySystem)) {
if (forecast.personalised_kWatt) personalised[sid] = forecast.personalised_kWatt;
else console.log(`${sid}: personalised_kWatt not ready yet`);
}
console.log(`${Object.keys(personalised).length} systems with personalised_kWatt`);
# 1) Add systems
curl -s -X POST "https://api.solar-forecast.com/v1/systems/bulk?api_key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"systems": [
{
"latitude": 42.56, "longitude": -84.6, "identifier": "lansing_site",
"array_0": {"orientation": 180, "tilt": 32, "panel_age": 5, "panel_capacity_kw": 6.45}
},
{
"latitude": 52.52, "longitude": 13.40, "identifier": "berlin_site",
"array_0": {"orientation": 160, "tilt": 30, "panel_age": 2, "panel_capacity_kw": 8.2}
}
]
}'
# Save the returned system_id values
# 2) Upload generation history for each system (UTC → kWh)
curl -s -X POST "https://api.solar-forecast.com/v1/systems/SYSTEM_ID_1/generation?api_key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"2024-06-01T12:00:00Z": 1.2,
"2024-06-01T13:00:00Z": 1.8,
"2024-06-01T14:00:00Z": 2.1,
"2024-06-01T15:00:00Z": 1.5
}'
curl -s -X POST "https://api.solar-forecast.com/v1/systems/SYSTEM_ID_2/generation?api_key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"2024-06-01T12:00:00Z": 0.9,
"2024-06-01T13:00:00Z": 1.4,
"2024-06-01T14:00:00Z": 1.7,
"2024-06-01T15:00:00Z": 1.1
}'
# 3) Wait for forecast run + personalised model training
sleep 900
# 4) Fetch forecasts and inspect personalised_kWatt
curl -G "https://api.solar-forecast.com/v1/forecast/bulk" \
--data-urlencode "api_key=YOUR_API_KEY" \
--data-urlencode "system_ids=SYSTEM_ID_1" \
--data-urlencode "system_ids=SYSTEM_ID_2"
<?php
$apiKey = "YOUR_API_KEY";
$base = "https://api.solar-forecast.com";
function api_request($method, $url, $body = null) {
$opts = ["http" => [
"method" => $method,
"header" => "Content-Type: application/json\r\n",
"ignore_errors" => true,
]];
if ($body !== null) $opts["http"]["content"] = json_encode($body);
return json_decode(file_get_contents($url, false, stream_context_create($opts)), true);
}
// 1) Add systems
$created = api_request("POST", "$base/v1/systems/bulk?api_key=" . urlencode($apiKey), [
"systems" => [
[
"latitude" => 42.56, "longitude" => -84.6, "identifier" => "lansing_site",
"array_0" => ["orientation" => 180, "tilt" => 32, "panel_age" => 5, "panel_capacity_kw" => 6.45],
],
[
"latitude" => 52.52, "longitude" => 13.40, "identifier" => "berlin_site",
"array_0" => ["orientation" => 160, "tilt" => 30, "panel_age" => 2, "panel_capacity_kw" => 8.2],
],
],
]);
if (($created["status"] ?? null) !== "success") {
throw new Exception(json_encode($created));
}
$systems = $created["systems"];
// 2) Upload generation history (UTC → kWh)
$sampleGeneration = [
"2024-06-01T12:00:00Z" => 1.2,
"2024-06-01T13:00:00Z" => 1.8,
"2024-06-01T14:00:00Z" => 2.1,
"2024-06-01T15:00:00Z" => 1.5,
];
foreach ($systems as $s) {
$sid = $s["system_id"];
$resp = api_request(
"POST",
"$base/v1/systems/" . rawurlencode($sid) . "/generation?api_key=" . urlencode($apiKey),
$sampleGeneration
);
echo $sid, " ", json_encode($resp), "\n";
}
// 3) Wait for forecast run + personalised model training
sleep(15 * 60);
// 4) Fetch bulk forecasts and collect personalised series
$params = ["api_key" => $apiKey];
foreach ($systems as $s) $params["system_ids"][] = $s["system_id"];
$bySystem = api_request("GET", "$base/v1/forecast/bulk?" . http_build_query($params));
$personalised = [];
foreach ($bySystem as $sid => $forecast) {
if (!empty($forecast["personalised_kWatt"])) {
$personalised[$sid] = $forecast["personalised_kWatt"];
} else {
echo "$sid: personalised_kWatt not ready yet\n";
}
}
echo count($personalised), " systems with personalised_kWatt\n";
5. Get aggregated solar PV forecast for a large number of systems
Register the fleet with bulk add (batched if needed), wait for forecasts, then call
GET /v1/forecast/aggregated for one summed AC series across every system on the account.
import time
import requests
API_KEY = "YOUR_API_KEY"
BASE = "https://api.solar-forecast.com"
BATCH = 50
sites = [
{
"latitude": 42.0 + i * 0.01,
"longitude": -84.0 - i * 0.01,
"identifier": f"fleet_site_{i:03d}",
"array_0": {
"orientation": 180, "tilt": 30,
"panel_age": 4, "panel_capacity_kw": 6.0,
},
}
for i in range(60)
]
# 1) Add the fleet in batches of 50
created_ids = []
for i in range(0, len(sites), BATCH):
created = requests.post(
f"{BASE}/v1/systems/bulk",
params={"api_key": API_KEY},
json={"systems": sites[i : i + BATCH]},
timeout=180,
).json()
assert created.get("status") == "success", created
created_ids.extend(s["system_id"] for s in created["systems"])
print(f"Created {len(created_ids)} systems")
# 2) Wait for the next forecast run (~15 minutes)
time.sleep(15 * 60)
# 3) One call returns the portfolio total (all systems on this API key)
portfolio = requests.get(
f"{BASE}/v1/forecast/aggregated",
params={"api_key": API_KEY},
timeout=180,
).json()
print(list(portfolio["kWatt"].items())[:3])
print(list(portfolio["clearsky_kWatt"].items())[:3])
const API_KEY = "YOUR_API_KEY";
const BASE = "https://api.solar-forecast.com";
const BATCH = 50;
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
const sites = Array.from({ length: 60 }, (_, i) => ({
latitude: 42.0 + i * 0.01,
longitude: -84.0 - i * 0.01,
identifier: `fleet_site_${String(i).padStart(3, "0")}`,
array_0: { orientation: 180, tilt: 30, panel_age: 4, panel_capacity_kw: 6.0 },
}));
// 1) Add the fleet in batches of 50
const createdIds = [];
for (let i = 0; i < sites.length; i += BATCH) {
const created = await (
await fetch(`${BASE}/v1/systems/bulk?api_key=${encodeURIComponent(API_KEY)}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ systems: sites.slice(i, i + BATCH) }),
})
).json();
if (created.status !== "success") throw new Error(JSON.stringify(created));
createdIds.push(...created.systems.map((s) => s.system_id));
}
console.log(`Created ${createdIds.length} systems`);
// 2) Wait for the next forecast run (~15 minutes)
await sleep(15 * 60_000);
// 3) Portfolio total across every system on this API key
const url = new URL(`${BASE}/v1/forecast/aggregated`);
url.searchParams.set("api_key", API_KEY);
const portfolio = await (await fetch(url)).json();
console.log(Object.entries(portfolio.kWatt).slice(0, 3));
# 1) Add fleet (repeat for additional batches of up to 50)
curl -s -X POST "https://api.solar-forecast.com/v1/systems/bulk?api_key=YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"systems":[ /* up to 50 system objects */ ]}'
# 2) Wait for the next forecast run
sleep 900
# 3) Aggregated AC forecast across all systems on this account
curl -G "https://api.solar-forecast.com/v1/forecast/aggregated" \
--data-urlencode "api_key=YOUR_API_KEY"
<?php
$apiKey = "YOUR_API_KEY";
$base = "https://api.solar-forecast.com";
$batch = 50;
function api_request($method, $url, $body = null) {
$opts = ["http" => [
"method" => $method,
"header" => "Content-Type: application/json\r\n",
"ignore_errors" => true,
]];
if ($body !== null) $opts["http"]["content"] = json_encode($body);
return json_decode(file_get_contents($url, false, stream_context_create($opts)), true);
}
$sites = [];
for ($i = 0; $i < 60; $i++) {
$sites[] = [
"latitude" => 42.0 + $i * 0.01,
"longitude" => -84.0 - $i * 0.01,
"identifier" => sprintf("fleet_site_%03d", $i),
"array_0" => [
"orientation" => 180, "tilt" => 30,
"panel_age" => 4, "panel_capacity_kw" => 6.0,
],
];
}
// 1) Add the fleet in batches of 50
$createdIds = [];
for ($i = 0; $i < count($sites); $i += $batch) {
$created = api_request(
"POST",
"$base/v1/systems/bulk?api_key=" . urlencode($apiKey),
["systems" => array_slice($sites, $i, $batch)]
);
if (($created["status"] ?? null) !== "success") {
throw new Exception(json_encode($created));
}
foreach ($created["systems"] as $s) $createdIds[] = $s["system_id"];
}
echo "Created ", count($createdIds), " systems\n";
// 2) Wait for the next forecast run (~15 minutes)
sleep(15 * 60);
// 3) Portfolio total across every system on this API key
$portfolio = api_request(
"GET",
"$base/v1/forecast/aggregated?api_key=" . urlencode($apiKey)
);
print_r(array_slice($portfolio["kWatt"], 0, 3, true));