{
  "openapi": "3.1.0",
  "info": {
    "title": "Prizmad API",
    "version": "1.0.0",
    "description": "Create AI-powered video ads programmatically. Pass a template and product data to generate professional video advertisements."
  },
  "servers": [
    { "url": "https://prizmad.com", "description": "Production" }
  ],
  "security": [{ "bearerAuth": [] }],
  "paths": {
    "/api/v1/templates": {
      "get": {
        "operationId": "listTemplates",
        "summary": "List available templates",
        "description": "Returns all available video templates with their features and token costs. No authentication required.",
        "security": [],
        "responses": {
          "200": {
            "description": "List of templates",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "templates": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Template" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/avatars": {
      "get": {
        "operationId": "listAvatars",
        "summary": "List available avatars",
        "description": "Returns all built-in avatar presets with their recommended voice IDs. Pass the avatar `id` as `avatarPresetId` when creating a video.",
        "security": [],
        "responses": {
          "200": {
            "description": "List of avatars",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "avatars": {
                      "type": "array",
                      "items": { "$ref": "#/components/schemas/Avatar" }
                    }
                  }
                }
              }
            }
          }
        }
      }
    },
    "/api/v1/upload": {
      "post": {
        "operationId": "uploadFiles",
        "summary": "Upload product images",
        "description": "Upload product images to use in video generation. Returns an array of hosted URLs that can be passed to `product.images` in POST /api/v1/videos. Max 10 files, 20 MB each.",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "properties": {
                  "files": {
                    "type": "array",
                    "items": { "type": "string", "format": "binary" },
                    "description": "Image files (JPG, PNG, WebP, AVIF)"
                  }
                },
                "required": ["files"]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Upload successful",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/UploadResponse" },
                "example": {
                  "urls": [
                    "https://rqc9qnbavbhegeml.public.blob.vercel-storage.com/api/abc/1.png",
                    "https://rqc9qnbavbhegeml.public.blob.vercel-storage.com/api/abc/2.png"
                  ]
                }
              }
            }
          },
          "400": { "description": "No files, wrong format, or file too large" },
          "401": { "description": "Missing or invalid API key" },
          "429": { "description": "Rate limit exceeded" }
        }
      }
    },
    "/api/v1/videos": {
      "post": {
        "operationId": "createVideo",
        "summary": "Create a video",
        "description": "Start generating a video ad. Provide a template ID and product data (either a URL to scrape or direct product info). Returns immediately with a video ID for polling.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/CreateVideoRequest" },
              "examples": {
                "with_images": {
                  "summary": "Product with uploaded images",
                  "value": {
                    "templateId": "showcase-slideshow",
                    "product": {
                      "title": "White Insulated Tumbler",
                      "description": "Double-wall vacuum insulated tumbler. Keeps drinks hot 12h, cold 24h. 500ml capacity.",
                      "price": "$24.99",
                      "images": ["https://...blob.../1.png", "https://...blob.../2.png"]
                    },
                    "duration": 20
                  }
                },
                "with_url": {
                  "summary": "Scrape product from URL",
                  "value": {
                    "templateId": "showcase-narrated",
                    "productUrl": "https://www.amazon.com/dp/B0EXAMPLE",
                    "language": "en",
                    "tone": "professional"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Video generation started",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/CreateVideoResponse" }
              }
            }
          },
          "400": { "description": "Validation error" },
          "401": { "description": "Missing or invalid API key" },
          "402": { "description": "Insufficient token balance" },
          "429": { "description": "Rate limit exceeded (10 req/min)" }
        }
      }
    },
    "/api/v1/videos/{id}": {
      "get": {
        "operationId": "getVideoStatus",
        "summary": "Get video status",
        "description": "Check the status and progress of a video generation. Poll this endpoint until status is 'completed' or 'failed'.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "format": "uuid" },
            "description": "Video ID returned from POST /api/v1/videos"
          }
        ],
        "responses": {
          "200": {
            "description": "Video status",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/VideoStatus" }
              }
            }
          },
          "401": { "description": "Missing or invalid API key" },
          "404": { "description": "Video not found or not owned by this key" }
        }
      }
    },
    "/api/v1/videos/{id}/download": {
      "get": {
        "operationId": "downloadVideo",
        "summary": "Download video file",
        "description": "Download the rendered video file directly. Returns the MP4 file with Content-Disposition header for download. Only available after status is 'completed'.",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": { "type": "string", "format": "uuid" }
          }
        ],
        "responses": {
          "200": {
            "description": "Video file",
            "content": { "video/mp4": { "schema": { "type": "string", "format": "binary" } } }
          },
          "401": { "description": "Missing or invalid API key" },
          "404": { "description": "Video not found" },
          "409": { "description": "Video not ready yet" }
        }
      }
    },
    "/api/v1/videos/batch": {
      "post": {
        "operationId": "createVideoBatch",
        "summary": "Create multiple videos",
        "description": "Launch up to 20 video generations in one request. All videos run in parallel. Pre-checks total token cost before starting. Shared callbackUrl receives webhook for each completed/failed video.",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": { "$ref": "#/components/schemas/BatchVideoRequest" },
              "example": {
                "videos": [
                  { "templateId": "showcase-slideshow", "product": { "title": "Product A", "description": "...", "images": ["https://..."] } },
                  { "templateId": "showcase-narrated", "product": { "title": "Product B", "description": "...", "images": ["https://..."] } }
                ],
                "callbackUrl": "https://yourserver.com/webhook"
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Batch launched",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/BatchVideoResponse" }
              }
            }
          },
          "400": { "description": "Validation error" },
          "401": { "description": "Missing or invalid API key" },
          "402": { "description": "Insufficient balance for entire batch" }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "API key (przmad_sk_live_...) or OAuth 2.0 access token from POST /oauth/token"
      },
      "oauth2": {
        "type": "oauth2",
        "description": "OAuth 2.0 client_credentials flow. Use your API key as client_secret.",
        "flows": {
          "clientCredentials": {
            "tokenUrl": "https://prizmad.com/oauth/token",
            "scopes": {
              "videos:read": "Read video status and download",
              "videos:write": "Create videos and upload images"
            }
          }
        }
      }
    },
    "schemas": {
      "Template": {
        "type": "object",
        "properties": {
          "id": { "type": "string", "example": "dynamic-promo" },
          "name": { "type": "string", "example": "Dynamic Promo" },
          "description": { "type": "string" },
          "category": { "type": "string", "enum": ["hooks", "avatar-pitch", "product-showcase"] },
          "fixedDuration": { "type": "integer", "nullable": true },
          "cost": { "type": "integer", "description": "Token cost" },
          "features": { "type": "array", "items": { "type": "string" } },
          "requires": {
            "type": "object",
            "properties": {
              "avatar": { "type": "boolean" },
              "voice": { "type": "boolean" }
            }
          }
        }
      },
      "CreateVideoRequest": {
        "type": "object",
        "required": ["templateId"],
        "properties": {
          "templateId": { "type": "string", "description": "Template ID from GET /api/v1/templates" },
          "productUrl": { "type": "string", "format": "uri", "description": "URL of the product page to scrape. Either productUrl or product is required." },
          "product": {
            "type": "object",
            "description": "Direct product data. Either productUrl or product is required.",
            "required": ["title", "description"],
            "properties": {
              "title": { "type": "string" },
              "description": { "type": "string" },
              "price": { "type": "string" },
              "images": { "type": "array", "items": { "type": "string", "format": "uri" } },
              "specs": { "type": "object", "additionalProperties": { "type": "string" } }
            }
          },
          "language": { "type": "string", "default": "en", "description": "Language code (en, es, fr, de, etc.)" },
          "tone": { "type": "string", "enum": ["energetic", "professional", "friendly", "luxury", "funny"], "default": "professional" },
          "script": { "type": "string", "description": "Custom voiceover script. If omitted, AI generates one." },
          "voiceId": { "type": "string", "description": "ElevenLabs voice ID. If omitted, uses avatar's recommended voice or auto-selects by language." },
          "avatarPresetId": { "type": "string", "description": "Built-in avatar ID (e.g. 'F01', 'M04'). Get list from GET /api/v1/avatars. Auto-sets recommended voice." },
          "avatarId": { "type": "string", "format": "uuid", "description": "Database avatar preset ID (legacy)." },
          "avatarImageUrl": { "type": "string", "format": "uri", "description": "Direct URL to a custom avatar image." },
          "duration": { "type": "integer", "minimum": 10, "maximum": 60, "default": 30, "description": "Video duration in seconds. Ignored for fixed-duration templates." },
          "imagePromptHint": { "type": "string", "description": "Style hint for AI-generated product images." },
          "videoPromptHint": { "type": "string", "description": "Style hint for AI-generated product video." },
          "musicTone": { "type": "string", "enum": ["energetic", "professional", "friendly", "luxury", "funny"] },
          "musicPromptHint": { "type": "string", "description": "Style hint for background music." },
          "callbackUrl": { "type": "string", "format": "uri", "description": "Webhook URL for completion/failure notifications." }
        }
      },
      "CreateVideoResponse": {
        "type": "object",
        "properties": {
          "videoId": { "type": "string", "format": "uuid" },
          "status": { "type": "string", "example": "generating" },
          "cost": { "type": "integer", "description": "Tokens deducted" },
          "remainingBalance": { "type": "integer" },
          "estimatedSeconds": { "type": "integer", "description": "Estimated generation time" },
          "statusUrl": { "type": "string", "description": "Relative URL to poll for status" }
        }
      },
      "VideoStatus": {
        "type": "object",
        "properties": {
          "videoId": { "type": "string", "format": "uuid" },
          "status": { "type": "string", "enum": ["parsing", "parsed", "scripting", "script_ready", "generating", "compositing", "completed", "failed"] },
          "progress": { "type": "integer", "minimum": 0, "maximum": 100 },
          "videoUrl": { "type": "string", "format": "uri", "nullable": true },
          "thumbnailUrl": { "type": "string", "format": "uri", "nullable": true },
          "steps": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "step": { "type": "string" },
                "status": { "type": "string", "enum": ["pending", "running", "completed", "failed"] }
              }
            }
          },
          "createdAt": { "type": "string", "format": "date-time" },
          "completedAt": { "type": "string", "format": "date-time", "nullable": true },
          "errorMessage": { "type": "string", "nullable": true }
        }
      },
      "Avatar": {
        "type": "object",
        "description": "Built-in AI avatar preset.",
        "properties": {
          "id": { "type": "string", "example": "F01", "description": "Pass this as `avatarPresetId` when creating a video." },
          "name": { "type": "string", "example": "Sofia" },
          "gender": { "type": "string", "enum": ["female", "male"] },
          "age": { "type": "string", "enum": ["young", "adult", "mature"] },
          "imageUrl": { "type": "string", "description": "Public URL of the avatar image." },
          "recommendedVoiceId": { "type": "string", "description": "ElevenLabs voice ID auto-selected if no `voiceId` is passed." },
          "badge": { "type": "string", "nullable": true, "example": "Top Pick" }
        }
      },
      "UploadResponse": {
        "type": "object",
        "description": "Response from POST /api/v1/upload.",
        "properties": {
          "urls": {
            "type": "array",
            "items": { "type": "string", "format": "uri" },
            "description": "Hosted image URLs to pass to product.images in /api/v1/videos."
          }
        }
      },
      "BatchVideoRequest": {
        "type": "object",
        "required": ["videos"],
        "description": "Request body for POST /api/v1/videos/batch.",
        "properties": {
          "videos": {
            "type": "array",
            "minItems": 1,
            "maxItems": 20,
            "items": { "$ref": "#/components/schemas/CreateVideoRequest" },
            "description": "List of video creation requests (1–20)."
          },
          "callbackUrl": {
            "type": "string",
            "format": "uri",
            "description": "Webhook URL — receives a POST for each video completion or failure."
          }
        }
      },
      "BatchVideoResponse": {
        "type": "object",
        "description": "Response from POST /api/v1/videos/batch.",
        "properties": {
          "batchSize": { "type": "integer", "description": "Total items submitted." },
          "launched": { "type": "integer", "description": "Items successfully started." },
          "failed": { "type": "integer", "description": "Items that failed to launch." },
          "totalCost": { "type": "integer", "description": "Total tokens deducted." },
          "remainingBalance": { "type": "integer" },
          "videos": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "videoId": { "type": "string", "format": "uuid" },
                "templateId": { "type": "string" },
                "cost": { "type": "integer" },
                "status": { "type": "string", "example": "generating" },
                "error": { "type": "string", "nullable": true }
              }
            }
          }
        }
      }
    }
  }
}
