← Lights Low
API

Drive Lights Low from your own code

The one metered task, light-plan, is available over HTTP. It takes up to 8 lights a home shows after dark - outdoor lamps or rooms seen through a window - each with its colour, spread, hours, purpose and pull, plus the page's fixes and verdict, and returns a summary, 1 reason and 1 first step per light, and a line on keeping the brightest light useful.

The division of labour first: a fixed rule scores every light and picks each fix and the verdict; the model explains them and writes the first steps. After a run the page checks that the verdict and every fix match its scores, that every light comes back in order, that the summary names the brightest pull, that every number comes from the lights and that no ids leak into the prose.

Base URL and the envelope

Every endpoint lives under https://api.skillsafe.ai/v1/app-api, and every response uses one envelope:

{ "ok": true,  "data":  { ... } }
{ "ok": false, "error": { "code": "...", "message": "..." } }

The token is minted for this app (the guest call takes {"slug":"lights-low"}), so no slug header is needed afterwards. Send it as Authorization: Bearer …. The run body is the input object, sent bare.

StatusCodeMeaning
400validation_errorThe body is not a JSON object, or a required field (task, place, lights, facts) is missing.
401unauthorizedNo token, or a stale one. Mint a guest token or sign in again.
402insufficient_creditsThe balance is under min_credits. Price with /estimate first.
403forbiddenA guest token tried to run: a plan is metered and needs a personal sign-in.
404not_foundUnknown job id.
429rate_limitedBack off and retry.
5xxserver_errorTransient. Retry with the same Idempotency-Key so a retry never double-bills.

The task field, the input and the verdict

Every run sends task: light-plan (the one task is light-plan); a missing or different one is still answered as light-plan. Each setting scores 1 to 3 and a light's pull is colour x spread x hours (1 to 27, a rough guide). Pull 4 or less is keep; otherwise the highest setting is lowered to 1 (ties: spread, then hours, then colour), giving aim-down or curtain (spread), timer (hours) or warm-bulb (colour). The verdict, in order: any pull 18 or more beacon; any pull 8 or more glow; otherwise low.

FieldRequiredWhat it holds
taskyesAlways light-plan.
placeyesThe home in the person's words, up to 60 characters, or a home.
lightsyes1 line per light: item 1 | outdoor light | name: ... | colour: cool or bluish white | spread: bare bulb or points up | on: all night | for: ... | pull: 27 (3 x 3 x 3).
factsyesThe page's lines: 1 light N: line per light (pull, fix, reason, after the fix), then verdict:, brightest pull: and total pull:.
retry_notenoSent only by the page's single reformat retry.

The reply

{"task": "light-plan", "verdict": "beacon", "summary": "...", "lights": [{"item": 1, "fix": "aim-down", "why": "...", "first_step": "..."}], "still_useful": "...", "closing": "..."}
FieldWhat it holds
verdictThe page's verdict, copied: beacon, glow or low.
summaryNames the brightest pull as an item number and gives the total pull now and after every fix, at most 35 words.
lights1 entry per light, in order: item, fix (copied from the page), why (at most 20 words) and first_step (at most 25 words).
still_usefulHow the brightest light still does its job after its fix, at most 30 words.
closing1 friendly sentence, at most 20 words.

The page then checks the reply (GlowKit.check) and lists any disagreement under "The page's check".

Worked examples - every verdict

These are the 3 free samples on the page: the exact input the page sends and the reply that replays for free.

Corner house, porch lamp on all night - total pull 49, 19 after the fixes: beacon

Input:

{
 "task": "light-plan",
 "place": "corner house with a front garden",
 "lights": "item 1 | outdoor light | name: porch lamp by the front door | colour: cool or bluish white | spread: bare bulb or points up | on: all night | for: finding keys | pull: 27 (3 x 3 x 3)\nitem 2 | room seen through a window | name: kitchen window over the sink | colour: plain white | spread: no curtain | on: evenings, off at bedtime | for: washing up | pull: 12 (2 x 3 x 2)\nitem 3 | outdoor light | name: floodlight on the shed | colour: cool or bluish white | spread: shines sideways | on: only when a sensor sees movement | for: putting the bins out | pull: 6 (3 x 2 x 1)\nitem 4 | room seen through a window | name: landing window | colour: warm or amber | spread: thin or half-open curtain | on: evenings, off at bedtime | for: going up to bed | pull: 4 (1 x 2 x 2)",
 "facts": "light 1: pull 27, strong | fix: aim-down | reason: its spread setting scores highest | after the fix: 9\nlight 2: pull 12, strong | fix: curtain | reason: its spread setting scores highest | after the fix: 4\nlight 3: pull 6, some | fix: warm-bulb | reason: its colour setting scores highest | after the fix: 2\nlight 4: pull 4, faint | fix: keep | reason: pull 4 or less | after the fix: 4\nverdict: beacon | reason: a light pulls 18 or more\nbrightest pull: item 1 (pull 27)\ntotal pull: 49 across 4 lights; after every fix: 19"
}

Reply:

