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

# Claim a queued run

> A daemon claims a run CliqHub offered to its realm (see Start a run, realm path); the
first claim wins and CliqHub then sends that daemon the run. Daemons call this with their
realm token; a realm member may also claim on a daemon's behalf.

Daemon only: requires the daemon's realm token (`Authorization: Bearer cliq_dt_…`) for the realm the record belongs to. Queue item must be in the token realm.



## OpenAPI

````yaml /openapi/hub-by-tag/hub-runs.yaml post /v1/runs/claim
openapi: 3.0.3
info:
  title: 'CliqHub API: Runs'
  version: 1.0.0
  description: >-
    Runs of a team on a daemon. People start runs (Start a run), follow them
    (Get a run, Stream

    run activity, Search run logs, Get run telemetry), and control them (Cancel
    a run, Resume a

    run, Supply run inputs). CliqHub hands each control to the run's daemon,
    which must be

    online: when it is not, the call fails with a `run/daemon_offline` or
    `run/daemon_stranded`

    conflict (cancel instead marks the run cancelled on CliqHub).


    Daemons report what happens during a run through the other endpoints here,
    with their realm

    token: Record a new run, Update run status, Complete a run, and three
    separate channels for

    run activity (the live timeline), run telemetry (token usage and traces) and
    run logs (text).
servers:
  - url: https://{host}
    variables:
      host:
        default: cliqhub.io
        description: CliqHub host
security: []
tags:
  - name: Runs
    description: >-
      Runs of a team on a daemon. People start runs (Start a run), follow them
      (Get a run, Stream

      run activity, Search run logs, Get run telemetry), and control them
      (Cancel a run, Resume a

      run, Supply run inputs). CliqHub hands each control to the run's daemon,
      which must be

      online: when it is not, the call fails with a `run/daemon_offline` or
      `run/daemon_stranded`

      conflict (cancel instead marks the run cancelled on CliqHub).


      Daemons report what happens during a run through the other endpoints here,
      with their realm

      token: Record a new run, Update run status, Complete a run, and three
      separate channels for

      run activity (the live timeline), run telemetry (token usage and traces)
      and run logs (text).
