Factory API

A factory session is a running factory process at one location. It polls the Orchestrator for the next queued run of a station on a line at that location, runs the station's handler, and reports back. The Orchestrator never calls a factory; every request starts on the factory's side.

You rarely call these endpoints yourself: @assemblyline/lib-factory does it for you (startFactory()). They are documented so you can see what crosses the wire.

Authentication

Every request carries the org's API key:

HeaderRequiredPurpose
api-keyYesAPI key (starts with al_)
api-secretYesAPI secret
X-LocationPoll onlyThe location this session serves; lines at this location are dispatched to it
X-Factory-User-AgentNoMachine fingerprint (package, host, user, pid). Sending it opens a factory session
X-Factory-SessionNoSession id returned by the previous poll
X-Exclude-StationsNo (poll only)Codes of the stations the session is running now; their runs aren't claimed

At most one factory session is active per org and location. A second session at the same location is refused with 409 LOCATION_IN_USE, naming the session that holds it.

Endpoints

EndpointPurpose
GET /api/factory/pollClaim the next queued run
POST /api/factory/completeReport a run's output
POST /api/factory/failedReport a failure (retried up to 3 times)
POST /api/factory/attach-documentAttach a markdown document to the work record
POST /api/factory/attach-reportAttach the run's report
POST /api/factory/attach-fileAttach a binary file (xlsx, xls, pdf, csv, png, jpeg; 10 MB max)
POST /api/factory/attach-workpiecesRecord each workpiece's outcome: { "<workpiece_id>": "done" | "failed" }
POST /api/factory/disconnectEnd the session on shutdown so the location frees at once

What crosses the wire

Workpieces stay in the factory's folders; the Orchestrator never sees them. It stores what the station's handler sends: the run's output, the report, attached documents and files, and the workpiece outcome map.