{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/withruntime-com/json-schema/withruntime-com-job-schema.json",
  "title": "Job",
  "description": "A job.",
  "x-generated": "2026-11-28",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/withruntime-com-openapi.json#/components/schemas/Job",
  "type": "object",
  "properties": {
    "schedule": {
      "$ref": "#/$defs/JobSchedule"
    },
    "run": {
      "$ref": "#/$defs/SandboxRun"
    },
    "retry": {
      "$ref": "#/$defs/JobRetry"
    },
    "secrets": {
      "$ref": "#/$defs/JobSecrets"
    },
    "vcpu": {
      "type": "integer",
      "description": "Each run's vCPUs; a job's default (1) when omitted.",
      "minimum": 1
    },
    "memoryGB": {
      "type": "number",
      "description": "Each run's memory in GB (1 GB is 1,024 MiB); a fraction is taken to the MiB (`0.5`). A job's default (1) when omitted.",
      "minimum": 1
    },
    "diskGB": {
      "type": "number",
      "description": "Each run's disk in GB, to the MiB, over a fresh copy of its image. When omitted, a job's default (4) or its image's size, whichever is larger.",
      "minimum": 1
    },
    "image": {
      "type": "string",
      "description": "The image each run boots, by name (its newest version), `name:version` or ID; Runtime's default image when omitted."
    },
    "user": {
      "type": "string",
      "enum": [
        "runtime",
        "root"
      ],
      "description": "Who its command runs as: `runtime` (uid 1000, with passwordless sudo) or `root`. Its image's when omitted, else `runtime`."
    },
    "volumes": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/VolumeMount"
      },
      "description": "Volumes each run attaches and mounts, at most one, in the job's project; a run waits while another machine holds it."
    },
    "maxCost": {
      "type": "string",
      "format": "decimal",
      "pattern": "^(0|[1-9][0-9]{0,11})(\\.[0-9]{1,9})?$",
      "description": "The most one run may cost, in US dollars (`\"0.50\"`): a run pauses once it has cost that, as a machine at its maxCost does."
    },
    "id": {
      "type": "string",
      "description": "Its ID."
    },
    "object": {
      "type": "string",
      "enum": [
        "job"
      ],
      "description": "Always `job`."
    },
    "name": {
      "type": "string",
      "description": "Its name, unique in its project."
    },
    "state": {
      "type": "string",
      "enum": [
        "scheduled",
        "paused",
        "finished",
        "deleted"
      ],
      "description": "Where it is: `scheduled` (its runs are made at their times), `paused` (none is), `finished` (its one time ran)."
    },
    "labels": {
      "type": "object",
      "additionalProperties": {
        "type": "string"
      },
      "description": "Its labels."
    },
    "nextRunAt": {
      "type": "string",
      "format": "date-time",
      "description": "When its next run is made, or its next retry; none when paused or finished."
    },
    "lastError": {
      "$ref": "#/$defs/JobError"
    },
    "createdAt": {
      "type": "string",
      "format": "date-time",
      "description": "When it was created."
    },
    "revision": {
      "type": "integer",
      "description": "Its revision, changed by every change to it."
    },
    "deletedAt": {
      "type": "string",
      "format": "date-time",
      "description": "When it was deleted: a delete's answer, its state `deleted`."
    }
  },
  "required": [
    "id",
    "object",
    "state",
    "labels"
  ],
  "$defs": {
    "JobError": {
      "type": "object",
      "description": "Why a time's run was not made and will not be tried again: the answer its create got. The job waits for its next time; a run made takes it off.",
      "properties": {
        "at": {
          "type": "string",
          "format": "date-time",
          "description": "The time whose run was not made."
        },
        "status": {
          "type": "integer",
          "description": "The HTTP status its create was answered with."
        },
        "code": {
          "type": "string",
          "description": "The error's code, as any call's error names it."
        },
        "message": {
          "type": "string",
          "description": "What went wrong."
        },
        "requestId": {
          "type": "string",
          "description": "The create's request ID, for support."
        }
      },
      "required": [
        "at",
        "status",
        "code",
        "message"
      ]
    },
    "JobRetry": {
      "type": "object",
      "description": "How a failed run is run again: a run that ends with an exit code other than 0, or at its timeout.",
      "properties": {
        "maxAttempts": {
          "type": "integer",
          "description": "Attempts in all for one time, the first included; 1 (no retry) when omitted.",
          "minimum": 1,
          "maximum": 10,
          "default": 1
        },
        "backoffSeconds": {
          "type": "integer",
          "description": "Seconds from a failed attempt's end to the next.",
          "minimum": 0,
          "maximum": 86400,
          "default": 30
        }
      }
    },
    "JobSchedule": {
      "type": "object",
      "description": "When a job runs: once, at `at`; or at each time of its `cron` in its `timezone`. One of the two.",
      "properties": {
        "at": {
          "type": "string",
          "format": "date-time",
          "description": "The one time it runs."
        },
        "cron": {
          "type": "string",
          "description": "A cron expression of five fields (minute, hour, day of month, month, day of week), as cron reads them, or `@hourly`, `@daily`, `@weekly`, `@monthly` or `@yearly`."
        },
        "timezone": {
          "type": "string",
          "description": "The IANA timezone its cron's times are in (`America/Denver`), daylight saving included; UTC when omitted."
        }
      }
    },
    "JobSecrets": {
      "type": "object",
      "description": "Which of its org's secrets each run gets, and under which variables.",
      "properties": {
        "only": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "The secrets each run gets in their own variables, by name: only those of them whose scope admits it; [] none.",
          "maxItems": 64
        },
        "env": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          },
          "description": "Variables each holding the value of one of the org's visible secrets whose scope admits the run, by the secret's name, `only` or not: `{\"WEBSITE_TOKEN\": \"CRON_SECRET\"}`."
        }
      }
    },
    "SandboxRun": {
      "type": "object",
      "description": "A command a machine runs once it starts: when it ends, the machine stops.",
      "properties": {
        "cmd": {
          "oneOf": [
            {
              "type": "string",
              "minLength": 1,
              "description": "Run by bash -lc."
            },
            {
              "type": "array",
              "items": {
                "type": "string"
              },
              "minItems": 1,
              "description": "The program and its arguments, run without a shell."
            }
          ],
          "description": "The command: text, run by `bash -lc`, or the program and its arguments as a list, run without a shell."
        },
        "cwd": {
          "type": "string",
          "description": "The directory it runs in; the user's home when omitted."
        },
        "env": {
          "type": "object",
          "additionalProperties": {
            "type": "string"
          },
          "description": "Environment variables to add."
        },
        "timeoutSeconds": {
          "type": "number",
          "description": "Seconds it may run before it is stopped (`1.5` for 1,500 ms); no limit when omitted or 0.",
          "minimum": 0
        }
      },
      "required": [
        "cmd"
      ]
    },
    "VolumeMount": {
      "type": "object",
      "description": "A volume a machine attaches at its create, mounted read-write in it, one machine at a time; detached when the machine is deleted.",
      "properties": {
        "volume": {
          "type": "string",
          "description": "The volume, by name or ID, in the machine's project."
        },
        "path": {
          "type": "string",
          "description": "Where it is mounted, such as `/data`: an absolute path, not under `/proc`, `/sys`, `/dev`, `/etc`, `/usr`, `/bin`, `/sbin`, `/lib` or `/boot`."
        }
      },
      "required": [
        "volume",
        "path"
      ]
    }
  }
}