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

# Create Key

> Mint a personal access token and return its plaintext once.

The plaintext is not stored, so this response is the only opportunity to
capture it. A caller who loses it must revoke the key and mint another.

Raises:
    HTTPException 400: If the requested scopes are not recognised.
    HTTPException 409: If the caller already holds the maximum active keys.



## OpenAPI

````yaml /openapi.json post /api/keys
openapi: 3.1.0
info:
  title: HAI-Co² API
  description: Human-AI Co-Construction reference implementation.
  version: 0.1.0
servers:
  - url: https://haico.gr
    description: Production
  - url: https://dev.haico.gr
    description: Development
  - url: http://localhost:8000
    description: Local development
security: []
paths:
  /api/keys:
    post:
      tags:
        - API Keys
      summary: Create Key
      description: |-
        Mint a personal access token and return its plaintext once.

        The plaintext is not stored, so this response is the only opportunity to
        capture it. A caller who loses it must revoke the key and mint another.

        Raises:
            HTTPException 400: If the requested scopes are not recognised.
            HTTPException 409: If the caller already holds the maximum active keys.
      operationId: create_key_api_keys_post
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ApiKeyCreateRequest'
        required: true
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ApiKeyCreateResponse'
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    ApiKeyCreateRequest:
      properties:
        name:
          type: string
          maxLength: 100
          minLength: 1
          title: Name
          description: Label to recognise this key by, e.g. 'analysis laptop'
        scopes:
          type: string
          enum:
            - read
            - read,write
          title: Scopes
          description: '''read'' for safe methods only, ''read,write'' for full access'
          default: read,write
        expires_in_days:
          anyOf:
            - type: integer
              maximum: 3650
              minimum: 0
            - type: 'null'
          title: Expires In Days
          description: Lifetime in days. Omit for the default (90); 0 never expires.
      type: object
      required:
        - name
      title: ApiKeyCreateRequest
      description: Request to mint a new personal access token.
    ApiKeyCreateResponse:
      properties:
        key:
          $ref: '#/components/schemas/ApiKeySchema'
        plaintext:
          type: string
          title: Plaintext
          description: The full key. Shown once and never retrievable again.
      type: object
      required:
        - key
        - plaintext
      title: ApiKeyCreateResponse
      description: >-
        Response to key creation: the only time the plaintext is ever returned.


        It is not stored anywhere, so a caller who loses it must revoke the key
        and

        mint another.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ApiKeySchema:
      properties:
        id:
          type: integer
          title: Id
        name:
          type: string
          title: Name
        key_prefix:
          type: string
          title: Key Prefix
        last_four:
          type: string
          title: Last Four
        scopes:
          type: string
          title: Scopes
        created_at:
          type: string
          format: date-time
          title: Created At
        last_used_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Last Used At
        expires_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Expires At
        revoked_at:
          anyOf:
            - type: string
              format: date-time
            - type: 'null'
          title: Revoked At
        active:
          type: boolean
          title: Active
      type: object
      required:
        - id
        - name
        - key_prefix
        - last_four
        - scopes
        - created_at
        - active
      title: ApiKeySchema
      description: A key's non-secret metadata. The plaintext is never included here.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
        input:
          title: Input
        ctx:
          type: object
          title: Context
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      description: >-
        A personal access token (`haico_pat_...`), created under Profile → API
        keys. Send it as `Authorization: Bearer <key>`. The browser session JWT
        is also accepted but is an internal mechanism and is not part of the
        public contract.
      scheme: bearer

````