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

# Rotate Secret

> Generates a new key (new prefix and secret) and returns it **once**.
There is no overlap window: the old key stops working at once
(within 60 seconds on every instance). Only `secret` keys rotate;
machine (`jwt`) keys are re-provisioned. Requires `api-key:rotate`.

The write only lands while the key still holds the secret and the
unrevoked state the request read. When a concurrent rotation or
revocation wins, the request answers `409` and no secret is
returned: read the key again and retry.




## OpenAPI

````yaml POST /permission/api-key/{document_id}/rotate
openapi: 3.0.1
info:
  title: API Key API
  description: |
    Credentials for machines and external systems (ADR 0105).

    A key has a `kind`:

    - `secret` — created through this API. The key reads
      `hzk_<env>_<prefix>_<secret>` (`env` is `live` on production and
      `test` elsewhere). Horizon stores only the `prefix` and the sha256 of
      the secret, and returns the plaintext key **once**, from create and
      rotate. Send it in the `x-api-key` header.
    - `jwt` — the MaihueGO machine path: a Bearer JWT minted at machine
      provisioning whose payload carries the key id. It keeps working until
      the key is revoked, deactivated, deleted or expired.

    A revoked (`revoked_at`), expired (`expiration_date`), inactive or
    deleted key answers `401`. Each `secret` key spends a sliding window of
    `rate_limit_per_minute` requests (600 when null); past it the API answers
    `429` with `Retry-After` and `X-RateLimit-Limit|Remaining|Reset`.
    Revocation and rotation reach every instance within 60 seconds.

    The management endpoints below require the matching `api-key:*` or
    `api-key-notification-gateway:*` permission. `secret_hash` is never
    returned, filtered or sorted on.
  version: '2026-10-21'
servers:
  - description: Production
    url: https://api.bbrands.io/api/v3
  - description: Certification
    url: https://certification.api.bbrands.io/api/v3
  - description: Development
    url: https://development.api.bbrands.io/api/v3
security:
  - bearerAuth: []
  - apiKeyAuth: []
tags:
  - name: API Key
    description: Keys, their secret lifecycle and revocation.
  - name: API Key Notification Gateway
    description: Notification gateways a key may send for.
paths:
  /permission/api-key/{document_id}/rotate:
    post:
      tags:
        - API Key
      summary: Rotate secret
      description: |
        Generates a new key (new prefix and secret) and returns it **once**.
        There is no overlap window: the old key stops working at once
        (within 60 seconds on every instance). Only `secret` keys rotate;
        machine (`jwt`) keys are re-provisioned. Requires `api-key:rotate`.

        The write only lands while the key still holds the secret and the
        unrevoked state the request read. When a concurrent rotation or
        revocation wins, the request answers `409` and no secret is
        returned: read the key again and retry.
      operationId: apiKeyRotate
      parameters:
        - $ref: '#/components/parameters/DocumentId'
      responses:
        '200':
          description: ApiKey secret rotated
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/ApiKeyWithSecret'
                  message:
                    type: string
                  meta:
                    $ref: '#/components/schemas/Meta'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '409':
          $ref: '#/components/responses/Conflict'
        '429':
          $ref: '#/components/responses/TooManyRequests'
components:
  parameters:
    DocumentId:
      name: document_id
      in: path
      required: true
      description: API key identifier.
      schema:
        type: string
        format: uuid
  schemas:
    ApiKeyWithSecret:
      allOf:
        - $ref: '#/components/schemas/ApiKey'
        - type: object
          properties:
            secret:
              type: string
              description: >-
                The plaintext key, `hzk_<env>_<prefix>_<secret>`. Returned only
                by create and rotate.
              example: hzk_live_k7m3q9xa_3q2-7wQ1eW9rT5yU8iO0pA4sD6fG2hJ1kL3zX5cV7bN
    Meta:
      type: object
      properties:
        correlation:
          type: string
          description: Request correlation id; quote it when reporting an issue.
        status:
          type: integer
        timestamp:
          type: string
          format: date-time
        version:
          type: string
          nullable: true
    ApiKey:
      type: object
      properties:
        document_id:
          type: string
          format: uuid
        account:
          type: string
          format: uuid
          description: Account the key acts for.
        name:
          type: string
        description:
          type: string
          nullable: true
        kind:
          type: string
          enum:
            - jwt
            - secret
          description: '`secret` keys use `x-api-key`; `jwt` keys are MaihueGO machines.'
        prefix:
          type: string
          nullable: true
          description: Public lookup part of a `secret` key (8 characters).
        expiration_date:
          type: string
          format: date-time
          nullable: true
          description: The key answers 401 from this instant; null never expires.
        rate_limit_per_minute:
          type: integer
          nullable: true
          description: >-
            Requests per minute for a `secret` key; null uses the platform
            default (600).
        last_used_at:
          type: string
          format: date-time
          nullable: true
          description: Last authenticated request, written at most once per minute.
        rotated_at:
          type: string
          format: date-time
          nullable: true
        revoked_at:
          type: string
          format: date-time
          nullable: true
        revoked_by:
          type: string
          format: uuid
          nullable: true
        revoked_reason:
          type: string
          nullable: true
        created_by:
          type: string
          format: uuid
          nullable: true
        is_actived:
          type: boolean
        is_deleted:
          type: boolean
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
          nullable: true
        deleted_at:
          type: string
          format: date-time
          nullable: true
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
              description: Machine-readable error code.
            errors:
              type: array
              items: {}
            message:
              type: string
        meta:
          $ref: '#/components/schemas/Meta'
  responses:
    Unauthorized:
      description: Missing, invalid, revoked or expired credentials
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: The caller lacks the required permission
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    NotFound:
      description: Record not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Conflict:
      description: >-
        The action conflicts with the key's state (machine key, already revoked,
        or changed by a concurrent rotation or revocation)
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    TooManyRequests:
      description: Rate limit exceeded
      headers:
        Retry-After:
          $ref: '#/components/headers/RetryAfter'
        X-RateLimit-Limit:
          $ref: '#/components/headers/RateLimitLimit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/RateLimitRemaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/RateLimitReset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  headers:
    RetryAfter:
      description: Seconds until the key's window frees a request.
      schema:
        type: integer
    RateLimitLimit:
      description: Requests per minute allowed for the key.
      schema:
        type: integer
    RateLimitRemaining:
      description: Requests left in the current window.
      schema:
        type: integer
    RateLimitReset:
      description: Unix seconds when the window frees a request.
      schema:
        type: integer
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
    apiKeyAuth:
      type: apiKey
      in: header
      name: x-api-key
      description: A `secret` API key, `hzk_<env>_<prefix>_<secret>`.

````

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