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

# Generate a random secret key



## OpenAPI

````yaml /api/machines/openapi.json post /v1/apps/{app_name}/secretkeys/{secret_name}/generate
openapi: 3.1.0
info:
  title: Machines API
  description: >-
    This site hosts documentation generated from the Fly.io Machines API OpenAPI
    specification. Visit our complete [Machines API
    docs](https://fly.io/docs/machines/api/) for how to get started, more
    information about each endpoint, parameter descriptions, and examples.
  contact: {}
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  version: '1.0'
servers:
  - url: https://api.machines.dev
security:
  - FlyBearerAuth: []
tags:
  - name: Apps
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/apps-resource/) for details about
      using the Apps resource.
  - name: Machines
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/machines-resource/) for details
      about using the Machines resource.
  - name: TLS Certificates
    description: >
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/certificates-resource/) for details
      about using the TLS Certificates resource.
  - name: Volumes
    description: >-
      This site hosts documentation generated from the Fly.io Machines API
      OpenAPI specification. Visit our complete [Machines API
      docs](https://fly.io/docs/machines/api/volumes-resource/) for details
      about using the Volumes resource.
  - name: Postgres Clusters
    description: >-
      Create and manage Postgres clusters, including databases, users,
      extensions, backups, and app attachments.
externalDocs:
  url: https://fly.io/docs/machines/working-with-machines/
paths:
  /v1/apps/{app_name}/secretkeys/{secret_name}/generate:
    post:
      tags:
        - Secrets
      summary: Generate a random secret key
      operationId: Secretkey_generate
      parameters:
        - name: app_name
          in: path
          description: Fly App Name
          required: true
          schema:
            type: string
        - name: secret_name
          in: path
          description: Secret key name
          required: true
          schema:
            type: string
      requestBody:
        description: generate secret key request
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SetSecretkeyRequest'
        required: true
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SetSecretkeyResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
components:
  schemas:
    SetSecretkeyRequest:
      type: object
      properties:
        type:
          type: string
          description: >-
            Type of the key: `hs256`, `hs384`, `hs512`, `xaes256gcm`,
            `nacl_auth`, `nacl_box`, `nacl_secretbox`, `nacl_sign`, or `es256`.
            Required.
        value:
          pattern: ^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$
          type: string
          description: Key material, base64-encoded. Ignored when generating a key.
          format: byte
    SetSecretkeyResponse:
      type: object
      properties:
        Version:
          type: integer
          description: |-
            Same value as `version`.

            Deprecated: use `version`.
        created_at:
          type: string
          description: When the key was first set.
        name:
          type: string
          description: Name of the secret key.
        public_key:
          pattern: ^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$
          type: string
          description: >-
            Public key of asymmetric keys (`nacl_box`, `nacl_sign`, `es256`),
            base64-encoded.
          format: byte
        type:
          type: string
          description: >-
            Type of the key: `hs256`, `hs384`, `hs512`, `xaes256gcm`,
            `nacl_auth`, `nacl_box`, `nacl_secretbox`, `nacl_sign`, or `es256`.
        updated_at:
          type: string
          description: When the key last changed.
        version:
          type: integer
          description: >-
            The app's secrets version after this change. Pass it as
            `min_version` to read the change

            back.
    ErrorResponse:
      type: object
      properties:
        details:
          type: object
          description: 'Deprecated: details about some errors. Do not rely on its contents.'
        error:
          type: string
          description: >-
            Human-readable description of the error. Its wording may change; use
            `status` to tell

            errors apart.
        status:
          type: object
          description: >-
            Machine-readable error code, set for some errors, such as
            `insufficient_capacity`,

            `volume_placement_capacity`, `name_taken`, `exec_request_too_large`,
            or

            `exec_output_too_large`.
          allOf:
            - $ref: '#/components/schemas/main.statusCode'
    main.statusCode:
      type: string
      enum:
        - unknown
        - insufficient_capacity
        - volume_placement_capacity
        - exec_request_too_large
        - exec_output_too_large
        - name_taken
      x-enum-varnames:
        - unknown
        - capacityErr
        - volumePlacementCapacityErr
        - execRequestTooLargeErr
        - execOutputTooLargeErr
        - nameTakenErr
  securitySchemes:
    FlyBearerAuth:
      type: http
      scheme: bearer
      description: >-
        A Fly API token with access to the requested organization or resource.
        Send it as `Authorization: Bearer <Fly API token>`.

````