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

# Create an API key

> The `secret` in the response is the ONLY time the raw key exists outside the caller's hands. Only its SHA-256 fingerprint is stored, so it cannot be shown again or recovered.



## OpenAPI

````yaml /api-reference/auth.json post /api/auth/keys
openapi: 3.1.0
info:
  title: truscan auth
  version: 1.0.0
  description: >-
    Identity: accounts, sessions, password resets and API keys.


    This is the only service that verifies a credential, because it is the
    service that issues them. Every other service decodes the identity the edge
    already verified.


    Protected routes accept either credential, a dashboard session JWT or an
    `tru_` API key, on the same path. There is no key-only variant of any route.
servers:
  - url: https://api.truscan.co
    description: Production
security: []
tags:
  - name: session
    description: Sign up, sign in, password reset
  - name: keys
    description: API key management
paths:
  /api/auth/keys:
    post:
      tags:
        - keys
      summary: Create an API key
      description: >-
        The `secret` in the response is the ONLY time the raw key exists outside
        the caller's hands. Only its SHA-256 fingerprint is stored, so it cannot
        be shown again or recovered.
      requestBody:
        required: false
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  maxLength: 60
                  description: A label. Defaults to "Untitled key".
      responses:
        '201':
          description: The key, including its secret.
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/Envelope'
                properties:
                  result:
                    $ref: '#/components/schemas/CreatedAPIKey'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '409':
          description: The per-account key limit was reached.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Failure'
        '422':
          $ref: '#/components/responses/Invalid'
      security:
        - session: []
        - apiKey: []
components:
  schemas:
    Envelope:
      type: object
      required:
        - success
        - result
        - message
      properties:
        success:
          type: boolean
        result: {}
        message:
          type: string
    CreatedAPIKey:
      allOf:
        - $ref: '#/components/schemas/APIKey'
        - type: object
          properties:
            secret:
              type: string
              examples:
                - tru_yR2xQ7bT...
              description: Shown exactly once. Not recoverable.
    Failure:
      type: object
      required:
        - success
        - result
        - message
      properties:
        success:
          type: boolean
          const: false
        result:
          type: object
          properties:
            code:
              type: string
        message:
          type: string
          description: Written for a person. Safe to show as-is.
    APIKey:
      type: object
      properties:
        id:
          type: string
          examples:
            - key_1b2c3d4e5f6a7b8c9d0e1f2a
        name:
          type: string
        last_four:
          type: string
          maxLength: 4
        created_at:
          type: string
          format: date-time
        last_used_at:
          type: string
          format: date-time
  responses:
    Unauthorized:
      description: No valid credential was presented.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Failure'
    Invalid:
      description: The request was well-formed but a value was not acceptable.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Failure'
  securitySchemes:
    session:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: A dashboard session, verified at the edge.
    apiKey:
      type: http
      scheme: bearer
      description: >-
        An `tru_` API key, resolved at the edge. Accepted on every route a
        session is.

````