> ## Documentation Index
> Fetch the complete documentation index at: https://docs.halfpagetechnologies.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create an image record

> Create an image record for the resumable upload flow.

Pass `resumable: true` to open the upload in the same call: the response then
carries `upload` with presigned part URLs — PUT each chunk of your file to
its URL, call `POST /upload/{image_id}/complete`, and poll
`GET /image/{image_id}` until `upload_status` is `ready`.

(For files up to a few hundred MB the single-request `POST /upload` is
simpler still — it creates the record for you and returns it `ready`.)

The image counts against your plan's storage cap the moment it is created, so
this returns `402` when the cap is reached — even before any bytes are
uploaded.



## OpenAPI

````yaml /api-reference/openapi.json post /api/v1/image
openapi: 3.1.0
info:
  title: HalfPage API
  description: >
    The **HalfPage API** runs Cellpose-based cell segmentation on your
    microscopy

    images programmatically — upload an image, run a prediction, and export the

    resulting cell masks, ROIs, and measurements.


    ## Base URL


    ```

    https://api.halfpagetechnologies.com/backend/api/v1

    ```


    Every path in this reference is relative to that base URL. A staging
    environment

    is available at
    `https://staging-api.halfpagetechnologies.com/backend/api/v1`.


    ## Authentication


    Authenticate every request with an API key in the `Authorization` header as
    a

    bearer token:


    ```

    Authorization: Bearer hp_live_xxxxxxxxxxxxxxxxxxxxxxxx

    ```


    Create and manage keys from the **API Keys** section of the HalfPage
    dashboard —

    keys cannot be minted through the API. A key is scoped to the organization
    that

    owns it; every resource you create or read is confined to that organization.

    Requests without a valid key receive `401`; a valid key used against an
    endpoint

    outside the public product surface receives `403`.


    ## Core workflow


    Segmentation runs asynchronously on GPU workers, so the API is poll-based:


    1. **Upload an image** (`POST /upload`) as `multipart/form-data` with a
    `file`
       field. One call: the image record is created automatically and the response
       returns it already `ready`, with the `image_id` for the next step.
       *(Large files: `POST /image` with `resumable: true` returns presigned part
       URLs — PUT the chunks, call `POST /upload/{image_id}/complete`, then poll
       `GET /image/{image_id}` until `upload_status` is `ready`.)*
    2. **Pick a model** (`GET /models`) and **submit a prediction**
       (`POST /job/prediction`) with the `image_id` and a `model_id`. This returns a
       `job_id`.
    3. **Poll the job** (`GET /job/{job_id}`) until `status` is `COMPLETED`; the
       response then carries a `segmentation_id`.
    4. **Export** results for that segmentation as CSV measurements
       (`GET /export/{segmentation_id}/measurements.csv`), GeoJSON ROIs
       (`.../rois.geojson`), or an ImageJ ROI archive (`.../rois.zip`). To collect a
       whole project at once, `GET /export/project/{folder_id}/measurements.csv`
       returns every analyzed image in it as one CSV.

    ## Quotas


    Uploads and analyses are metered against your plan. Exceeding your image

    storage cap or monthly analysis cap returns `402` with a human-readable

    `detail` explaining the limit — upgrade your plan to raise it.
  version: 1.0.0
servers:
  - url: https://api.halfpagetechnologies.com/backend
    description: Production
  - url: https://staging-api.halfpagetechnologies.com/backend
    description: Staging
