---
title: "Start a job."
method: POST
path: "/v1/machines/{id}/jobs"
tags: ["machines"]
---

# Start a job.

`POST /v1/machines/{id}/jobs`

## Request

- Base URL: `https://api.smolmachines.com`
- URL: `https://api.smolmachines.com/v1/machines/{id}/jobs`
- Auth: HTTP bearer
- TypeScript: <https://skmtc.dev/smolmachines/apis/smolfleet-api/docs/v1/machines/:id/jobs/post.ts> (a function with typed inputs; its response is checked against the schema)

Starts a command detached and returns at once. Its stdout, stderr and exit code are kept in the machine, so the caller can disconnect and poll `GET /v1/machines/{id}/jobs/{job_id}` and read output from an offset. A running job keeps the machine from auto-stopping. Wakes a stopped machine. The image needs `sh`. Requires the `machine:exec` scope.

## Path parameters

- `id` string, required

## Request body

- MachineJobRequest: Start a command as a job: it runs detached, and its output and exit code are kept in the machine until read, so a client can disconnect and poll.
  - `command` union, required
    - string[]
    - string
  - `cwd` string, nullable
  - `env` object
  - `timeoutSeconds` integer, nullable: Stop the job with SIGTERM after this many seconds. Unset: no limit.
  - `user` string, nullable: Run as this user (image user name or `uid[:gid]`).

## Response `202`

The job is running

- MachineJob: A job and what is known about it.
  - `command` string[], required: The command as it was run (argv).
  - `createdAt` string, required
  - `exitCode` integer, nullable: The command's exit code once `exited`; 143 when it was cancelled or hit its timeout.
  - `finishedAt` string, nullable
  - `id` string, required
  - `machineId` string, required
  - `state` string, required: `running`, `exited` (see `exitCode`), or `lost`: the machine stopped or restarted while the job ran, so it never finished.
  - `stderrBytes` integer, nullable: Bytes of stderr written so far, when the machine was asked.
  - `stdoutBytes` integer, nullable: Bytes of stdout written so far, when the machine was asked.

## Other responses

- `401`: Missing or invalid API key
- `403`: Key lacks the required scope
- `404`: Not found
- `422`: The job could not start in this machine
- `429`: Rate limited; retry after the Retry-After header
- `500`: Internal error
- `503`: Retryable: the machine was unavailable

## Changes

- **2026-10-16** `bc31fc04a568`: 1 info
  - endpoint added

[Operation history](https://skmtc.dev/smolmachines/apis/smolfleet-api/changes/v1/machines/:id/jobs/post.md)

---

[API](https://skmtc.dev/smolmachines/apis/smolfleet-api.md) - [All operations](https://skmtc.dev/smolmachines/apis/smolfleet-api/llms.txt) - [OpenAPI document](https://skmtc.dev/smolmachines/apis/smolfleet-api/revisions/bc31fc04a568?raw)
