openapi: 3.0.0
info:
  title: Create SSH Key API
  description: 'Create a new SSH key and associate it with your account.

    The key will be added to all your current instances automatically.

    '
  version: 1.0.0
servers:
- url: https://console.vast.ai
  description: Production server
paths:
  /api/v0/ssh/:
    post:
      summary: create ssh-key
      description: |
        Creates a new SSH key and associates it with your account.
        The key will be automatically added to all your current instances.

        CLI Usage: `vastai create ssh-key <ssh_key>`
      security:
      - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
              - ssh_key
              properties:
                ssh_key:
                  type: string
                  description: The public SSH key to add (from .pub file)
                  example: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC...
      responses:
        '200':
          description: SSH key created successfully
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: true
                  key:
                    type: object
                    properties:
                      id:
                        type: integer
                        description: The ID of the created SSH key
                        example: 123
                      user_id:
                        type: integer
                        description: The user ID who owns the key
                        example: 456
                      public_key:
                        type: string
                        description: The public SSH key content
                        example: ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC...
                      created_at:
                        type: string
                        format: date-time
                        example: '2023-01-01T12:00:00Z'
                      deleted_at:
                        type: string
                        format: date-time
                        nullable: true
                        example: null
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                    example: false
                  error:
                    type: string
                    enum:
                    - no_ssh_key
                  msg:
                    type: string
                    example: No ssh key provided
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '429':
          description: Too Many Requests
          content:
            application/json:
              schema:
                type: object
                properties:
                  detail:
                    type: string
                    example: API requests too frequent endpoint threshold=1.0
      tags:
      - Accounts
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      description: API key must be provided in the Authorization header
  schemas:
    Error:
      type: object
      properties:
        success:
          type: boolean
          example: false
        error:
          type: string
        msg:
          type: string
x-rate-limit:
  threshold: 1.0
  per: request
  description: Maximum request frequency per IP address for this endpoint
x-input-validation:
  ssh_key:
    required: true
    sanitization: NUL characters removed
    description: Must be a valid SSH public key
x-cli-commands:
- name: create ssh-key
  description: Create a new ssh-key and add it to your account
  endpoint: /api/v0/ssh/
  method: POST
  example: vast create ssh-key "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC..."