security: []
tags:
  - name: upload
    description: >-
      Get microscopy images into HalfPage. The single-request `POST /upload` is
      the simplest path: it creates the image record for you and returns it
      `ready`. For large files over flaky connections, use the resumable flow:
      `POST /image` with `resumable: true` (or `init`), PUT the presigned parts,
      then `complete` (no ETag bookkeeping needed) and poll the image until
      `ready`.
  - name: job
    description: >-
      Submit and poll asynchronous GPU jobs. `POST /job/prediction` runs
      segmentation on a ready image; `POST /job/training` fine-tunes a custom
      model. Both return a `job_id` you poll via `GET /job/{job_id}` until it is
      `COMPLETED`.
  - name: image
    description: >-
      Create and manage image records. `POST /image` starts the resumable upload
      flow (with `resumable: true` it returns presigned part URLs in the same
      call); poll `GET /image/{image_id}` for the upload lifecycle (`uploading`
      → `processing` → `ready`) and metadata such as pixel `shape`, and delete
      images you no longer need.
  - name: segmentation
    description: >-
      Read the segmentations produced by prediction jobs and derive new ones. A
      segmentation is the set of detected cell ROIs for an image; fetch its
      metadata, regenerate its mask from annotations, or fork a refinement to
      iterate on the result.
  - name: export
    description: >-
      Download results in analysis-ready formats: a CSV of per-cell
      measurements, a GeoJSON of ROI polygons, or a ZIP of ImageJ-compatible
      ROIs. Export one segmentation at a time, or pull every analyzed image in a
      project into a single CSV. Both CSV endpoints accept a `columns` parameter
      to narrow the output to the measurements you care about.
  - name: models
    description: >-
      List the segmentation models available to your organization — the shared
      public base models (e.g. `cpsam`) plus any custom models you have trained
      — to choose a `model_id` for a prediction job.
paths:
  /api/v1/image:
    post:
      tags:
        - image
      summary: Create an image record
      description: >-
        Create an image record for the resumable upload flow.


        Pass `resumable: true` to open the upload in the same call: the response
        then

        carries `upload` with presigned part URLs — PUT each chunk of your file
        to

        its URL, call `POST /upload/{image_id}/complete`, and poll

        `GET /image/{image_id}` until `upload_status` is `ready`.


        (For files up to a few hundred MB the single-request `POST /upload` is

        simpler still — it creates the record for you and returns it `ready`.)


        The image counts against your plan's storage cap the moment it is
        created, so

        this returns `402` when the cap is reached — even before any bytes are

        uploaded.
      operationId: create_image_api_v1_image_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateImageRequest'
        required: true
      responses:
        '201':
          description: The image record was created; upload the pixels next.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateImageResponse'
              example:
                id: 3fa85f64
                name: sample.tif
                upload_status: uploading
                image_type: TIFF
                size: 4194304
                created_at: '2026-07-16T12:00:00Z'
                upload:
                  upload_id: 2~aBcD3fGhIjKlMnOpQrStUvWxYz
                  part_size: 33554432
                  urls:
                    - part_number: 1
                      url: https://halfpage.s3.amazonaws.com/...&partNumber=1
        '401':
          description: >-
            Missing or invalid credentials. Supply a valid `Authorization:
            Bearer hp_live_...` API key.
          content:
            application/json:
              example:
                detail: Requires authentication
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '402':
          description: >-
            Image storage quota exceeded for your plan. Upgrade to store more
            images.
          content:
            application/json:
              example:
                detail: >-
                  You've reached your storage limit of 100 images. Upgrade to
                  store more.
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: The resource does not exist, or is not in your organization.
          content:
            application/json:
              example:
                detail: Image with id 3fa85f64-5717-4562-b3fc-2c963f66afa6 not found
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '422':
          description: >-
            The request body is invalid (e.g. missing `name`/`size`, or a bad
            `size` with `resumable`).
        '501':
          description: >-
            `resumable: true` but storage does not support multipart uploads
            (local dev only).
      security:
        - HTTPBearer: []
