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

# Create a key

> A source key with scopes. The secret is shown once.



## OpenAPI

````yaml openapi/en/control.json POST /v1/sources/{source_id}/keys
openapi: 3.1.0
info:
  title: Niadra control API
  version: '1'
  description: >-
    Tenants, projects, sources, keys, people, configuration and usage. It never
    receives customer content.
servers:
  - url: https://control.api.niadra.com
security: []
paths:
  /v1/sources/{source_id}/keys:
    post:
      summary: Create a key
      description: >-
        Issues a key for the source. Without `scopes`, the scopes follow the
        audience of the source. The secret is returned once; Niadra keeps only
        two hashes of it. Needs the admin role.


        **Authentication.** Person token issued by the control plane
        (`Authorization: Bearer <JWT>`), with the role the operation needs.
      operationId: issue_key_v1_sources__source_id__keys_post
      parameters:
        - in: path
          name: source_id
          required: true
          schema:
            format: uuid
            title: Source Id
            type: string
          example: 0192f0a0-5f60-7172-8d83-9e0f1a2b3c45
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/KeyCreate'
            example:
              scopes:
                - context
                - search
                - track
                - act
        required: true
      responses:
        '201':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/IssuedKeyOut'
              example:
                key:
                  key_id: k7Q2mX9a
                  source_id: 0192f0a0-5f60-7172-8d83-9e0f1a2b3c45
                  scopes:
                    - context
                    - search
                    - track
                    - act
                  status: active
                  created_at: '2026-09-22T12:00:00Z'
                  expires_at: null
                  revoked_at: null
                secret: >-
                  nia_sk_live_us-east-1_acme-prod_k7Q2mX9a_Vh3pL9sQ2rT8wZ4yB6nD1fG5
          description: The key and its secret, shown this once.
        '422':
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
          description: The request does not match the contract.
      security:
        - personToken: []
components:
  schemas:
    KeyCreate:
      additionalProperties: false
      properties:
        scopes:
          anyOf:
            - items:
                $ref: '#/components/schemas/Scope'
              type: array
            - type: 'null'
          description: Defaults follow the source's audience.
          title: Scopes
      title: KeyCreate
      type: object
    IssuedKeyOut:
      additionalProperties: false
      properties:
        key:
          $ref: '#/components/schemas/KeyOut'
        secret:
          description: The full key. Shown once; Niadra keeps only two hashes of it.
          title: Secret
          type: string
      required:
        - key
        - secret
      title: IssuedKeyOut
      type: object
    Problem:
      additionalProperties: false
      description: RFC 9457 problem details; `code` comes from the versioned error catalog.
      properties:
        code:
          title: Code
          type: string
        detail:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Detail
        request_id:
          anyOf:
            - type: string
            - type: 'null'
          default: null
          title: Request Id
        status:
          title: Status
          type: integer
        title:
          title: Title
          type: string
        type:
          default: about:blank
          title: Type
          type: string
      required:
        - title
        - status
        - code
      title: Problem
      type: object
    Scope:
      enum:
        - track
        - act
        - context
        - search
        - identify
        - admin
        - analytics
      title: Scope
      type: string
    KeyOut:
      additionalProperties: false
      properties:
        created_at:
          format: date-time
          title: Created At
          type: string
        expires_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Expires At
        key_id:
          title: Key Id
          type: string
        revoked_at:
          anyOf:
            - format: date-time
              type: string
            - type: 'null'
          title: Revoked At
        scopes:
          items:
            $ref: '#/components/schemas/Scope'
          title: Scopes
          type: array
        source_id:
          format: uuid
          title: Source Id
          type: string
        status:
          $ref: '#/components/schemas/KeyStatus'
      required:
        - key_id
        - source_id
        - scopes
        - status
        - created_at
        - expires_at
        - revoked_at
      title: KeyOut
      type: object
    KeyStatus:
      enum:
        - active
        - revoked
      title: KeyStatus
      type: string
  securitySchemes:
    personToken:
      type: http
      scheme: bearer
      bearerFormat: JWT

````