> ## 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.

# Rotate a dispatch key

> Asks CliqHub to replace a realm's dispatch key pair, which signs the tokens CliqHub uses
when it sends work to the realm's daemons, and returns the new public key. Needs a
signed-in user who administers the realm. The private key never leaves CliqHub.

No credential is needed from this machine. From another host, send `Authorization: Bearer` with a dispatch token CliqHub signed for this daemon or a `cliq_tok_…` personal token of a user in the daemon's realm; this only works once the daemon is connected to CliqHub. See [Authentication](/daemon-api/overview#authentication).



## OpenAPI

````yaml /openapi/daemon-by-tag/daemon-auth.yaml post /v1/auth/rotate_dispatch
openapi: 3.1.0
info:
  title: cliqd API
  version: 1.9.48
  description: >-
    HTTP API of `cliqd`, the local Cliq daemon. Generated from the daemon source
    by `scripts/generate_daemon_openapi.mjs` — do not edit by hand. See the
    [overview](/daemon-api/overview).
servers:
  - url: http://127.0.0.1:4900
    description: Local daemon (default port; `CLIQ_DAEMON_PORT` changes it)
security: []
tags:
  - name: Daemon Sign-in
    description: >-
      Signing this daemon in to CliqHub, choosing the realm it belongs to, and
      minting CliqHub

      tokens with its sign-in. `cliq login` and `cliq logout` use these
      endpoints.


      A daemon that has never joined a realm **enrolls** in one the first time
      it signs in. Once

      enrolled it stays in that realm: signing in again keeps it, and moving it
      to another realm

      needs cliqd started with `--allow-realm-override` plus an explicit
      confirmation. Sign-in

      and sign-out are only accepted from the machine running cliqd.
