API guide
Everything the portal does, you can do with HTTP. Base URL: https://squirmware.net. The machine-readable description is at /api/openapi.json, browsable at /api/docs.
Overview
Squirmware turns an intention ("read a sensor, blink a light, log over USB") plus components (a board, part numbers, spec sheets) into firmware, in five phases. Each phase produces one record, a deterministic verifier checks it, and the run parks at a gate until a person approves it, asks for changes, or rejects it. The API exposes exactly that: create a project, sharpen the brief, run phases, read what was produced, decide gates, download the package.
awaiting_approval, its checker already passed; the view endpoint lists its warnings and the facts the model supplied so you know where to look.Authentication
Every /api route except /api/health takes a bearer token:
Authorization: Bearer <token>
Tokens are issued by the operator. A missing or wrong token answers 401. The pages (/, /docs, /app) and /static are public.
Quick start
A Raspberry Pi Pico thermostat, from nothing to a reviewed behaviour spec:
export SQW=https://squirmware.net TOKEN=... # your token
H=(-H "Authorization: Bearer $TOKEN" -H "content-type: application/json")
# 1. create the project without starting it, so you can attach a spec sheet and run the interview
curl -s "${H[@]}" -d '{
"description": "Read the temperature from an SHT31 on the I2C header every 5 seconds and print it over USB. Blink the LED above 30 C.",
"board_ref": "profile:raspberry_pi_pico",
"parts": [{"part_number": "SHT31-DIS", "role": "temperature sensor on the I2C header"}],
"start": false
}' $SQW/api/projects
# -> {"project": {"id": "prj_...", "brief": {...}}, "run": null}
# 2. attach the sensor's datasheet (PDF or text; the text is extracted for the prompts)
curl -s -X PUT -H "Authorization: Bearer $TOKEN" -H "content-type: application/pdf" \
--data-binary @SHT31.pdf $SQW/api/projects/prj_.../attachments/SHT31.pdf
# 3. ask the interviewer; answer; ask again until it says ready (or stop whenever you like)
curl -s -X POST "${H[@]}" $SQW/api/projects/prj_.../interview
# -> {"round": {"understanding": "...", "ready": false, "questions": [{"id": "alarm_hysteresis", ...}]}, "brief": {...}}
curl -s "${H[@]}" -d '{"answers": [{"question_id": "alarm_hysteresis", "answer": "Use a 1 C margin"}]}' \
$SQW/api/projects/prj_.../interview/answers
# 4. start Phase 1; it runs in the background
curl -s -X POST "${H[@]}" $SQW/api/projects/prj_.../phases/intent
# -> {"id": "run_...", "phase": "intent", "status": "queued", ...}
# 5. poll the run, then read the gate view and decide
curl -s "${H[@]}" $SQW/api/projects/prj_.../runs/run_.../view
curl -s "${H[@]}" -d '{"decision": "approve"}' $SQW/api/projects/prj_.../runs/run_.../decision
# -> {"next_run": {"phase": "binding", "status": "queued"}} (approve starts the next phase)
# 6. at any point, take the package
curl -s -H "Authorization: Bearer $TOKEN" -o firmware.zip $SQW/api/projects/prj_.../package.zip
Passing "start": true (the default) skips the interview and queues Phase 1 immediately, which is what a script with a complete description wants.
Concepts
Projects and the brief
A project is one device: the user's description, a board_ref, and a brief. The brief is everything gathered before Phase 1: parts (part numbers with a role), attachments (spec sheets, with their extracted text), and the interview: the questions asked (questions_asked), the ones waiting (pending), the answers, the interviewer's latest understanding and a status of open, ready or skipped. Every prompt in Phases 1 and 2 sees the brief, so an answer you gave beats an assumption the model would otherwise make.
Boards
board_ref says where the components come from:
| form | meaning | Phase 2 |
|---|---|---|
profile:<id> | a dev board Squirmware knows (GET /api/boards lists them) | deterministic, no model call |
pcbyay:<dir> | a pcbyay design exported as spec, BOM, netlist and plan | netlist bound to pins deterministically; the model settles gaps |
library:<component id> | a board published in the Library of Everything | as pcbyay |
mcu:<family> | a bare processor (esp32, rp2040); chosen automatically when a part number in parts is a known processor and no board is given | the model proposes every pin from the free-pin list; each is marked for you to confirm |
manual:<path> | a hand-written board map (operator use) | as written |
Phases, runs and gates
Five phases, in order: intent, binding, plan, build, target. A phase executes as a run. A run's status moves queued → running → awaiting_approval | failed; a decision then makes it approved, rejected or superseded. Rules: one active run per project; a phase starts only when every earlier phase has an approved run; approving a run again later invalidates every downstream approval (they were built on the old result).
| decision | effect |
|---|---|
approve | the run becomes the phase's approved result; with start_next (default true) the next phase is queued |
revise | keep the result, apply the change request in feedback; a new run of the same phase starts from it |
reject | start the phase over; feedback is shown to the model as the reviewer's reasons |
On this server Phase 4 runs in source_only mode: the source is written module by module and statically checked, but not compiled (no toolchain container). The build report and the package README say so plainly. Phase 5 needs a bench or simulator and fails cleanly without one.
Artifacts and traces
Everything a run produces is an artifact named in run.artifacts: the phase's record (spec, board_map, plan, build, release), its verification report, every attempt (spec_attempt_1, verification_attempt_1, ...) and every model call as a trace (trace/1, trace/2-implementer-drv_led, ...) holding the full system prompt, user text and raw answer.
Endpoints
Health and boards
{"ok": true, "version", "provider", "storage", "toolchain": false, "bench": "none", "mcus": [...], "platforms": [...], "auth": "token"}. toolchain false means Phase 4 is source-only.profiles, and profile_details with name, MCU and interface ids), processor families and parts in the MCU database (mcu_families, mcus), platform ids, and the board_ref forms.Projects
Body: description (at least 10 characters), board_ref (optional when parts names a processor), parts (list of {part_number, role?, quantity?, notes?}), title?, owner?, start (default true). Returns 201 with {project, run}; run is the queued Phase 1 run when start is true, else null. 422 when no board can be determined.
{project, runs}: the project with its brief and phase states (phases.<phase>.approved_run_id / active_run_id / run_ids), and every run in creation order.Spec sheets and the interview
Raw body is the file; send its content-type. PDFs have their text extracted (pypdf); text files are kept as text; other files are stored without text. Up to 15 MB. Returns 201 {attachment, brief}; attachment.note says what happened ("text extracted from 12 of 12 pages", "PDF has no extractable text (scanned?)"). GET the same path returns the original bytes.
One interviewer round. Returns {round, brief} where round is {understanding, ready, ready_reason, questions: [{id, topic, question, why, kind, options, suggested}]}. kind is text, choice (pick one of options), confirm (yes or no to suggested) or number. At most 5 questions per round and 3 rounds per project; after that the brief is ready whatever the model thinks. 409 when questions are pending or the interview is over.
Body: {"answers": [{"question_id", "answer"}], "done": false}. Records answers against pending questions (unanswered ones are dropped; the interviewer may ask again). done: true ends the interview. Returns {brief}.
Runs and gates
intent | binding | plan | build | target. 201 with the run; 409 if a run is active or an earlier phase lacks an approval. Use it to start Phase 1 after the interview and to retry a failed phase.status, attempt, max_attempts, verification counts, error, artifacts (name → key), gate. Poll it while queued or running.The gate view: headline, summary, sections (each a table, list, kv or text), warnings, failures, model_sourced (facts the model supplied), assumptions, open_questions, checks (every verifier check with its detail), artifacts and traces. Built from the artifacts without a model call; it is what the portal shows.
artifacts.Body: {"decision": "approve" | "revise" | "reject", "feedback": "", "start_next": true}. revise and reject want feedback. Returns {project, run, next_run}; next_run is the queued follow-up (next phase on approve, same phase on revise and reject). 409 if the run is not awaiting_approval or another run is active.
The firmware package
A zip of everything so far: README.md (status, what the device does, the board and its pins, how to build and flash, tests), brief.json, spec.json, board_map.json, plan.json, build.json, release.json when they exist, firmware/ (the complete source tree for the platform's SDK) and images/ when compiled. Approved runs are preferred; a run waiting at its gate is used otherwise and the README says so. 409 before the spec exists.
files, which run each phase came from, compiled, images.Records
One record per phase, all JSON, all described with field documentation in the OpenAPI schema:
| phase | record | what is in it |
|---|---|---|
| 1 intent | BehaviorSpec | signals bound to board interfaces, behaviours with triggers and steps, modes, comms channels, failure handling, constraints, assumptions, open questions, declared totals |
| 2 binding | BoardMap | the MCU, every pin with function, net, interface and source (netlist, profile, model, user), peripherals with bus and address, power, flash method, unresolved items |
| 3 plan | FirmwarePlan | platform, language, RTOS, modules (ownership, dependencies, files, public API), tasks, budget, host tests, target tests with bench steps, risks |
| 4 build | BuildReport + modules | mode (toolchain or source_only), diagnostics, size, host-test results, static findings, files, image artifacts; each module's files and narration |
| 5 target | FirmwareRelease | version, images with checksums, flash recipe, bench kind, target-test results with evidence, manual, changelog, library component id |
Every verifier emits the same CheckResult shape as pcbyay: name, passed, severity (error blocks the gate and triggers a retry; warning is shown), detail (actionable; it is what the model receives on retry).
Errors
| status | meaning |
|---|---|
401 | missing or wrong bearer token |
404 | no such project, run, artifact or attachment |
409 | state conflict: a run is active, the phase is not ready, the run is not at its gate, the interview has pending questions, the project changed underneath you, nothing to package yet |
413 | attachment too large |
422 | the body did not validate, no board could be determined, an answer names an unknown question |
A run that could not finish is not an HTTP error: it is a run with status: failed and an error string ("the checks still fail after 3 attempts", "model provider: ...", "board ... could not be resolved"). Retry it with POST .../phases/{phase}.
Costs and limits
- Every interviewer round and every phase attempt is a model call; a phase retries up to 3 times on checker failures. Phase 4 makes one call per module and per host test.
- Interview: at most 5 questions per round, 3 rounds per project. Attachments: 15 MB each; the prompts quote at most 8,000 characters per sheet and 24,000 in total, so put the important pages first or upload the relevant section.
- Runs execute in the background inside the service; poll the run every few seconds. There is no webhook yet.
- Records and artifacts are kept per project with no expiry.
Source: github.com/leidichj/squirmware (private). This guide describes version 0.1.