{
  "components": {
    "parameters": {
      "Attempt": {
        "in": "path",
        "name": "attempt",
        "required": true,
        "schema": {
          "minimum": 1,
          "type": "integer"
        }
      },
      "TaskId": {
        "description": "The task id a claim returned (opaque).",
        "in": "path",
        "name": "taskId",
        "required": true,
        "schema": {
          "type": "string"
        }
      }
    },
    "responses": {
      "BadRequest": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Status"
            }
          }
        },
        "description": "The request is malformed or breaks a limit."
      },
      "Forbidden": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Status"
            }
          }
        },
        "description": "The key lacks the scope, the region, or a label it presented; or the task is not the app's."
      },
      "NotHeld": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Status"
            }
          }
        },
        "description": "The attempt is not held by this worker any more; stop working on it."
      },
      "TooManyRequests": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Status"
            }
          }
        },
        "description": "The key holds as many open claims as it may; retry after Retry-After."
      },
      "Unauthorized": {
        "content": {
          "application/json": {
            "schema": {
              "$ref": "#/components/schemas/Status"
            }
          }
        },
        "description": "No valid app key."
      }
    },
    "schemas": {
      "ArtifactRef": {
        "properties": {
          "name": {
            "description": "The name presigned for this attempt.",
            "type": "string"
          }
        },
        "required": [
          "name"
        ],
        "type": "object"
      },
      "ClaimRequest": {
        "properties": {
          "labels": {
            "additionalProperties": {
              "type": "string"
            },
            "description": "What the worker carries, each granted by the AppClient's spec.workerLabels.",
            "type": "object"
          },
          "leaseSeconds": {
            "default": 60,
            "maximum": 600,
            "minimum": 30,
            "type": "integer"
          },
          "limit": {
            "default": 1,
            "maximum": 50,
            "minimum": 1,
            "type": "integer"
          },
          "waitSeconds": {
            "default": 0,
            "maximum": 25,
            "minimum": 0,
            "type": "integer"
          },
          "worker": {
            "description": "The worker's own name, a DNS label; the same for every call about its tasks.",
            "pattern": "^[a-z0-9]([-a-z0-9.]{0,61}[a-z0-9])?$",
            "type": "string"
          }
        },
        "required": [
          "worker"
        ],
        "type": "object"
      },
      "ClaimResponse": {
        "properties": {
          "tasks": {
            "items": {
              "$ref": "#/components/schemas/Task"
            },
            "type": "array"
          }
        },
        "required": [
          "tasks"
        ],
        "type": "object"
      },
      "CompleteRequest": {
        "properties": {
          "artifacts": {
            "items": {
              "$ref": "#/components/schemas/ArtifactRef"
            },
            "type": "array"
          },
          "output": {
            "$ref": "#/components/schemas/Output"
          },
          "weightMilli": {
            "description": "Work done, in milli-credits; the step's catalog weight is the least charged.",
            "format": "int64",
            "type": "integer"
          }
        },
        "required": [
          "output"
        ],
        "type": "object"
      },
      "Document": {
        "properties": {
          "fields": {
            "additionalProperties": {
              "$ref": "#/components/schemas/Field"
            },
            "type": "object"
          },
          "files": {
            "items": {
              "$ref": "#/components/schemas/InputFile"
            },
            "type": "array"
          },
          "text": {
            "type": "string"
          }
        },
        "type": "object"
      },
      "FailRequest": {
        "properties": {
          "backoffSeconds": {
            "default": 0,
            "maximum": 3600,
            "minimum": 0,
            "type": "integer"
          },
          "error": {
            "maxLength": 2000,
            "type": "string"
          },
          "retryable": {
            "default": false,
            "type": "boolean"
          }
        },
        "required": [
          "error"
        ],
        "type": "object"
      },
      "Field": {
        "properties": {
          "raw": {
            "description": "What the document said; defaults to the value as text.",
            "type": "string"
          },
          "type": {
            "enum": [
              "string",
              "number",
              "boolean",
              "date",
              "money",
              "object",
              "array"
            ],
            "type": "string"
          },
          "value": {
            "description": "The value; a money value is {amount, currency}, a date YYYY-MM-DD."
          }
        },
        "required": [
          "type"
        ],
        "type": "object"
      },
      "HeartbeatRequest": {
        "properties": {
          "leaseSeconds": {
            "default": 60,
            "maximum": 600,
            "minimum": 30,
            "type": "integer"
          },
          "refs": {
            "items": {
              "$ref": "#/components/schemas/TaskRef"
            },
            "maxItems": 200,
            "type": "array"
          }
        },
        "required": [
          "refs"
        ],
        "type": "object"
      },
      "HeartbeatResponse": {
        "properties": {
          "refs": {
            "items": {
              "$ref": "#/components/schemas/TaskRef"
            },
            "type": "array"
          }
        },
        "required": [
          "refs"
        ],
        "type": "object"
      },
      "InputFile": {
        "properties": {
          "contentType": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "size": {
            "format": "int64",
            "type": "integer"
          },
          "url": {
            "description": "A signed GET",
            "good while the lease is; empty when the store cannot sign.": null,
            "type": "string"
          }
        },
        "required": [
          "name",
          "contentType",
          "size"
        ],
        "type": "object"
      },
      "Output": {
        "properties": {
          "fields": {
            "additionalProperties": {
              "$ref": "#/components/schemas/Field"
            },
            "type": "object"
          },
          "text": {
            "type": "string"
          }
        },
        "type": "object"
      },
      "PresignRequest": {
        "properties": {
          "attempt": {
            "type": "integer"
          },
          "contentType": {
            "type": "string"
          },
          "name": {
            "pattern": "^[A-Za-z0-9_-][A-Za-z0-9._-]{0,127}$",
            "type": "string"
          },
          "size": {
            "format": "int64",
            "minimum": 1,
            "type": "integer"
          },
          "taskId": {
            "type": "string"
          }
        },
        "required": [
          "taskId",
          "attempt",
          "name",
          "contentType",
          "size"
        ],
        "type": "object"
      },
      "PresignResponse": {
        "properties": {
          "expiresAt": {
            "format": "date-time",
            "type": "string"
          },
          "headers": {
            "additionalProperties": {
              "type": "string"
            },
            "type": "object"
          },
          "method": {
            "enum": [
              "PUT"
            ],
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "url": {
            "type": "string"
          }
        },
        "required": [
          "name",
          "method",
          "url",
          "headers",
          "expiresAt"
        ],
        "type": "object"
      },
      "Status": {
        "properties": {
          "code": {
            "type": "integer"
          },
          "message": {
            "type": "string"
          },
          "reason": {
            "type": "string"
          }
        },
        "type": "object"
      },
      "Task": {
        "properties": {
          "attempt": {
            "description": "This claim's attempt; later calls name it.",
            "type": "integer"
          },
          "config": {
            "additionalProperties": true,
            "description": "The node's settings.",
            "type": "object"
          },
          "id": {
            "description": "Opaque; names the task in every later call.",
            "type": "string"
          },
          "idempotencyKey": {
            "description": "Stable across attempts.",
            "type": "string"
          },
          "input": {
            "items": {
              "$ref": "#/components/schemas/Document"
            },
            "type": "array"
          },
          "leaseExpiresAt": {
            "format": "date-time",
            "type": "string"
          },
          "maxAttempts": {
            "type": "integer"
          },
          "nodeId": {
            "type": "string"
          },
          "runId": {
            "type": "string"
          },
          "step": {
            "description": "The ClusterStep's name.",
            "type": "string"
          },
          "workspace": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "attempt",
          "maxAttempts",
          "workspace",
          "runId",
          "step",
          "nodeId",
          "idempotencyKey",
          "leaseExpiresAt",
          "input"
        ],
        "type": "object"
      },
      "TaskRef": {
        "properties": {
          "attempt": {
            "type": "integer"
          },
          "id": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "attempt"
        ],
        "type": "object"
      }
    },
    "securitySchemes": {
      "appKey": {
        "description": "An AppClient key, lak_\u003cid\u003e_\u003csecret\u003e.",
        "scheme": "bearer",
        "type": "http"
      }
    }
  },
  "info": {
    "description": "The API an application built on Lumen uses, authenticated by a key of its\nAppClient (`Authorization: Bearer lak_\u003cid\u003e_\u003csecret\u003e`).\n\nWorker API (`/worker/v1`): an app's own workers pull the tasks of its remote\nsteps (ClusterStep `executor.remote.app`) from the region the workspace\nlives in. A worker claims tasks, heartbeats them every lease/3, uploads any\nfiles through `artifacts:presign`, and completes or fails each attempt. An\nattempt it no longer holds (its lease ran out and the task was claimed\nagain, or it finished) answers 409, and the worker must stop working on it.\nThe task `idempotencyKey` is stable across attempts: key side effects on it.\n\nErrors are a Status object (`code`, `reason`, `message`).\n",
    "title": "Lumen Platform API",
    "version": "v1"
  },
  "openapi": "3.0.3",
  "paths": {
    "/worker/v1/artifacts:presign": {
      "post": {
        "description": "Returns a PUT to the region's store, among the run's files. Send exactly\nthe returned headers: Content-Type and Content-Length are signed, so the\nstore refuses any other body. The size and type are checked again when\nthe attempt completes.\n",
        "operationId": "presignArtifact",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/PresignRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/PresignResponse"
                }
              }
            },
            "description": "The signed upload."
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/NotHeld"
          }
        },
        "summary": "Sign an upload of one artifact of a held attempt"
      }
    },
    "/worker/v1/claims": {
      "post": {
        "description": "Takes up to `limit` tasks the worker may run, from the workspaces the app\nis installed in, each leased for `leaseSeconds`. With `waitSeconds` the\ncall waits that long for a task when none is ready (a long poll). The\nlabels a worker presents must be granted by the AppClient's\n`spec.workerLabels`; the app label is set for it.\n",
        "operationId": "claimTasks",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/ClaimRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ClaimResponse"
                }
              }
            },
            "description": "The tasks claimed; none when nothing was ready."
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "429": {
            "$ref": "#/components/responses/TooManyRequests"
          }
        },
        "summary": "Claim tasks of the app's remote steps"
      }
    },
    "/worker/v1/heartbeats": {
      "post": {
        "description": "Extends the lease of every attempt the worker still holds and returns\nthose. An attempt missing from the answer was lost: stop working on it.\n",
        "operationId": "heartbeatTasks",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/HeartbeatRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "200": {
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/HeartbeatResponse"
                }
              }
            },
            "description": "The attempts still held."
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          }
        },
        "summary": "Extend the leases of held tasks"
      }
    },
    "/worker/v1/tasks/{taskId}/attempts/{attempt}:complete": {
      "post": {
        "description": "Finishes the attempt with its output, and the run goes on. The output's\nfields are set over the first input document's, its text replaces the\ntext when given, and each artifact (uploaded first through\n`artifacts:presign`) is added as a file.\n",
        "operationId": "completeTask",
        "parameters": [
          {
            "$ref": "#/components/parameters/TaskId"
          },
          {
            "$ref": "#/components/parameters/Attempt"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/CompleteRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "204": {
            "description": "Completed."
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/NotHeld"
          }
        },
        "summary": "Complete a held attempt"
      }
    },
    "/worker/v1/tasks/{taskId}/attempts/{attempt}:fail": {
      "post": {
        "description": "A retryable failure queues the task again after `backoffSeconds` while\nit has attempts left; otherwise the task and its run fail.\n",
        "operationId": "failTask",
        "parameters": [
          {
            "$ref": "#/components/parameters/TaskId"
          },
          {
            "$ref": "#/components/parameters/Attempt"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/FailRequest"
              }
            }
          },
          "required": true
        },
        "responses": {
          "204": {
            "description": "Failed."
          },
          "400": {
            "$ref": "#/components/responses/BadRequest"
          },
          "401": {
            "$ref": "#/components/responses/Unauthorized"
          },
          "403": {
            "$ref": "#/components/responses/Forbidden"
          },
          "409": {
            "$ref": "#/components/responses/NotHeld"
          }
        },
        "summary": "Fail a held attempt"
      }
    }
  },
  "security": [
    {
      "appKey": []
    }
  ],
  "servers": [
    {
      "url": "https://api.go-lumen.ai"
    }
  ]
}
