# Run API Any system can start a job with one HTTP call: a tracker, a webhook, a cron job or `curl`. Every route needs a token from `machinist token create`. ## Start a job ```sh curl -sS -X POST "$MACHINIST_URL/machinist/run" \ -H "Authorization: Bearer $MACHINIST_TOKEN" \ -d '{ "key": "linear:ENG-142", "pipeline": "deploy", "vars": {"repo": "owner/name", "environment": "staging"}, "prompt": "Deploy the latest release to staging." }' ``` | Field | Meaning | | --- | --- | | `key` | Your ID for the request, at most 200 bytes. The same key returns the same job, so retries are safe | | `pipeline` | Optional (legacy alias: `preset`). A pipeline in the factory. Without one, the job uses `default_pipeline`, which clones the repository, implements the change, opens one pull request, runs `merge-gate`, and merges when `github.auto_merge` is `true` | | `base_branch` | Optional. Target base branch (for example `develop`, `staging`, or `release/1.2`) to fork `machinist/` from and target with the pull request. Omit or leave empty to target the repository's default branch (`origin/HEAD`). Invalid git branch names, leading `-`, `..`, control characters, or whitespace return `400` | | `vars` | String key-value map. `vars.repo` is always required and must be a connected repository (in `github.repositories` or added on Settings → Projects). Pass any [pipeline inputs](factory.md#pipeline-inputs) declared by `pipeline` alongside `repo` (missing required inputs, undeclared names, or values over 1024 bytes return `400`) | | `runs_on` | Optional. List of runner labels (e.g. `["macos", "arm64"]`) a runner must advertise to claim the job. Overrides the pipeline's `runs_on` when set | | `prompt` | The work. Its first line is the job's title | The reply is the job, with `201` when it was created and `200` when the key already had one. ## Follow and decide a job | Route | Does | | --- | --- | | `GET /machinist/jobs` | Lists the newest jobs. `?repo=owner/name` and `?source=linear` (or `?source=github`) filter them | | `GET /machinist/jobs/{id}` | Returns one job, including any direct triggered `children` | | `POST /machinist/jobs/{id}/approve` | Approves a job paused at a gate (`state: "waiting"`) so it resumes from the next step. Optional JSON body `{"reason": "..."}` (trimmed, max 1024 bytes). Requires `run` scope (`403` for `read` tokens or `viewer` users); returns `409` if the job is not `waiting` or the gate can no longer be resumed | | `POST /machinist/jobs/{id}/deny` | Denies a job paused at a gate (`state: "waiting"`), cancelling it. Optional JSON body `{"reason": "..."}` (trimmed, max 1024 bytes). Requires `run` scope (`403` for `read` tokens or `viewer` users); returns `409` if the job is not `waiting` | | `POST /machinist/jobs/{id}/cancel` | Stops a `queued`, `running`, or `waiting` job. Its pull request stays open | | `POST /machinist/jobs/{id}/rerun` | Runs an ended job again, on the same branch, and returns it. Returns `409` while the job is `queued`, `running`, or `waiting` | ```sh # Approve or deny a job waiting at a gate curl -sS -X POST "$MACHINIST_URL/machinist/jobs/$JOB_ID/approve" \ -H "Authorization: Bearer $MACHINIST_TOKEN" \ -H "Content-Type: application/json" \ -d '{"reason": "Smoke tests look good."}' ``` A job looks like this: ```json { "id": "t_cc205867de0efc0e", "key": "on_merge:t_aa104756cd9deb0d:0:deploy", "source": "trigger", "pipeline": "deploy", "preset": "deploy", "vars": {"repo": "owner/name", "environment": "staging"}, "title": "Deploy the latest release to staging.", "state": "waiting", "gate": { "step": "approve-production", "message": "Promote to production?", "details": "All staging smoke checks passed.", "waiting_since": "2026-11-22T15:02:00Z", "timeout_at": "2026-11-23T15:02:00Z" }, "parent_id": "t_aa104756cd9deb0d", "current_step": "", "tokens": 0, "cost_usd": null, "created_by": "trigger", "created_at": "2026-11-22T15:00:00Z", "updated_at": "2026-11-22T15:02:00Z" } ``` | Field | Meaning | | --- | --- | | `id` | Machinist's ID for the job. Use it in the routes above | | `key` | The key the job was started with. A job that came from somewhere else, such as a schedule or trigger, shows that source's key | | `source` | Where the job came from: `web` for the web app, `api` for a call with a token such as `curl`, `mcp` for a bot calling the [MCP endpoint](mcp.md), `schedule` for an automation, `trigger` for a child job started by a [`trigger:` step or `on_merge`](factory.md#triggers-and-on_merge), or an issue tracker such as `github` ([GitHub Issues](github-issues.md)) or `linear` ([Linear](linear.md)). See [job sources](designs/issue-sources.md) | | `source_url` | The original issue, parent job, or message, such as a GitHub issue, Linear issue, or parent Machinist job link. Left out when there is none, as for a job started with `curl` | | `pipeline`, `vars`, `title` | What the job runs, as in the request (`vars` includes `repo` plus resolved pipeline inputs; `preset` is also returned as a backwards-compatible alias of `pipeline`) | | `base_branch` | Target base branch when the job targets a non-default branch. Left out when targeting the repository's default branch | | `state` | Where the job is. See the table below | | `gate` | Present when a job is waiting at an [approval gate](factory.md#approval-gates) or has a recorded gate decision. While `waiting`, includes `step`, `message`, optional `details`, `waiting_since`, and optional `timeout_at`. Once decided, retains decision history (`decided_by`, `decided_at`, `decision`, and optional `reason`) | | `parent_id` | The parent job's ID when this job was started by a `trigger:` step or `on_merge`. Left out otherwise | | `children` | Returned by `GET /machinist/jobs/{id}` when this job triggered downstream child jobs. Each entry has `id`, `pipeline` (and alias `preset`), `state`, and `title` | | `current_step` | The pipeline step a running job is on. Empty when the job is not running, or has not started a step yet | | `tokens` | Tokens the job's runs used, added up. It counts a run once the run ends | | `cost_usd` | What the job's runs cost in US dollars, added up as runs end. `null` until a run reports a cost. Some harnesses report tokens but no cost | | `pr_number`, `pr_state` | The job's pull request, once it has one | | `merge_gate_decision`, `merge_gate_risk`, `merge_gate_reason` | The merge gate's judgment (`approve` or `human_review`, risk `low`/`medium`/`high`, and reason), when a merge gate ran. Left out when no merge gate ran | | `created_by` | The token or source that started the job | | `created_at` | When the job was made | | `updated_at` | When the job last changed: it started running, paused at or left a gate, opened a pull request, ended, or its pull request merged or closed | | State | Meaning | | --- | --- | | `queued` | Waiting for a runner | | `running` | A runner holds it | | `waiting` | Paused at a human approval gate (`gate` describes what it is waiting on). Approve it to resume from the next step, or deny/cancel it | | `done` | It finished. `pr_number` is set when it opened a pull request, and `pr_state` says whether that pull request is `open`, `merged` or `closed` | | `failed` | It could not finish | | `cancelled` | Someone cancelled or denied it, or a gate timed out | Machinist checks each open pull request on the job's branch every minute, so `pr_state` changes within about a minute of a merge or close. It stops checking once the pull request has merged or closed. Steps run headless without mid-step Q&A; a job pauses only at an explicit `gate:` step in its pipeline. Calling `approve` or `deny` on a job that is not `waiting` returns `409`, cancelling a job that has ended returns `409`, and running a job again while it is `queued`, `running`, or `waiting` returns `409`. Calling a write route (`run`, `approve`, `deny`, `cancel`, `rerun`) with a `read`-scoped token or `viewer` session returns `403`. A missing job returns `404`.