paths:
  /v1/auth/rotate_dispatch:
    post:
      tags:
        - Daemon Sign-in
      summary: Rotate a dispatch key
      description: >-
        Asks CliqHub to replace a realm's dispatch key pair, which signs the
        tokens CliqHub uses

        when it sends work to the realm's daemons, and returns the new public
        key. Needs a

        signed-in user who administers the realm. The private key never leaves
        CliqHub.


        No credential is needed from this machine. From another host, send
        `Authorization: Bearer` with a dispatch token CliqHub signed for this
        daemon or a `cliq_tok_…` personal token of a user in the daemon's realm;
        this only works once the daemon is connected to CliqHub. See
        [Authentication](/daemon-api/overview#authentication).
      operationId: daemon_post_auth_rotate_dispatch
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                realm_id:
                  type: string
                  minLength: 1
                  description: Realm whose dispatch key rotates
              required:
                - realm_id
            examples:
              default:
                value:
                  realm_id: 5b0c3a7e-2f4d-4b8e-9a51-7c1d2e3f4a5b
      responses:
        '200':
          description: Success.
          content:
            application/json:
              schema:
                type: object
                required:
                  - ok
                  - data
                properties:
                  ok:
                    type: boolean
                    const: true
                  data:
                    $ref: '#/components/schemas/DispatchKey'
              example:
                ok: true
                data:
                  realm_id: 5b0c3a7e-2f4d-4b8e-9a51-7c1d2e3f4a5b
                  public_key_pem: |
                    -----BEGIN PUBLIC KEY-----
                    MIIBIjANBgkq…
                    -----END PUBLIC KEY-----
        '400':
          description: >-
            `PAYLOAD_INVALID` — The body (query string for `GET`) fails the
            request schema. `details` lists each issue.


            `BAD_REQUEST` — The body is not valid JSON or is larger than the
            route allows (10 MB; artifact uploads more).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorReply'
              examples:
                PAYLOAD_INVALID:
                  summary: PAYLOAD_INVALID
                  value:
                    ok: false
                    error:
                      code: PAYLOAD_INVALID
                      message: >-
                        realm_id: Invalid input: expected string, received
                        undefined
                      details:
                        - path: realm_id
                          message: 'Invalid input: expected string, received undefined'
                BAD_REQUEST:
                  summary: BAD_REQUEST
                  value:
                    ok: false
                    error:
                      code: BAD_REQUEST
                      message: >-
                        Request body could not be read: Unexpected token } in
                        JSON at position 12
        '401':
          description: '`UNAUTHORIZED` — The daemon is not signed in to CliqHub.'
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorReply'
              examples:
                UNAUTHORIZED:
                  summary: UNAUTHORIZED
                  value:
                    ok: false
                    error:
                      code: UNAUTHORIZED
                      message: 'Not logged in. Run: cliq login'
        '403':
          description: >-
            `WEB_REQUEST_REFUSED` — The request carries an `Origin` header (it
            came from a web page).


            `HOST_NOT_LOCAL` — A loopback caller addressed a `Host` other than
            localhost (DNS rebinding guard).


            `LOCAL_ONLY` — The daemon isn't connected to CliqHub (no dispatch
            key) and the caller is on another host.


            `FORBIDDEN` — A `cliq_tok_…` token's user is not in this daemon's
            realm ACL, or the ACL is not loaded yet.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorReply'
              examples:
                WEB_REQUEST_REFUSED:
                  summary: WEB_REQUEST_REFUSED
                  value:
                    ok: false
                    error:
                      code: WEB_REQUEST_REFUSED
                      message: cliqd doesn't accept requests from web pages
                HOST_NOT_LOCAL:
                  summary: HOST_NOT_LOCAL
                  value:
                    ok: false
                    error:
                      code: HOST_NOT_LOCAL
                      message: cliqd only answers requests addressed to localhost
                LOCAL_ONLY:
                  summary: LOCAL_ONLY
                  value:
                    ok: false
                    error:
                      code: LOCAL_ONLY
                      message: >-
                        This cliqd isn't connected to CliqHub yet, so from
                        another machine it only accepts a local token (minted by
                        tokens/create on the machine running cliqd)
                FORBIDDEN:
                  summary: FORBIDDEN
                  value:
                    ok: false
                    error:
                      code: FORBIDDEN
                      message: Access denied — identity not in realm ACL
        '500':
          description: >-
            `INTERNAL_ERROR` — CliqHub refused (for example the user is not a
            realm admin; the message is CliqHub's), could not be reached, or
            returned no public key.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorReply'
              examples:
                INTERNAL_ERROR:
                  summary: INTERNAL_ERROR
                  value:
                    ok: false
                    error:
                      code: INTERNAL_ERROR
                      message: Failed to rotate dispatch key
      security:
        - {}
        - DaemonBearer: []
components:
  schemas:
    DispatchKey:
      type: object
      required:
        - realm_id
        - public_key_pem
      properties:
        realm_id:
          type: string
          example: 5b0c3a7e-2f4d-4b8e-9a51-7c1d2e3f4a5b
        public_key_pem:
          type: string
          description: >-
            The realm's new public key. Daemons of the realm use it to check the
            dispatch tokens CliqHub signs.
          example: |
            -----BEGIN PUBLIC KEY-----
            MIIBIjANBgkq…
            -----END PUBLIC KEY-----
    ErrorReply:
      type: object
      description: >-
        Every failure. Switch on `error.code` — it is stable; `message` is for
        people and may change.
      required:
        - ok
        - error
      properties:
        ok:
          type: boolean
          const: false
        error:
          type: object
          required:
            - code
            - message
          properties:
            code:
              type: string
              description: Stable error code. See [Errors](/daemon-api/errors).
              example: TEAM_NOT_FOUND
            message:
              type: string
              description: What went wrong and, where possible, what to do.
              example: Team 'acme/code-review' not found
            details:
              description: >-
                Structured detail when there is some: the list of schema issues
                for `PAYLOAD_INVALID`, the agent problems for
                `TEAM_AGENT_CONFIG_REQUIRED`, …
  securitySchemes:
    DaemonBearer:
      type: http
      scheme: bearer
      description: >-
        Not needed from the same machine. From another host: a dispatch JWT
        CliqHub signed for this daemon, or a `cliq_tok_…` personal token whose
        user is in the daemon's realm.

````

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