paths:
  /v1/runs/claim:
    post:
      tags:
        - Runs
      summary: Claim a queued run
      description: >-
        A daemon claims a run CliqHub offered to its realm (see Start a run,
        realm path); the

        first claim wins and CliqHub then sends that daemon the run. Daemons
        call this with their

        realm token; a realm member may also claim on a daemon's behalf.


        Daemon only: requires the daemon's realm token (`Authorization: Bearer
        cliq_dt_…`) for the realm the record belongs to. Queue item must be in
        the token realm.
      operationId: POST_v1_runs_claim
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                queue_item_id:
                  type: string
                  minLength: 1
                  description: The offered queue item.
                daemon_id:
                  type: string
                  minLength: 1
                  description: The daemon claiming it.
              required:
                - queue_item_id
                - daemon_id
            examples:
              default:
                value:
                  queue_item_id: e1d2c3b4-a5f6-4789-8a0b-1c2d3e4f5a6b
                  daemon_id: 7d1c2b3a-4e5f-4a6b-8c7d-9e0f1a2b3c4d
      responses:
        '200':
          description: Success.
          content:
            application/json:
              schema:
                type: object
                required:
                  - ok
                  - data
                properties:
                  ok:
                    type: boolean
                    enum:
                      - true
                    description: Always `true` on success.
                  data:
                    $ref: '#/components/schemas/QueueItemData'
              example:
                ok: true
                data:
                  id: e1d2c3b4-a5f6-4789-8a0b-1c2d3e4f5a6b
                  realm_id: 5b0c3a7e-2f4d-4b8e-9a51-7c1d2e3f4a5b
                  kind: run
                  payload:
                    team_id: 3f6c2a8e-6b1d-4c1e-9a57-0d2f4b8e91c4
                  priority: 0
                  status: claimed
                  claimed_by: 7d1c2b3a-4e5f-4a6b-8c7d-9e0f1a2b3c4d
                  claimed_at: 1759834200500
                  run_id: null
                  results: null
                  submitted_by: 1a2b3c4d-5e6f-4a7b-8c9d-0e1f2a3b4c5d
                  submitted_at: 1759834200000
                  error: null
                  created_at: 1759834200000
                  updated_at: 1759834200500
        '401':
          description: >-
            `unauthorized`: No `Authorization` header, or the token is
            malformed, expired or revoked.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HubErr'
              examples:
                unauthorized:
                  summary: unauthorized
                  value:
                    ok: false
                    error:
                      code: unauthorized
                      message: Authentication required
        '403':
          description: >-
            `forbidden`: A user token was used, or the daemon's token belongs to
            another realm.


            `forbidden`: The daemon token's realm is not the queue item's realm,
            or the daemon is not a member of it; for a user, not a member of the
            realm.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HubErr'
              examples:
                forbidden:
                  summary: forbidden
                  value:
                    ok: false
                    error:
                      code: forbidden
                      message: You do not have access to do this
                forbidden (endpoint):
                  summary: forbidden (endpoint)
                  value:
                    ok: false
                    error: Daemon token realm does not match queue item
                    code: forbidden
        '404':
          description: '`not_found`: No queue item has this id.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HubErr'
              examples:
                not_found:
                  summary: not_found
                  value:
                    ok: false
                    error: >-
                      Queue item 'e1d2c3b4-a5f6-4789-8a0b-1c2d3e4f5a6b' not
                      found
                    code: not_found
        '409':
          description: '`conflict`: Another daemon claimed the item first.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HubErr'
              examples:
                conflict:
                  summary: conflict
                  value:
                    ok: false
                    error: >-
                      Queue item 'e1d2c3b4-a5f6-4789-8a0b-1c2d3e4f5a6b' already
                      claimed by '3a4b5c6d-7e8f-4a9b-8c0d-1e2f3a4b5c6d'
                    code: conflict
        '422':
          description: >-
            `invalid_params`: The body fails the request schema: a required
            field is missing or a value has the wrong type or format. The
            message lists every issue as `field: problem`.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HubErr'
              examples:
                invalid_params:
                  summary: invalid_params
                  value:
                    ok: false
                    error: 'queue_item_id: Required'
                    code: invalid_params
        '500':
          description: >-
            `internal_error`: An unexpected server fault. Retry later; if it
            persists, report it with the time of the request.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HubErr'
              examples:
                internal_error:
                  summary: internal_error
                  value:
                    ok: false
                    error: Internal server error
                    code: internal_error
      security:
        - BearerAuth: []
components:
  schemas:
    QueueItemData:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Queue item UUID
        realm_id:
          type: string
          description: Realm that owns the queue
        kind:
          type: string
          description: Queue kind (run, install, …)
        payload:
          type: object
          additionalProperties:
            type: object
            additionalProperties: true
          description: Kind-specific payload
        priority:
          type: number
          description: Higher wins claim order
        status:
          type: string
          description: queued | offered | claimed | …
        claimed_by:
          type: string
          nullable: true
          description: Daemon id that claimed, or null
        claimed_at:
          type: number
          nullable: true
          description: Claim time (unix ms)
        run_id:
          type: string
          nullable: true
          description: Linked run id when set
        results:
          type: object
          additionalProperties: true
          nullable: true
          description: Terminal results payload
        submitted_by:
          type: string
          description: User id that enqueued
        submitted_at:
          type: number
          description: Enqueue time (unix ms)
        error:
          type: string
          nullable: true
          description: Error message when failed
        created_at:
          type: number
          description: Row create time (unix ms)
        updated_at:
          type: number
          description: Row update time (unix ms)
      required:
        - id
        - realm_id
        - kind
        - payload
        - priority
        - status
        - claimed_by
        - claimed_at
        - run_id
        - results
        - submitted_by
        - submitted_at
        - error
        - created_at
        - updated_at
      description: Realm dispatch queue item
    HubErr:
      type: object
      required:
        - ok
        - error
      description: >-
        Every failure. Route-policy denials (401/403/404, and 400 when neither
        realm_id nor org_id was sent) answer `error` as `{ code, message }`;
        errors raised by the endpoint answer `error` as the message with the
        code beside it in `code`. Every error has a code. See
        [Errors](/hub-api/errors).
      properties:
        ok:
          type: boolean
          description: Always false on error
        error:
          description: The message, or `{ code, message }` for an access denial.
          oneOf:
            - type: string
            - type: object
              required:
                - code
                - message
              properties:
                code:
                  type: string
                message:
                  type: string
        code:
          type: string
          description: Stable error code of an endpoint error.
        details:
          type: object
          additionalProperties: true
          description: Structured detail, when there is some.
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: cliq_tok_* | cliq_dt_*
      description: >-
        User PAT (`cliq_tok_…`, including session-scoped) or realm token
        (`cliq_dt_…`).

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.