Cancel a build

OpenAPI contract

Method
POST
Path
/api/v1/builds/{taskId}/cancel
Security
jwtBearer (bearer) OR automationKey (bearer)
Response status
200 400 401 403 404 429 500
Request and response schemas
JSON
{
  "requestBody": {},
  "responses": {
    "200": {
      "description": "Build cancelled",
      "content": {
        "application/json": {
          "$ref": "#/components/schemas/CompileTaskResponse"
        }
      }
    },
    "400": {
      "description": "Invalid request",
      "content": {
        "application/json": {
          "$ref": "#/components/schemas/RequestError"
        }
      }
    },
    "401": {
      "description": "Authentication required or invalid",
      "content": {
        "application/json": {
          "$ref": "#/components/schemas/SecurityError"
        }
      }
    },
    "403": {
      "description": "Authenticated but not permitted",
      "content": {
        "application/json": {
          "$ref": "#/components/schemas/SecurityError"
        }
      }
    },
    "404": {
      "description": "Requested build was not found",
      "content": {
        "application/json": {
          "$ref": "#/components/schemas/ApiError"
        }
      }
    },
    "429": {
      "description": "HTTP rate limit or API-key NCU usage limit exceeded",
      "content": {
        "application/json": {
          "$ref": "#/components/schemas/RateLimitError"
        }
      }
    },
    "500": {
      "description": "Unexpected server error",
      "content": {
        "application/json": {
          "$ref": "#/components/schemas/ApiError"
        }
      }
    }
  }
}

Request cancellation of a pending or running build with a JWT or an nfy_ key carrying build:write. A project task additionally requires effective build:write capability on its project; a legacy or ad-hoc task uses its exact-owner fallback. The service marks it cancelled, attempts to terminate an active compiler process, and reconciles billing. A completed, failed, or already cancelled task cannot be cancelled again.

Treat cancellation as a state-changing POST, not an idempotent retry target. Read the returned task and, if necessary, poll it until the worker has stopped before attempting deletion. Hosted retrieval remains authenticated and task/resource-authorized, and is available only for a successful task whose output is still stored.