{
 "task": "light-plan",
 "verdict": "beacon",
 "summary": "Item 1, the porch lamp by the front door, pulls hardest on moths, making your home attractive to them. The pull across every light adds up to 49, dropping to 19 once changes are made.",
 "lights": [
  {
   "item": 1,
   "fix": "aim-down",
   "why": "Its spread, bare bulb or points up, is the highest-scoring setting here.",
   "first_step": "Switch off the porch lamp by the front door, let it cool, then fit a shade that aims it down for finding keys."
  },
  {
   "item": 2,
   "fix": "curtain",
   "why": "Its spread, no curtain, scores higher than its other settings.",
   "first_step": "Close a curtain or blind on the kitchen window over the sink so the room stays lit inside while you wash up."
  },
  {
   "item": 3,
   "fix": "warm-bulb",
   "why": "Its colour, cool or bluish white, outscores its other settings.",
   "first_step": "Switch off the floodlight on the shed, let it cool, then swap in a warm or amber bulb for putting the bins out."
  },
  {
   "item": 4,
   "fix": "keep",
   "why": "Its pull is already low enough to need no change.",
   "first_step": "Leave the landing window's thin or half-open curtain as it is, light off at bedtime, for going up to bed."
  }
 ],
 "still_useful": "Aimed down, the porch lamp by the front door still lights the door brightly enough for finding keys, just without spilling light up and out.",
 "closing": "Whenever you're ready, the first small changes below can calm your home's strong pull on moths."
}

First-floor flat with a balcony - total pull 16, 8 after the fixes: glow

Input:

{
 "task": "light-plan",
 "place": "first-floor flat with a balcony",
 "lights": "item 1 | outdoor light | name: balcony string lights | colour: warm or amber | spread: shines sideways | on: all night | for: sitting out | pull: 6 (1 x 2 x 3)\nitem 2 | room seen through a window | name: living room window | colour: plain white | spread: thin or half-open curtain | on: evenings, off at bedtime | for: reading | pull: 8 (2 x 2 x 2)\nitem 3 | room seen through a window | name: bedroom window | colour: warm or amber | spread: curtain or blind closed | on: evenings, off at bedtime | for: getting ready for bed | pull: 2 (1 x 1 x 2)",
 "facts": "light 1: pull 6, some | fix: timer | reason: its hours setting scores highest | after the fix: 2\nlight 2: pull 8, some | fix: curtain | reason: its spread setting scores highest | after the fix: 4\nlight 3: pull 2, faint | fix: keep | reason: pull 4 or less | after the fix: 2\nverdict: glow | reason: a light pulls 8 or more\nbrightest pull: item 2 (pull 8)\ntotal pull: 16 across 3 lights; after every fix: 8"
}

Reply:

{
 "task": "light-plan",
 "verdict": "glow",
 "summary": "Item 2, the living room window, pulls hardest. Overall the flat gives off a noticeable pull after dark, adding up to 16 now and 8 once every fix is done.",
 "lights": [
  {
   "item": 1,
   "fix": "timer",
   "why": "Its hours score highest - it stays on all night, more than its sideways spread or warm colour.",
   "first_step": "Add a plug-in timer or motion sensor to the balcony string lights, so they switch off once you've finished sitting out."
  },
  {
   "item": 2,
   "fix": "curtain",
   "why": "Its spread scores highest - the curtain is only thin or half-open, so light shows through it.",
   "first_step": "Close the living room window's thin or half-open curtain once it's dark, so you can keep reading with the room lit inside."
  },
  {
   "item": 3,
   "fix": "keep",
   "why": "Its pull is already low - just 2 - so nothing about colour, spread or hours needs to change yet.",
   "first_step": "Keep closing the bedroom window's curtain or blind each evening, just as you already do, to help with getting ready for bed."
  }
 ],
 "still_useful": "With the curtain closed once it's dark, the living room window still gives you light for reading, just kept inside instead of spilling out.",
 "closing": "Whenever you're ready, closing that curtain could be a simple first step toward quieter light after dark."
}

Terraced cottage - total pull 11, 7 after the fixes: lights low

Input:

{
 "task": "light-plan",
 "place": "terraced cottage",
 "lights": "item 1 | outdoor light | name: lamp over the front door | colour: warm or amber | spread: points down or shaded | on: only when a sensor sees movement | for: unlocking the door | pull: 1 (1 x 1 x 1)\nitem 2 | room seen through a window | name: bathroom window | colour: warm or amber | spread: thin or half-open curtain | on: evenings, off at bedtime | for: evening bath | pull: 4 (1 x 2 x 2)\nitem 3 | outdoor light | name: solar lights along the path | colour: plain white | spread: points down or shaded | on: all night | for: walking to the gate | pull: 6 (2 x 1 x 3)",
 "facts": "light 1: pull 1, faint | fix: keep | reason: pull 4 or less | after the fix: 1\nlight 2: pull 4, faint | fix: keep | reason: pull 4 or less | after the fix: 4\nlight 3: pull 6, some | fix: timer | reason: its hours setting scores highest | after the fix: 2\nverdict: low | reason: every light pulls under 8\nbrightest pull: item 3 (pull 6)\ntotal pull: 11 across 3 lights; after every fix: 7"
}

