openapi: 3.0.3
info:
  title: PixelGenie Public API
  version: 1.0.0
  description: Create images, videos, and complete AI video series.
  license:
    name: Proprietary
    url: https://pixelgenieai.com/legal
externalDocs:
  description: PixelGenie API and MCP setup guide
  url: https://pixelgenieai.com/docs
servers:
  - url: https://api.pixelgenieai.com/api/v1
security:
  - bearerAuth: []
tags:
  - name: Images
    description: Create and list account images.
  - name: Series
    description: Plan and manage complete video series.
  - name: Video
    description: Generate episodes and individual scenes.
  - name: Delivery
    description: Share and download completed videos.
  - name: Webhooks
    description: Receive signed generation status events.
  - name: MCP
    description: Use PixelGenie through Model Context Protocol tools.
paths:
  /images:
    get:
      tags: [Images]
      summary: List images
      operationId: listImages
      x-required-scope: images:read
      parameters:
        - name: page
          in: query
          schema:
            type: integer
            minimum: 1
            default: 1
        - name: pageSize
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 50
            default: 20
        - name: albumId
          in: query
          schema:
            type: integer
            minimum: 1
      responses:
        '200':
          description: Paginated images owned by the authenticated account
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PaginatedImages'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /images/create:
    post:
      tags: [Images]
      summary: Create images
      description: PixelGenie selects the generation provider. Reference images are optional.
      operationId: createImages
      x-required-scope: images:write
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateImageRequest'
      responses:
        '200':
          description: Created images
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Image'
        '400':
          $ref: '#/components/responses/BadRequest'
        '403':
          $ref: '#/components/responses/Forbidden'
        '401':
          $ref: '#/components/responses/Unauthorized'
  /ugc/series/plan:
    post:
      tags: [Series]
      summary: Plan a series with AI
      operationId: planSeries
      x-required-scope: series:write
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PlanSeriesRequest'
      responses:
        '200':
          description: Editable series plan
          content:
            application/json:
              schema:
                type: object
                required: [plan]
                properties:
                  plan:
                    $ref: '#/components/schemas/CreateSeriesRequest'
                  runtime_version:
                    type: integer
                  input_tokens:
                    type: integer
                  output_tokens:
                    type: integer
        '400':
          $ref: '#/components/responses/BadRequest'
  /ugc/series:
    post:
      tags: [Series]
      summary: Create a series from an approved plan
      operationId: createSeries
      x-required-scope: series:write
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateSeriesRequest'
      responses:
        '201':
          description: Created series
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Series'
        '400':
          $ref: '#/components/responses/BadRequest'
    get:
      tags: [Series]
      summary: List series
      operationId: listSeries
      x-required-scope: series:read
      parameters:
        - name: limit
          in: query
          schema:
            type: integer
            minimum: 1
            maximum: 100
            default: 20
        - name: offset
          in: query
          schema:
            type: integer
            minimum: 0
            default: 0
      responses:
        '200':
          description: Series list
          content:
            application/json:
              schema:
                type: object
                properties:
                  series:
                    type: array
                    items:
                      $ref: '#/components/schemas/Series'
                  total:
                    type: integer
                  limit:
                    type: integer
                  offset:
                    type: integer
        '401':
          $ref: '#/components/responses/Unauthorized'
  /ugc/series/{seriesId}:
    get:
      tags: [Series]
      summary: Get a series
      operationId: getSeries
      x-required-scope: series:read
      parameters:
        - $ref: '#/components/parameters/SeriesId'
      responses:
        '200':
          description: Series with episodes and projects
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Series'
        '404':
          $ref: '#/components/responses/NotFound'
    delete:
      tags: [Series]
      summary: Delete a series
      operationId: deleteSeries
      x-required-scope: series:write
      parameters:
        - $ref: '#/components/parameters/SeriesId'
      responses:
        '204':
          description: Series deleted
        '404':
          $ref: '#/components/responses/NotFound'
  /ugc/series/{seriesId}/workspace:
    put:
      tags: [Series]
      summary: Save series, episode, character, and scene changes
      operationId: updateSeriesWorkspace
      x-required-scope: series:write
      parameters:
        - $ref: '#/components/parameters/SeriesId'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [episode_id]
              properties:
                episode_id:
                  type: integer
                title:
                  type: string
                characters:
                  type: array
                  items:
                    $ref: '#/components/schemas/Character'
                scenes:
                  type: array
                  items:
                    $ref: '#/components/schemas/SceneInput'
      responses:
        '200':
          description: Updated series
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Series'
        '400':
          $ref: '#/components/responses/BadRequest'
  /ugc/series/{seriesId}/revise:
    post:
      tags: [Series]
      summary: Create an AI revision proposal
      operationId: reviseSeries
      x-required-scope: series:write
      parameters:
        - $ref: '#/components/parameters/SeriesId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [instruction, scope, current]
              properties:
                instruction:
                  type: string
                scope:
                  type: string
                  enum: [scene, episode, series]
                episode_number:
                  type: integer
                scene_order:
                  type: integer
                current:
                  $ref: '#/components/schemas/CreateSeriesRequest'
                model_class:
                  type: string
                  enum: [primary, fast]
      responses:
        '200':
          description: Reviewable revision proposal
          content:
            application/json:
              schema:
                type: object
        '400':
          $ref: '#/components/responses/BadRequest'
  /ugc/reference-images:
    post:
      tags: [Series]
      summary: Upload a reference image
      operationId: uploadReferenceImage
      x-required-scope: series:write
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              required: [image]
              properties:
                image:
                  type: string
                  format: binary
      responses:
        '201':
          description: Stored reference image
          content:
            application/json:
              schema:
                type: object
                properties:
                  url:
                    type: string
                    format: uri
                  s3_key:
                    type: string
        '400':
          $ref: '#/components/responses/BadRequest'
  /ugc/projects/{projectId}:
    get:
      tags: [Video]
      summary: Get episode generation status
      operationId: getProject
      x-required-scope: video:read
      parameters:
        - $ref: '#/components/parameters/ProjectId'
      responses:
        '200':
          description: Project with scene and media status
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Project'
        '404':
          $ref: '#/components/responses/NotFound'
  /ugc/projects/{projectId}/generate:
    post:
      tags: [Video]
      summary: Generate and assemble an episode
      operationId: generateEpisode
      x-required-scope: video:write
      parameters:
        - $ref: '#/components/parameters/ProjectId'
        - $ref: '#/components/parameters/IdempotencyKey'
      responses:
        '202':
          description: Generation started
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
                  project_id:
                    type: integer
                  status:
                    type: string
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '409':
          description: Generation already started or completed
  /ugc/projects/{projectId}/scenes/{sceneId}/generate:
    post:
      tags: [Video]
      summary: Regenerate one scene
      operationId: regenerateScene
      x-required-scope: video:write
      parameters:
        - $ref: '#/components/parameters/ProjectId'
        - $ref: '#/components/parameters/SceneId'
        - $ref: '#/components/parameters/IdempotencyKey'
      responses:
        '202':
          description: Scene regeneration started
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '409':
          description: Episode generation is already active
  /ugc/series/{seriesId}/shares:
    post:
      tags: [Delivery]
      summary: Create a public share
      operationId: createSeriesShare
      x-required-scope: series:write
      parameters:
        - $ref: '#/components/parameters/SeriesId'
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required: [scope]
              properties:
                scope:
                  type: string
                  enum: [series, episode]
                episode_id:
                  type: integer
      responses:
        '201':
          description: Public share
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Share'
        '400':
          $ref: '#/components/responses/BadRequest'
    get:
      tags: [Delivery]
      summary: List active shares
      operationId: listSeriesShares
      x-required-scope: series:read
      parameters:
        - $ref: '#/components/parameters/SeriesId'
      responses:
        '200':
          description: Active share links
          content:
            application/json:
              schema:
                type: object
                properties:
                  shares:
                    type: array
                    items:
                      $ref: '#/components/schemas/Share'
        '404':
          $ref: '#/components/responses/NotFound'
  /ugc/series/{seriesId}/shares/{shareId}:
    delete:
      tags: [Delivery]
      summary: Revoke a share
      operationId: revokeSeriesShare
      x-required-scope: series:write
      parameters:
        - $ref: '#/components/parameters/SeriesId'
        - $ref: '#/components/parameters/ShareId'
      responses:
        '204':
          description: Share revoked
        '404':
          $ref: '#/components/responses/NotFound'
  /ugc/shared/{token}:
    get:
      security: []
      tags: [Delivery]
      summary: Read a public share
      operationId: getPublicShare
      parameters:
        - name: token
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Public playback data
          content:
            application/json:
              schema:
                type: object
        '404':
          $ref: '#/components/responses/NotFound'
  /ugc/series/{seriesId}/download:
    get:
      tags: [Delivery]
      summary: Download completed episodes
      operationId: downloadSeries
      x-required-scope: series:read
      parameters:
        - $ref: '#/components/parameters/SeriesId'
      responses:
        '200':
          description: ZIP containing episode MP4 files
          content:
            application/zip:
              schema:
                type: string
                format: binary
        '404':
          $ref: '#/components/responses/NotFound'
  /ugc/webhooks:
    post:
      tags: [Webhooks]
      summary: Register a generation webhook
      operationId: createWebhook
      x-required-scope: video:write
      parameters:
        - $ref: '#/components/parameters/IdempotencyKey'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateWebhookRequest'
      responses:
        '201':
          description: Webhook with one-time signing secret
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Webhook'
        '400':
          $ref: '#/components/responses/BadRequest'
    get:
      tags: [Webhooks]
      summary: List generation webhooks
      operationId: listWebhooks
      x-required-scope: video:read
      responses:
        '200':
          description: Registered webhooks
        '401':
          $ref: '#/components/responses/Unauthorized'
  /ugc/webhooks/{webhookId}:
    delete:
      tags: [Webhooks]
      summary: Disable a webhook
      operationId: deleteWebhook
      x-required-scope: video:write
      parameters:
        - $ref: '#/components/parameters/WebhookId'
      responses:
        '204':
          description: Webhook disabled
        '404':
          $ref: '#/components/responses/NotFound'
  /ugc/webhooks/{webhookId}/deliveries:
    get:
      tags: [Webhooks]
      summary: List webhook delivery attempts
      operationId: listWebhookDeliveries
      x-required-scope: video:read
      parameters:
        - $ref: '#/components/parameters/WebhookId'
      responses:
        '200':
          description: Delivery history
        '404':
          $ref: '#/components/responses/NotFound'
  /mcp:
    post:
      tags: [MCP]
      summary: Use PixelGenie MCP tools
      operationId: callMCP
      x-required-scope: mcp:use
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
      responses:
        '200':
          description: MCP JSON-RPC response
          content:
            application/json:
              schema:
                type: object
        '400':
          $ref: '#/components/responses/BadRequest'
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: PixelGenie API key or user JWT.
  parameters:
    IdempotencyKey:
      name: Idempotency-Key
      in: header
      required: true
      description: Retry-safe key stored for 24 hours. API key requests require this header.
      schema:
        type: string
        minLength: 8
        maxLength: 255
        pattern: '^[A-Za-z0-9][A-Za-z0-9._:-]{7,254}$'
    SeriesId:
      name: seriesId
      in: path
      required: true
      schema:
        type: integer
        minimum: 1
    ProjectId:
      name: projectId
      in: path
      required: true
      schema:
        type: integer
        minimum: 1
    SceneId:
      name: sceneId
      in: path
      required: true
      schema:
        type: integer
        minimum: 1
    WebhookId:
      name: webhookId
      in: path
      required: true
      schema:
        type: integer
        minimum: 1
    ShareId:
      name: shareId
      in: path
      required: true
      schema:
        type: integer
        minimum: 1
  responses:
    BadRequest:
      description: Invalid request
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    NotFound:
      description: Resource not found
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Unauthorized:
      description: Authentication failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    Forbidden:
      description: The key lacks access, or the account lacks required credits or entitlement
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
    PaymentRequired:
      description: The account needs more credits
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/Error'
  schemas:
    Error:
      type: object
      properties:
        error:
          type: string
        message:
          type: string
    CreateImageRequest:
      type: object
      additionalProperties: false
      required: [prompt]
      properties:
        prompt:
          type: string
          minLength: 1
        reference_images:
          type: array
          maxItems: 20
          description: HTTPS URLs or base64-encoded images.
          items:
            type: string
        num_outputs:
          type: integer
          minimum: 1
          maximum: 4
          default: 1
        aspect_ratio:
          type: string
          enum: ['1:1', '3:4', '9:16', '9:21', '4:3', '16:9', '21:9']
        seed:
          type: integer
        output_format:
          type: string
          enum: [jpeg, png, webp]
    Image:
      type: object
      properties:
        id:
          type: integer
        url:
          type: string
          format: uri
        prompt:
          type: string
        width:
          type: integer
        height:
          type: integer
        aspect_ratio:
          type: string
        output_format:
          type: string
        album_id:
          type: integer
        created_at:
          type: string
          format: date-time
    PaginatedImages:
      type: object
      required: [images, total, page, pageSize]
      properties:
        images:
          type: array
          items:
            $ref: '#/components/schemas/Image'
        total:
          type: integer
        page:
          type: integer
        pageSize:
          type: integer
    PlanSeriesRequest:
      type: object
      required: [idea]
      properties:
        idea:
          type: string
        audience:
          type: string
        goal:
          type: string
        episode_count:
          type: integer
          minimum: 1
          maximum: 8
        episode_duration:
          type: integer
          minimum: 15
          maximum: 60
          multipleOf: 5
        scene_pacing:
          type: string
          enum: [auto, short, long]
        aspect_ratio:
          type: string
          enum: ['9:16', '16:9', '1:1']
        tone:
          type: string
        character_name:
          type: string
        character_image_url:
          type: string
          format: uri
        product_name:
          type: string
        product_image_url:
          type: string
          format: uri
    CreateSeriesRequest:
      type: object
      required: [title]
      properties:
        title:
          type: string
        description:
          type: string
        logline:
          type: string
        aspect_ratio:
          type: string
          enum: ['9:16', '16:9', '1:1']
        target_duration:
          type: integer
        tone:
          type: string
        quality:
          type: string
          enum: [Fast, Realistic, Cinema]
        location:
          type: string
        visual_style:
          type: string
        voice:
          type: string
        characters:
          type: array
          items:
            $ref: '#/components/schemas/Character'
        season:
          $ref: '#/components/schemas/SeasonInput'
    SeasonInput:
      type: object
      properties:
        season_number:
          type: integer
        title:
          type: string
        status:
          type: string
        episodes:
          type: array
          items:
            $ref: '#/components/schemas/EpisodeInput'
    EpisodeInput:
      type: object
      properties:
        episode_number:
          type: integer
        title:
          type: string
        story_phase:
          type: string
        story_beat:
          type: string
        creative_brief:
          type: string
        target_duration:
          type: integer
        quality:
          type: string
        scenes:
          type: array
          items:
            $ref: '#/components/schemas/SceneInput'
    SceneInput:
      type: object
      required: [scene_order, duration]
      properties:
        id:
          type: integer
        scene_order:
          type: integer
        title:
          type: string
        dialogue:
          type: string
        dialogue_lines:
          type: array
          items:
            type: object
        audio_direction:
          type: string
        visual_prompt:
          type: string
        camera_movement:
          type: string
        story_beat:
          type: string
        model_choice:
          type: string
          enum: [Fast, Realistic, Cinema]
        duration:
          type: integer
          minimum: 1
          maximum: 30
        image_url:
          type: string
          format: uri
        reference_image_url:
          type: string
          format: uri
        character_keys:
          type: array
          items:
            type: string
    Character:
      type: object
      required: [name]
      properties:
        id:
          type: integer
        key:
          type: string
        name:
          type: string
        description:
          type: string
        voice:
          type: string
        reference_images:
          type: array
          items:
            type: string
            format: uri
    Series:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        description:
          type: string
        logline:
          type: string
        status:
          type: string
        aspect_ratio:
          type: string
        seasons:
          type: array
          items:
            type: object
            properties:
              id:
                type: integer
              episodes:
                type: array
                items:
                  type: object
                  properties:
                    id:
                      type: integer
                    project_id:
                      type: integer
                    project:
                      $ref: '#/components/schemas/Project'
    Project:
      type: object
      properties:
        id:
          type: integer
        title:
          type: string
        status:
          type: string
          enum: [draft, processing, composing, completed, failed]
        final_video_url:
          type: string
          format: uri
        credits_used:
          type: integer
        error_message:
          type: string
        scenes:
          type: array
          items:
            type: object
            properties:
              id:
                type: integer
              status:
                type: string
              video_url:
                type: string
                format: uri
    Share:
      type: object
      properties:
        id:
          type: integer
        scope:
          type: string
        token:
          type: string
        public_path:
          type: string
        ready_episodes:
          type: integer
        total_episodes:
          type: integer
    CreateWebhookRequest:
      type: object
      required: [url, events]
      properties:
        description:
          type: string
        url:
          type: string
          format: uri
        events:
          type: array
          minItems: 1
          items:
            type: string
            enum: [episode.completed, episode.failed, scene.completed, scene.failed]
    Webhook:
      type: object
      properties:
        id:
          type: integer
        description:
          type: string
        url:
          type: string
          format: uri
        events:
          type: array
          items:
            type: string
        status:
          type: string
        signing_secret:
          type: string
          description: Returned only when the webhook is created.
