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

# Add SSH key to instance

> Append an SSH public key to an existing instance's `authorized_keys`.

Behavior:
- If `public_key` is provided, that raw key material is appended to `authorized_keys`. If the same public key is already attached, the request is a no-op (no error).
- If `public_key` is omitted, Thunder generates a new key pair, appends the public half to `authorized_keys`, and returns the private key in the response. The private key is only returned once — store it immediately.

Note: SSH keys saved in your account (Authentication section of the console) are a separate store and are NOT automatically attached to instances. To use one of those keys, copy its public key material into the `public_key` field on this request.



## OpenAPI

````yaml https://api.thundercompute.com:8443/openapi.json post /instances/{id}/add_key
openapi: 3.1.0
info:
  contact:
    email: support@thundercompute.com
    name: Thunder Compute API Support
    url: https://thundercompute.com/support
  description: >-
    This is the Thunder Compute API server for managing compute resources and
    GPU workloads.
  license:
    name: Apache 2.0
    url: http://www.apache.org/licenses/LICENSE-2.0.html
  termsOfService: http://swagger.io/terms/
  title: Thunder Compute API
  version: '1.0'
servers:
  - description: Production server
    url: https://api.thundercompute.com:8443/v1
security: []
externalDocs:
  description: ''
  url: ''
paths:
  /instances/{id}/add_key:
    post:
      tags:
        - Instances
      summary: Add SSH key to instance
      description: >-
        Append an SSH public key to an existing instance's `authorized_keys`.


        Behavior:

        - If `public_key` is provided, that raw key material is appended to
        `authorized_keys`. If the same public key is already attached, the
        request is a no-op (no error).

        - If `public_key` is omitted, Thunder generates a new key pair, appends
        the public half to `authorized_keys`, and returns the private key in the
        response. The private key is only returned once — store it immediately.


        Note: SSH keys saved in your account (Authentication section of the
        console) are a separate store and are NOT automatically attached to
        instances. To use one of those keys, copy its public key material into
        the `public_key` field on this request.
      parameters:
        - description: Instance ID
          in: path
          name: id
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - type: object
                - $ref: '#/components/schemas/thundertypes.InstanceAddKeyRequest'
                  summary: request
                  description: 'Optional: provide an existing public key to add'
        description: 'Optional: provide an existing public key to add'
      responses:
        '200':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/thundertypes.InstanceAddKeyResponse'
          description: OK
        '400':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/thundertypes.ErrorResponse'
          description: Bad Request
        '401':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/thundertypes.ErrorResponse'
          description: Unauthorized
        '404':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/thundertypes.ErrorResponse'
          description: Not Found
        '500':
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/thundertypes.ErrorResponse'
          description: Internal Server Error
      security:
        - ApiKeyAuth: []
components:
  schemas:
    thundertypes.InstanceAddKeyRequest:
      properties:
        public_key:
          description: >-
            Optional SSH public key material. Omit to have a key pair generated
            and the private key returned.
          type: string
      type: object
    thundertypes.InstanceAddKeyResponse:
      properties:
        key:
          description: Private key (only when generated)
          type: string
        message:
          description: Status message
          type: string
        success:
          description: Whether the key was successfully added
          type: boolean
        uuid:
          type: string
      required:
        - success
        - uuid
      type: object
    thundertypes.ErrorResponse:
      properties:
        code:
          example: 400
          type: integer
        error:
          example: invalid_request
          type: string
        message:
          example: The request is malformed
          type: string
      type: object
  securitySchemes:
    ApiKeyAuth:
      description: >-
        Bearer token authentication. Provide your API token prefixed with
        "Bearer ", e.g. "Bearer your-api-token".
      in: header
      name: Authorization
      type: apiKey

````