Reply:

{
 "task": "light-plan",
 "verdict": "low",
 "summary": "Item 3, the solar lights along the path, pulls hardest at 6. Your terraced cottage's lights all stay under 8, keeping the whole place low. Together they pull 11 now, 7 after every fix.",
 "lights": [
  {
   "item": 1,
   "fix": "keep",
   "why": "Its pull is already low, at 1, so none of its settings need changing.",
   "first_step": "Keep an eye on the sensor so it still responds well for unlocking the door when you arrive."
  },
  {
   "item": 2,
   "fix": "keep",
   "why": "Its pull is already low, at 4, so no setting needs changing.",
   "first_step": "Keep the curtain at the same thin or half-open gap each evening for your evening bath."
  },
  {
   "item": 3,
   "fix": "timer",
   "why": "Being on all night scores highest among its settings, so shortening its hours is the fix.",
   "first_step": "Switch the lights off, let them cool, then fit a motion sensor so they still light the path for walking to the gate."
  }
 ],
 "still_useful": "Even with shorter hours, the solar lights along the path still switch on with movement, so walking to the gate stays lit and safe.",
 "closing": "Your terraced cottage already sits low for moths, so try these small steps whenever feels right for you."
}

Build the input yourself

Load the engine in node (global.window = global; require("./glowkit.js")), then:

const K = GlowKit;
const built = K.buildInput(K.form({ place: "corner house with a front garden",
  lights: [{ place: "outdoor", name: "porch lamp by the front door", colour: "cool", spread: "high", hours: "night", need: "finding keys" },
           { place: "window", name: "kitchen window over the sink", colour: "neutral", spread: "high", hours: "evening", need: "washing up" }] }));
built.input.facts;                      // the page's lines: each light's pull and fix, the verdict, the totals
const wire = K.toWire(built.input);     // POST this to /estimate and /run
// then: const reply = K.normalize(K.parseReply(job.output.output));
// built.facts.verdict                  // the verdict the page's rule gives
// K.check(reply, built).notes          // the page's re-check of the reply
// K.md(built, reply, "my house")       // the plan as Markdown

Step 1 — a tiny client helper

One function that sends JSON and unwraps the envelope. Paste a personal token from /tokens.html, or leave it empty and mint a guest token in step 2.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://lights-low.skillsafe.ai/tokens.html
api() { # api METHOD PATH [JSON-BODY]
  curl -s -X "$1" "$BASE$2" -H "Content-Type: application/json" \
    ${TOKEN:+-H "Authorization: Bearer $TOKEN"} ${3:+--data "$3"}
}

Step 2 — a token

A guest token is enough for /me and /estimate. A run is metered, so it needs a personal token: sign in on /tokens.html and copy it from there.

# a guest token (enough for /me and /estimate); a run needs your personal token from /tokens.html
TOKEN=$(curl -s -X POST "$BASE/guest" -H "Content-Type: application/json" -d '{"slug":"lights-low"}' | jq -r '.data.token')

Step 3 — GET /me

Who the token is (subject_type: user or guest) and the credit balance.

api GET /me | jq '.data | {subject_type, credits}' 

Step 4 — POST /estimate

Free. The body is the run input itself, the bare object (never wrapped in {"input": ...}). hold_credits is a reservation, not the price; min_credits is what the balance must cover; model_alias reads gpt-terra.

# input.json: the run input object - {"task": "light-plan", "place": "corner house with a front garden", "lights": "item 1 | outdoor light | name: porch lamp by the front door | ...", "facts": "light 1: pull 27, strong | fix: aim-down | ..."}
# - see the field table
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — POST /run, then poll the job

Send an Idempotency-Key built from the lane and the input: a retry with the same key never bills twice. The page uses lights-low:<task>:<inputHash>:a<attempt> (the one task is light-plan), and its one reformat retry (with retry_note added) is attempt 2, a new key and a second run. The job's output.output is the reply text; truncated: true means the balance cut it short.

KEY="lights-low:light-plan:$(shasum -a 256 input.json | cut -c1-16):a1"
JOB=$(curl -s -X POST "$BASE/run" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: $KEY" --data @input.json | jq -r '.data.job_id')
while :; do
  J=$(api GET "/jobs/$JOB"); S=$(echo "$J" | jq -r '.data.status')
  case "$S" in succeeded|failed|cancelled) break;; esac; sleep 2
done
echo "$J" | jq -r '.data.output.output' > reply.json   # one JSON object, the reply contract
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — POST /run-stream

The same run as Server-Sent Events, with the same input.json. Browsers receive progress ticks rather than text deltas; the final done event carries the reply.

# Server-Sent Events: tick/delta events while the job runs, then a final event with the job
curl -N -s -X POST "$BASE/run-stream" -H "Content-Type: application/json" -H "Authorization: Bearer $TOKEN" \
  -H "Idempotency-Key: lights-low:light-plan:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json