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

# Create API Key

> Creates a `secret` key and returns the plaintext key in `secret`
**once**; store it right away, it cannot be recovered, only rotated.
The caller is recorded as `created_by`. Requires `api-key:create`.




## OpenAPI

````yaml POST /permission/api-key
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:
    post:
      tags:
        - API Key
      summary: Create API key
      description: |
        Creates a `secret` key and returns the plaintext key in `secret`
        **once**; store it right away, it cannot be recovered, only rotated.
        The caller is recorded as `created_by`. Requires `api-key:create`.
      operationId: apiKeyCreate
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApiKeyCreateBody'
      responses:
        '201':
          description: ApiKey record created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    $ref: '#/components/schemas/ApiKeyWithSecret'
                  message:
                    type: string
                  meta:
                    $ref: '#/components/schemas/Meta'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '429':
          $ref: '#/components/responses/TooManyRequests'
components:
  schemas:
    ApiKeyCreateBody:
      type: object
      additionalProperties: false
      required:
        - account
        - name
      properties:
        account:
          type: string
          format: uuid
        name:
          type: string
          maxLength: 255
        description:
          type: string
          maxLength: 255
          nullable: true
        expiration_date:
          type: string
          format: date-time
          nullable: true
          description: Must be in the future; null or absent never expires.
        rate_limit_per_minute:
          type: integer
          minimum: 1
          maximum: 100000
          nullable: true
    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:
    BadRequest:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    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'
    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.