← Five Whys
Your token

Five Whys API

Reading your chain, the checks, the diagram and every download run free in the browser and need no API. The API is for the one metered step: send a problem and your chain of whys (one branch or several), and get back, as JSON, the steps that continue each chain to a systemic root cause (each with a way to check it), a root cause per branch sorted as a missing check, document, process or automation, the answers of yours that need work, fixes with a way to tell they worked, and questions to find out. The page checks the reply against your own answers before drawing it.

Base URL: https://api.skillsafe.ai/v1/app-api. Every response is {"data": ...} or {"error": {"code", "message"}}; read error.code and error.message rather than the HTTP status alone.

The task field

This app has one task. Always send "task": "dig".

taskWhat it doesReply
digContinues each chain of whys until it reaches a systemic root cause, may open up to two new branches when the facts show a separate cause, names each root cause, points at weak answers and proposes fixes.One JSON object

Input fields

All values are strings. task, problem and chain are required.

FieldMeaning
task"dig"
problemThe problem, one line, such as "12% of orders shipped a day late in March".
chainJSON text: [{branch, label, whys: [{id, text}], root, root_stated}]. Branch ids are letters A, B…; why ids are the letter and step number, A1, A2…, in order. root is your stated root cause (or your last answer, with root_stated false). At most 6 branches of 12 answers.
fixesJSON text: [{id, branch, text}] with ids F1…, or "[]".
page_flagsJSON text: [{id, code}] from the page's check, codes blame, vague, circular, shallow, root-blame, root-detail, fix-symptom; or "[]".
contextOptional extra facts, up to 1,500 characters, or "".

The reply

job.output.output is text holding one JSON object (sometimes inside a ```json fence): {"branches": [{"branch", "add": [{"id", "text", "check"}], "root": {"text", "kind"}}], "new_branches": [...same shape...], "weak_links": [{"id", "issue", "note"}], "fixes": [{"branch", "text", "verify"}], "questions": [...]}. branches has one entry per branch sent; add holds 0 to 3 new steps numbered after your last answer, each a hypothesis with a check; kind is validation, documentation, process or automation; issue is blame, vague, circular, guess, two-causes, leap or symptom. Before using it, check that every id is one you sent or the next in sequence, that no step repeats an earlier one and that every kind and issue is on the list; the page does this, keeps your own answers word for word, marks every added step as one to check and lists what it refused. If the balance ran low, truncated is true and the reply may stop early; the page keeps every part that arrived whole.

Worked example

Input (input.json), the missed-deadline sample on the page, with two branches:

{
  "task": "dig",
  "problem": "The app launch slipped three weeks past the 1 May date",
  "chain": "[{\"branch\":\"A\",\"label\":\"Scope\",\"whys\":[{\"id\":\"A1\",\"text\":\"Two features were added halfway through\"},{\"id\":\"A2\",\"text\":\"Sales promised them to a large customer\"},{\"id\":\"A3\",\"text\":\"Poor communication\"}],\"root\":\"Poor communication\",\"root_stated\":false},{\"branch\":\"B\",\"label\":\"Reviews\",\"whys\":[{\"id\":\"B1\",\"text\":\"Finished work waited days for code review\"},{\"id\":\"B2\",\"text\":\"Only the tech lead can approve a merge\"},{\"id\":\"B3\",\"text\":\"The approval rule was set up when the team was two people and never revisited\"}],\"root\":\"No owner reviews team process as the team grows\",\"root_stated\":true}]",
  "fixes": "[{\"id\":\"F1\",\"branch\":\"A\",\"text\":\"Freeze scope two weeks into each release\"},{\"id\":\"F2\",\"branch\":\"B\",\"text\":\"Let any two senior engineers approve a merge, and check review wait time each month\"}]",
  "page_flags": "[{\"id\":\"A3\",\"code\":\"vague\"},{\"id\":\"A\",\"code\":\"root-detail\"},{\"id\":\"F2\",\"code\":\"fix-symptom\"}]",
  "context": "Team of 6. The launch slipped from 1 May to 22 May. Two features were added in week 3 at the sales team's request. Code reviews waited 3 days on average; only the tech lead could approve."
}

Reply:

{"branches":[{"branch":"A","add":[{"id":"A4","text":"Sales can commit features to a customer without first checking what engineering can deliver","check":"Ask how the two features reached the team and whether engineering was asked before the promise"},{"id":"A5","text":"No agreed process decides how a request that arrives mid-release is weighed against the date","check":"Look for a written rule on scope changes; ask what happened to the 1 May date when they came in"}],"root":{"text":"Nobody owns a process that weighs mid-release feature requests against the launch date before they are promised.","kind":"process"}},{"branch":"B","add":[],"root":{"text":"Nobody owns reviewing team rules like merge approval as the team grows, so the old rule stayed in place.","kind":"process"}}],"new_branches":[],"weak_links":[{"id":"A3","issue":"vague","note":"Ask which communication was missing: between whom, about what, and at which point the promise was made."}],"fixes":[{"branch":"A","text":"Add a step where any feature request after kickoff is sized by engineering and its effect on the date agreed before it is promised","verify":"Next release: every added feature has a recorded sizing and a date decision"},{"branch":"B","text":"Name an owner to review team rules such as merge approval each quarter, and widen who can approve now","verify":"Review wait time falls from about 3 days and the quarterly review happens on schedule"}],"questions":["Who at sales made the promise, and was there any way for them to see engineering capacity?","Was the 1 May date ever changed when the two features were added?"]}

On the page, the new steps appear dashed under your own answers in branch A, each root cause gets its kind, and the fixes appear under the diagram with how to tell they worked.

Errors

HTTPWhat to do
401The token is missing, expired or a guest token on a run. Get a personal token on the token page.
402The balance is below what the run reserves. Top up at skillsafe.ai/account/billing.
400The body is not a JSON object of the fields above, or a required field is missing.
429Wait and retry with the same Idempotency-Key.

Step 1 — a tiny client helper

One function that sends JSON and unwraps the {data, error} envelope.

BASE="https://api.skillsafe.ai/v1/app-api"
TOKEN="paste-your-token-here"   # from https://five-whys.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 your personal token: sign in on the token page and copy it.

# 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":"five-whys"}' | jq -r '.data.token')

Step 3 — who am I, and my balance

subject_type is guest or user; credits is the balance (1 credit = $0.0001).

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

Step 4 — price a run for free

/estimate charges nothing and starts no job. hold_credits is the amount reserved while a run is in flight, not the price; the run is charged what it uses.

# input.json: the run input object - {"task": "dig", "problem": "Orders ship late", "chain": "[...]", "fixes": "[]", "page_flags": "[]", "context": ""}
api POST /estimate "$(cat input.json)" | jq '.data | {hold_credits, min_credits, model, model_alias, markup_bps, warnings}' 

Step 5 — run it and wait for the job

Send an Idempotency-Key derived from the input: a retry with the same key is never billed twice.

KEY="five-whys:dig:$(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: {branches, new_branches, weak_links, fixes, questions}
echo "$J" | jq '.data | {charged_credits, truncated}' 

Step 6 — or stream it

/run-stream sends Server-Sent Events while the job runs and the finished job at the end.

# 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: five-whys:dig:$(shasum -a 256 input.json | cut -c1-16):a1" --data @input.json