components:
  schemas:
    CreateImageRequest:
      properties:
        name:
          type: string
          title: Name
          description: Filename or label for the image.
          examples:
            - sample.tif
        size:
          type: integer
          title: Size
          description: Total size of the image file in bytes.
          examples:
            - 4194304
        image_type:
          $ref: '#/components/schemas/ImageType'
          description: Image format. Only `TIFF` is currently supported.
          default: TIFF
        additional_info:
          additionalProperties: true
          type: object
          title: Additional Info
          description: Arbitrary JSON metadata to store alongside the image.
        folder_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Folder Id
          description: >-
            Optional folder to place the image in; it must belong to your
            organization. API clients typically have no folders and omit this.
        resumable:
          type: boolean
          title: Resumable
          description: >-
            Set to `true` to also open a resumable upload in the same call: the
            response then carries `upload` with presigned part URLs sized for
            `size` (so `size` must be exact). PUT each chunk to its URL, then
            call `POST /upload/{image_id}/complete` — no separate `/init` call
            needed.
          default: false
      type: object
      required:
        - name
        - size
      title: CreateImageRequest
      description: >-
        The metadata for a new image record. The pixels are uploaded separately;

        `size` is the total byte size of the file you will upload. Set
        `resumable`

        to also receive the presigned upload plan in the same response.

        Server-controlled fields (`id`, `created_by`, `organization_id`,

        `upload_status`) are not accepted here.
      examples:
        - name: sample.tif
          size: 4194304
    CreateImageResponse:
      properties:
        id:
          type: string
          title: Id
        name:
          type: string
          title: Name
        upload_status:
          $ref: '#/components/schemas/UploadStatus'
        image_type:
          $ref: '#/components/schemas/ImageType'
        size:
          type: integer
          title: Size
        shape:
          anyOf:
            - items:
                type: integer
              type: array
            - type: 'null'
          title: Shape
        folder_id:
          anyOf:
            - type: string
              format: uuid
            - type: 'null'
          title: Folder Id
        created_at:
          type: string
          format: date-time
          title: Created At
        processed_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Processed At
        upload_error:
          anyOf:
            - type: string
            - type: 'null'
          title: Upload Error
        upload:
          anyOf:
            - $ref: '#/components/schemas/InitUploadResponse'
            - type: 'null'
      type: object
      required:
        - id
        - name
        - upload_status
        - image_type
        - size
        - created_at
      title: CreateImageResponse
      description: |-
        The created image record, plus — when `resumable: true` was requested —
        the presigned upload plan under `upload` (otherwise `null`).
      examples:
        - created_at: '2026-07-01T12:00:00Z'
          id: 3fa85f64-5717-4562-b3fc-2c963f66afa6
          image_type: TIFF
          name: sample.tif
          processed_at: '2026-07-01T12:00:05Z'
          shape:
            - 512
            - 512
            - 3
          size: 4194304
          upload_status: ready
    ErrorResponse:
      properties:
        detail:
          type: string
          title: Detail
          examples:
            - Job with id 11111111-1111-1111-1111-111111111111 not found
      type: object
      required:
        - detail
      title: ErrorResponse
      description: |-
        The body returned for a handled error: a single human-readable
        ``detail`` string.
    ImageType:
      type: string
      enum:
        - TIFF
      title: ImageType
    UploadStatus:
      type: string
      enum:
        - uploading
        - processing
        - ready
        - failed
      title: UploadStatus
      description: >-
        Lifecycle of a resumable S3 multipart image upload.


        uploading  -> row created, bytes still being PUT directly to S3

        processing -> object landed in S3, backend is converting it off the
        event loop

        ready      -> conversion done, `shape` populated, image is usable

        failed     -> aborted or conversion failed (orphan-sweep cron will reap
        it)
    InitUploadResponse:
      properties:
        upload_id:
          type: string
          title: Upload Id
        part_size:
          type: integer
          title: Part Size
        urls:
          items:
            $ref: '#/components/schemas/PartUrlOut'
          type: array
          title: Urls
      type: object
      required:
        - upload_id
        - part_size
        - urls
      title: InitUploadResponse
      description: >-
        The presigned multipart plan: PUT each chunk of the file to its `url`

        (in part order), then call `/complete` — no body needed, the server

        verifies the uploaded parts with storage directly.


        The internal S3 object key is deliberately not exposed: the presigned
        `url`s

        already encode everything the client needs, and the key layout is a

        server-side implementation detail we keep off the public contract.
      examples:
        - part_size: 33554432
          upload_id: 2~aBcD3fGhIjKlMnOpQrStUvWxYz
          urls:
            - part_number: 1
              url: https://halfpage.s3.amazonaws.com/...&partNumber=1
            - part_number: 2
              url: https://halfpage.s3.amazonaws.com/...&partNumber=2
    PartUrlOut:
      properties:
        part_number:
          type: integer
          title: Part Number
        url:
          type: string
          title: Url
      type: object
      required:
        - part_number
        - url
      title: PartUrlOut
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````