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

# Generate a lot or serial run

> Reserve a contiguous block of identifiers. **Lot** templates: small batches run inline and return `201` with a `reserved` run; batches above the async threshold (or `force_async=true`) return `202` with a `queued` run a Celery worker completes. A sync hard collision returns `409` with the `hard_collisions` payload. **Serial** templates (`target_field=serial`, C-2712): always async — up to 10,000,000 per run — and always return `202` with a `queued` run; poll `GET /lots/runs/{id}/` or subscribe to the SSE stream for the outcome, and export the reserved serials via `GET /lots/runs/{id}/serials.csv|.jsonl`. In every case the `failed_collision` run is persisted and linkable.



## OpenAPI

````yaml /openapi/openapi-products.json post /products/api/v1/lots/runs/
openapi: 3.1.0
info:
  title: Products API
  version: 1.0.0
  description: >
    Look up, claim, and browse GTINs in the Closient product repository.


    ## Authentication


    All endpoints require an API key passed via the `X-API-Key` HTTP header,
    unless otherwise noted.


    ```

    X-API-Key: csb_<body>_<checksum>

    ```


    Generate API keys in **Settings > API Keys** in your dashboard, or via the
    Account API.

    Session-based (cookie) authentication is also accepted for browser-based
    access.


    ## Rate Limits


    | Tier        | Requests / minute | Requests / day |

    |-------------|-------------------|----------------|

    | Default     | 300               | 10,000         |

    | Custom      | Contact us        | Contact us     |


    Rate-limit headers are included on every response so callers can
    self-throttle without

    hitting our 429s ("informed governor"):


    - `RateLimit-Policy` — every active window, e.g. `300;w=60, 10000;w=86400`

    - `RateLimit-Limit` — quota for the **most-restrictive** currently-active
    window

    - `RateLimit-Remaining` — requests left in that window

    - `RateLimit-Reset` — seconds until that window resets (relative; clock-skew
    safe)


    Legacy `X-RateLimit-*` aliases are also emitted for back-compat.
    `X-RateLimit-Reset`

    keeps the absolute Unix-timestamp shape to avoid breaking existing
    consumers.


    When rate-limited, you receive `429 Too Many Requests` with a
    `retry_after_seconds` field

    in the error envelope and a `Retry-After` header.


    ## Pagination


    List endpoints return paginated results in this envelope:


    ```json

    {
      "data": [...],
      "pagination": {
        "page": 1,
        "page_size": 25,
        "total_count": 342,
        "total_pages": 14,
        "has_next": true,
        "has_previous": false
      }
    }

    ```


    Use `?page=2&page_size=50` query parameters. Maximum page size is 100.


    ## Error Responses


    All errors conform to [RFC 9457 Problem
    Details](https://www.rfc-editor.org/rfc/rfc9457)

    with `Content-Type: application/problem+json`:


    ```json

    {
      "type": "https://closient.com/docs/errors/not_found",
      "title": "Not Found",
      "status": 404,
      "detail": "The requested resource was not found.",
      "error_code": "not_found",
      "retryable": false,
      "timestamp": "2026-03-31T12:00:00+00:00"
    }

    ```


    Common error codes: `unauthorized` (401), `forbidden` (403), `not_found`
    (404),

    `validation_error` (422), `rate_limited` (429), `internal_error` (500).
  termsOfService: https://www.closient.com/terms/
servers:
  - url: https://www.closient.com
security: []
tags:
  - name: Products
    description: Look up, claim, and browse products and trade items.
  - name: Product Group
    description: Manage GDSN packaging hierarchy relationships.
  - name: Import
    description: Bulk import products from CSV files.
  - name: QR
    description: Generate QR codes encoding GS1 Digital Link URLs.
  - name: Codes
    description: Generate GS1 DataMatrix and 1D barcodes (EAN/UPC/ITF-14/Code128).
  - name: Digital Link
    description: >-
      Parse GS1 Digital Link URIs into structured AIs (GTIN, lot, expiry,
      serial).
  - name: Labels
    description: >-
      Bulk label-export jobs: ZIPs of QR / DataMatrix / 1D symbols and multi-up
      sheet PDFs, async via Celery with status polling.
  - name: Lots
    description: >-
      Lot generator v2: format templates with persistent counters,
      reserve/commit/discard runs, soft/hard collision handling, and an async
      Celery path with SSE progress.
externalDocs:
  description: Closient Documentation
  url: https://docs.closient.com
paths:
  /products/api/v1/lots/runs/:
    post:
      tags:
        - Lots
      summary: Generate a lot or serial run
      description: >-
        Reserve a contiguous block of identifiers. **Lot** templates: small
        batches run inline and return `201` with a `reserved` run; batches above
        the async threshold (or `force_async=true`) return `202` with a `queued`
        run a Celery worker completes. A sync hard collision returns `409` with
        the `hard_collisions` payload. **Serial** templates
        (`target_field=serial`, C-2712): always async — up to 10,000,000 per run
        — and always return `202` with a `queued` run; poll `GET
        /lots/runs/{id}/` or subscribe to the SSE stream for the outcome, and
        export the reserved serials via `GET
        /lots/runs/{id}/serials.csv|.jsonl`. In every case the
        `failed_collision` run is persisted and linkable.
      operationId: apps_products_api_lots_create_lot_run
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/LotRunCreateIn'
        required: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LotRunOut'
        '202':
          description: Accepted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/LotRunOut'
        '403':
          description: Forbidden
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorOut'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorOut'
        '409':
          description: Conflict
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HardCollisionResponseOut'
        '422':
          description: Unprocessable Content
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorOut'
      security:
        - APIKeyHeaderAuth: []
        - OAuthTokenAuth: []
        - SessionAuth: []
components:
  schemas:
    LotRunCreateIn:
      description: Request body for `POST /lots/runs/`.
      examples:
        - gtin: '00012345678905'
          quantity: 5
          template_id: AbCdEfGhIjKlMnOpQrStUv
      properties:
        template_id:
          description: Template to generate against (id as UUID or shortuuid).
          title: Template Id
          type: string
        gtin:
          description: GTIN of the product the generated lots belong to.
          title: Gtin
          type: string
        lot_id:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Lot (id as UUID or shortuuid) the generated serials belong to.
            **Optional for serial templates** (`target_field=serial`, C-4103) —
            a serialized unit may be unbatched (its identity is the SGTIN, GTIN
            + serial); omit to mint serials with no lot. Ignored for lot
            templates.
          title: Lot Id
        quantity:
          description: >-
            How many identifiers to generate. Lots cap at 100,000; serial
            templates (`target_field=serial`) accept up to 10,000,000 and always
            run async.
          maximum: 10000000
          minimum: 1
          title: Quantity
          type: integer
        tag:
          anyOf:
            - maxLength: 128
              type: string
            - type: 'null'
          description: Scope tag — required when the template's scope_kind is `tag`.
          title: Tag
        force_async:
          default: false
          description: >-
            Force the Celery async path even for a small batch (returns a
            `queued` run).
          title: Force Async
          type: boolean
        idempotency_key:
          anyOf:
            - maxLength: 128
              type: string
            - type: 'null'
          description: >-
            Optional client request id. A repeat within 5 minutes returns the
            existing run.
          title: Idempotency Key
      required:
        - template_id
        - gtin
        - quantity
      title: LotRunCreateIn
      type: object
    LotRunOut:
      description: A generation run and its outcome.
      examples:
        - chunks_done: 1
          chunks_total: 1
          counter_state_after: 5
          counter_state_before: 0
          created: '2026-05-02T10:00:00Z'
          created_by_id: UsAbCdEfGhIjKlMnOpQrSt
          discard_reason: ''
          first_id: LOT-2026123-0001
          generated_ids:
            - LOT-2026123-0001
            - LOT-2026123-0002
            - LOT-2026123-0003
            - LOT-2026123-0004
            - LOT-2026123-0005
          gtin: '00012345678905'
          hard_collisions: []
          id: RnAbCdEfGhIjKlMnOpQrSt
          last_id: LOT-2026123-0005
          quantity: 5
          scope_key: '00012345678905'
          soft_collision_count: 0
          status: reserved
          template_id: AbCdEfGhIjKlMnOpQrStUv
          template_version: 1
      properties:
        id:
          description: Run id (22-char shortuuid). Use in `/lots/runs/{id}/` paths.
          title: Id
          type: string
        template_id:
          description: Template this run generated against.
          title: Template Id
          type: string
        template_version:
          description: Template version pinned at generation time.
          title: Template Version
          type: integer
        scope_key:
          description: Counter scope key derived from the template's scope_kind.
          title: Scope Key
          type: string
        gtin:
          description: GTIN of the product the generated lots belong to.
          title: Gtin
          type: string
        quantity:
          description: Number of identifiers requested.
          title: Quantity
          type: integer
        status:
          $ref: '#/components/schemas/LotRunStatusEnum'
          description: Lifecycle state of the run.
        first_id:
          anyOf:
            - type: string
            - type: 'null'
          description: First identifier in the reserved block; null until reserved.
          title: First Id
        last_id:
          anyOf:
            - type: string
            - type: 'null'
          description: Last identifier in the reserved block; null until reserved.
          title: Last Id
        counter_state_before:
          anyOf:
            - type: integer
            - type: 'null'
          description: Counter value (post-reset) before this run advanced it.
          title: Counter State Before
        counter_state_after:
          anyOf:
            - type: integer
            - type: 'null'
          description: Counter value after this run; null on failed_collision.
          title: Counter State After
        generated_ids:
          description: Denormalized list of identifiers rendered by this run.
          items:
            type: string
          title: Generated Ids
          type: array
        soft_collision_count:
          description: Random-source retries that resolved during generation.
          title: Soft Collision Count
          type: integer
        hard_collisions:
          description: Populated only on `failed_collision` runs; empty otherwise.
          items:
            $ref: '#/components/schemas/HardCollisionOut'
          title: Hard Collisions
          type: array
        chunks_done:
          anyOf:
            - type: integer
            - type: 'null'
          description: 'Async progress: chunks written so far.'
          title: Chunks Done
        chunks_total:
          anyOf:
            - type: integer
            - type: 'null'
          description: 'Async progress: total chunks the run will write.'
          title: Chunks Total
        created_by_id:
          anyOf:
            - type: string
            - type: 'null'
          description: User id that created the run; null if the user was deleted.
          title: Created By Id
        queued_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          description: When the async run was enqueued.
          title: Queued At
        generating_started_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          description: When the worker began generating.
          title: Generating Started At
        committed_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          description: When the run was committed.
          title: Committed At
        discarded_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          description: When the run was discarded.
          title: Discarded At
        failed_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          description: When the run failed on a hard collision.
          title: Failed At
        discard_mode:
          anyOf:
            - $ref: '#/components/schemas/LotDiscardModeEnum'
            - type: 'null'
          description: '`rollback` or `burn` on a discarded run; null otherwise.'
        discard_reason:
          default: ''
          description: Free-text reason recorded when the run was discarded.
          title: Discard Reason
          type: string
        created:
          description: Creation timestamp (ISO-8601).
          format: date-time
          title: Created
          type: string
      required:
        - id
        - template_id
        - template_version
        - scope_key
        - gtin
        - quantity
        - status
        - generated_ids
        - soft_collision_count
        - hard_collisions
        - created
      title: LotRunOut
      type: object
    ErrorOut:
      description: |-
        RFC 9457 Problem Details response.

        All API errors are returned in this format with Content-Type:
        application/problem+json.
      examples:
        - detail: The requested resource was not found.
          error_code: not_found
          retryable: false
          status: 404
          timestamp: '2026-03-31T12:00:00+00:00'
          title: Not Found
          type: https://closient.com/docs/errors/not_found
        - detail: Validation error.
          details:
            - loc:
                - body
                - name
              msg: Field required
              type: missing
          error_code: validation_error
          retryable: false
          status: 422
          timestamp: '2026-03-31T12:00:00+00:00'
          title: Validation Error
          type: https://closient.com/docs/errors/validation_error
        - detail: Rate limit exceeded. Please try again later.
          error_code: rate_limited
          retry_after: 31
          retryable: true
          status: 429
          timestamp: '2026-03-31T12:00:00+00:00'
          title: Rate Limited
          type: https://closient.com/docs/errors/rate_limited
      properties:
        type:
          description: URI reference identifying the error type.
          title: Type
          type: string
        title:
          description: Short human-readable summary of the error.
          title: Title
          type: string
        status:
          description: HTTP status code.
          title: Status
          type: integer
        detail:
          description: Human-readable explanation of this specific occurrence.
          title: Detail
          type: string
        error_code:
          description: Machine-readable error code (e.g. not_found, unauthorized).
          title: Error Code
          type: string
        retryable:
          default: false
          description: Whether retrying the same request can succeed.
          title: Retryable
          type: boolean
        timestamp:
          description: ISO 8601 timestamp of when the error occurred.
          title: Timestamp
          type: string
        retry_after:
          anyOf:
            - type: integer
            - type: 'null'
          description: Seconds to wait before retrying (when applicable).
          title: Retry After
        owner_action_required:
          anyOf:
            - type: boolean
            - type: 'null'
          description: Whether the error requires account owner intervention.
          title: Owner Action Required
        details:
          description: Additional context (validation errors, etc.).
          title: Details
      required:
        - type
        - title
        - status
        - detail
        - error_code
        - timestamp
      title: ErrorOut
      type: object
    HardCollisionResponseOut:
      description: |-
        409 body for a sync run aborted by a hard collision. The run is still
        persisted (in `failed_collision` status) and linkable via `run_id`.
      examples:
        - detail: Generation aborted by a hard collision; counter not advanced.
          hard_collisions:
            - conflicts_with_lot_id: AbCdEfGhIjKlMnOpQrStUv
              generated_id: LOT-2026123-0001
              position: 0
          run_id: RnAbCdEfGhIjKlMnOpQrSt
      properties:
        detail:
          description: Human-readable summary.
          title: Detail
          type: string
        run_id:
          description: Id of the persisted `failed_collision` run.
          title: Run Id
          type: string
        hard_collisions:
          description: Every unresolved collision.
          items:
            $ref: '#/components/schemas/HardCollisionOut'
          title: Hard Collisions
          type: array
      required:
        - detail
        - run_id
        - hard_collisions
      title: HardCollisionResponseOut
      type: object
    LotRunStatusEnum:
      description: |-
        Lifecycle state of a lot generation run.

        Mirrors :class:`apps.products.models.LotRunStatus`. ``queued`` /
        ``generating`` are the async in-flight states; ``reserved`` awaits
        commit/discard; ``committed`` / ``discarded`` / ``failed_collision`` are
        terminal.
      enum:
        - queued
        - generating
        - reserved
        - committed
        - discarded
        - failed_collision
      title: LotRunStatusEnum
      type: string
    HardCollisionOut:
      description: One unresolved collision that aborted a run.
      examples:
        - conflicts_with_lot_id: AbCdEfGhIjKlMnOpQrStUv
          conflicts_with_run_id: ZyXwVuTsRqPoNmLkJiHgFe
          generated_id: LOT-2026123-0001
          position: 0
      properties:
        position:
          description: Zero-based index within the batch that collided.
          title: Position
          type: integer
        generated_id:
          description: The identifier that collided.
          title: Generated Id
          type: string
        conflicts_with_lot_id:
          anyOf:
            - type: string
            - type: 'null'
          description: Existing lot id it collided with, if any (lot runs).
          title: Conflicts With Lot Id
        conflicts_with_serial_id:
          anyOf:
            - type: string
            - type: 'null'
          description: Existing serial id it collided with, if any (serial runs, C-2712).
          title: Conflicts With Serial Id
        conflicts_with_run_id:
          anyOf:
            - type: string
            - type: 'null'
          description: >-
            Best-effort id of the run that first generated the conflicting id;
            null for legacy imports.
          title: Conflicts With Run Id
      required:
        - position
        - generated_id
      title: HardCollisionOut
      type: object
    LotDiscardModeEnum:
      description: >-
        How a discarded run treats its identifiers and counter.


        Mirrors :class:`apps.products.models.DiscardMode`. ``rollback`` returns
        the

        IDs to the counter (only when safe); ``burn`` consumes them permanently.
      enum:
        - rollback
        - burn
      title: LotDiscardModeEnum
      type: string
  securitySchemes:
    APIKeyHeaderAuth:
      type: apiKey
      in: header
      name: X-API-Key
    OAuthTokenAuth:
      type: http
      scheme: bearer
    SessionAuth:
      type: apiKey
      in: cookie
      name: sessionid

````