openapi: 3.0.0
info:
  title: ClipCloud API
  version: "1.0.0"
  description: |
    REST API for generating images with ClipCloud and managing account data.
    
    **Authentication**  
    Send header `Authorization: Bearer <API_KEY>` where `<API_KEY>` is the key you received from @clipcloudbot Telegram bot.

servers:
  - url: https://clipcloud.clipai.pro
    description: Production
  - url: https://clipcloud-rumirror.clipai.pro
    description: Production (RU mirror)

tags:
  - name: ImageGeneration
    description: Operations related to image generation
  - name: Account
    description: Account utilities

security:
  - BearerAuth: []

components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: API-Key
      description: "API key via `Authorization: Bearer <API_KEY>`."

  schemas:
    StyleName:
      type: string
      description: Image style preset (standard generation).
      enum:
        - standard
        - smallHQ
        - HD-HQ
        - FullHD-HQ-h
        - FullHD-HQ-v
        - standard-2
        - standard-2-FullHD
        - photorealistic-1
        - photo-horizontal
        - graffiti
        - illustration
        - oldphoto
        - aquarelle
        - pixel-art
        - pop-art
        - neon-lines
        - neon-noir
        - photo-portrait
        - tilt-shift
        - anime
        - lowquality
        - HQ-4K-h
        - HQ-768-512-h
        - HQ-832-448-h
        - HQ-832-640-h
        - HQ-1024-640-h
        - HQ-1200-640-h
        - HQ-1280-720-h
        - HQ-1920-1024-h
        - HQ-512-768-v
        - HQ-640-1024-v
        - standard-512
        - pop-art-512
    Quality:
      type: string
      enum: [ultra-low, low, medium, high, ultra]
    Model:
      type: string
      enum: [Low, Medium, High, Ultra-High, Anime, Low-Realism, Medium-Realism]

    # --- Request payloads ---
    CreationRequestStandard:
      type: object
      additionalProperties: false
      required: [prompt, styleName]
      properties:
        prompt:
          type: string
          description: Text prompt (recommended English).
        negative_prompt:
          type: string
          description: Things to avoid in the generated image.
        styleName:
          $ref: '#/components/schemas/StyleName'
        count:
          type: integer
          minimum: 1
          maximum: 10
          default: 1
          description: Number of images to generate.
        soft_id:
          type: integer
          description: Software ID for referral payouts.
        check_cost:
          type: boolean
          default: false
          description: If `true`, only check generation cost without actually starting it.

    CreationRequestAdvanced:
      type: object
      additionalProperties: false
      required: [prompt, model, width, height, quality]
      properties:
        prompt:
          type: string
        negative_prompt:
          type: string
        temperature:
          type: number
          minimum: 1
          maximum: 15
          default: 7
        width:
          type: integer
          minimum: 512
          maximum: 4096
        height:
          type: integer
          minimum: 512
          maximum: 4096
        quality:
          $ref: '#/components/schemas/Quality'
        model:
          $ref: '#/components/schemas/Model'
        count:
          type: integer
          minimum: 1
          maximum: 10
          default: 1
        soft_id:
          type: integer
        check_cost:
          type: boolean
          default: false

    # Unified request payload (flattened for tool compatibility)
    CreationRequest:
      type: object
      description: | 
        Parameters for image generation.  
        **Required:**
        * `prompt` – text description of what to generate  
        * `styleName` – Style preset. **In most of these cases you need to pass ONLY this two required parameters!** More details: https://app.theneo.io/1503fe86-2db1-43ac-880a-cbf661919292/clipcloud-clone/image-generation
      additionalProperties: false
      required: [prompt, styleName]
      properties:
        prompt:
          type: string
          description: Text prompt (recommended English).
        styleName:
          $ref: '#/components/schemas/StyleName'
        negative_prompt:
          type: string
          description: Things to avoid in the generated image.
        # standard‑only options
        count:
          type: integer
          minimum: 1
          maximum: 10
          default: 1
        soft_id:
          type: integer
          description: Software ID for referral payouts.
        check_cost:
          type: boolean
          default: false
          description: If `true`, only check generation cost without actually starting it.
        # advanced‑mode extra options (ignored by standard styles)
        temperature:
          type: number
          minimum: 1
          maximum: 15
          default: 7
        width:
          type: integer
          minimum: 512
          maximum: 4096
        height:
          type: integer
          minimum: 512
          maximum: 4096
        quality:
          $ref: '#/components/schemas/Quality'
        model:
          $ref: '#/components/schemas/Model'

    # --- Common responses ---
    CreationAccepted:
      type: object
      additionalProperties: false
      required: [creation_id]
      properties:
        success:
          type: boolean
          example: true
        creation_id:
          type: string
          format: uuid
    CreationStatus:
      type: object
      additionalProperties: false
      required: [creation_id]
      description: Response while generation is still in progress.
      properties:
        success:
          type: boolean
          example: true
        message:
          type: string
          example: In progress
        creation_id:
          type: string
          format: uuid
    CreationResult:
      type: object
      additionalProperties: false
      required: [creation_id]
      description: Response with finished images.
      properties:
        success:
          type: boolean
          example: true
        message:
          type: string
          example: Images processed successfully
        creation_id:
          type: string
          format: uuid
        cost:
          type: number
        censored:
          type: integer
        results:
          type: array
          items:
            type: string
            format: uri
    BalanceResponse:
      type: object
      additionalProperties: false
      properties:
        success:
          type: boolean
        balance:
          type: number
        free_balance:
          type: number
    Style:
      type: object
      additionalProperties: false
      properties:
        isFree:
          type: boolean
        name:
          type: string
        width:
          type: integer
        height:
          type: integer
    StylesResponse:
      type: object
      additionalProperties: false
      properties:
        success:
          type: boolean
        styles:
          type: array
          items:
            $ref: '#/components/schemas/Style'

paths:
  /api/creation:
    post:
      tags: [ImageGeneration]
      summary: Start image generation
      operationId: startCreation
      security:
        - BearerAuth: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreationRequest'
      responses:
        '200':
          description: Generation request accepted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreationAccepted'
        '400':
          description: Invalid parameters
        '401':
          description: Unauthorized – missing or invalid API key
        '415':
          description: Unsupported Media Type – `Content-Type` must be `application/json`
  /api/creation/{creation_id}:
    get:
      tags: [ImageGeneration]
      summary: Retrieve generation status or results
      operationId: getCreation
      security:
        - BearerAuth: []
      parameters:
        - name: creation_id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: Current status or final results
          content:
            application/json:
              schema:
                oneOf:
                  - $ref: '#/components/schemas/CreationStatus'
                  - $ref: '#/components/schemas/CreationResult'
        '400':
          description: Invalid parameters
        '401':
          description: Unauthorized – invalid API key
        '404':
          description: Generation not found
  /api/users/mybalance:
    get:
      tags: [Account]
      summary: Check API key balance
      operationId: getBalance
      security:
        - BearerAuth: []
      responses:
        '200':
          description: Balance information
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BalanceResponse'
        '401':
          description: Unauthorized – invalid API key
  /api/styles:
    get:
      tags: [ImageGeneration]
      summary: Retrieve available styles
      operationId: getStyles
      security:
        - BearerAuth: []
      responses:
        '200':
          description: List of styles
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StylesResponse'
