{
  "openapi": "3.1.0",
  "info": {
    "title": "Puppetry API",
    "description": "Create AI-powered talking head videos programmatically. Upload a portrait image, provide text or audio, and get a realistic talking video back.",
    "version": "1.0.0",
    "contact": {
      "name": "Puppetry Support",
      "url": "https://www.puppetry.com",
      "email": "support@puppetry.com"
    },
    "termsOfService": "https://www.puppetry.com/tos",
    "license": {
      "name": "Proprietary"
    }
  },
  "servers": [
    {
      "url": "https://www.puppetry.com",
      "description": "Production"
    }
  ],
  "paths": {
    "/api/v1/animate/text": {
      "post": {
        "operationId": "animateWithText",
        "summary": "Create a talking head video from text",
        "description": "Upload a portrait image URL and text script. Puppetry generates TTS audio and creates a lip-synced talking head video.",
        "tags": ["Video Generation"],
        "security": [{ "apiKey": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["imageURL", "inputText"],
                "properties": {
                  "imageURL": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL of the portrait image to animate"
                  },
                  "inputText": {
                    "type": "string",
                    "minLength": 1,
                    "description": "The script text to convert to speech and animate"
                  },
                  "voice": {
                    "type": "string",
                    "description": "JSON-encoded voice info object (voiceId, gender, language)"
                  },
                  "outputFormat": {
                    "type": "string",
                    "enum": ["mp4", "gif", "webm"],
                    "default": "mp4"
                  },
                  "seamlessLoop": {
                    "type": "boolean",
                    "default": true
                  },
                  "removeBg": {
                    "type": "boolean",
                    "default": false,
                    "description": "Remove background from the portrait"
                  },
                  "cropToFace": {
                    "type": "boolean",
                    "default": false,
                    "description": "Auto-crop to face region"
                  },
                  "expressiveness": {
                    "type": "number",
                    "minimum": 0,
                    "maximum": 2,
                    "default": 1.0,
                    "description": "Controls animation expressiveness (0=subtle, 2=exaggerated)"
                  },
                  "musicURL": {
                    "type": "string",
                    "format": "uri",
                    "description": "Optional background music URL"
                  },
                  "authKey": {
                    "type": "string",
                    "description": "API authentication key"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Video generation task created",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AnimationResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid input",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/ErrorResponse" }
              }
            }
          },
          "401": { "description": "Authentication required" },
          "429": { "description": "Quota exceeded" }
        }
      }
    },
    "/api/v1/animate/audio": {
      "post": {
        "operationId": "animateWithAudio",
        "summary": "Create a talking head video from audio",
        "description": "Upload a portrait image URL and audio URL. Puppetry creates a lip-synced talking head video using the provided audio.",
        "tags": ["Video Generation"],
        "security": [{ "apiKey": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["imageURL", "inputAudioURL"],
                "properties": {
                  "imageURL": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL of the portrait image to animate"
                  },
                  "inputAudioURL": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL of the audio file to lip-sync"
                  },
                  "outputFormat": {
                    "type": "string",
                    "enum": ["mp4", "gif", "webm"],
                    "default": "mp4"
                  },
                  "authKey": {
                    "type": "string",
                    "description": "API authentication key"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Video generation task created",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AnimationResponse" }
              }
            }
          },
          "400": { "description": "Invalid input" },
          "401": { "description": "Authentication required" },
          "429": { "description": "Quota exceeded" }
        }
      }
    },
    "/api/v1/animate/video": {
      "post": {
        "operationId": "animateWithVideo",
        "summary": "Create a lip-synced video from a driving video",
        "description": "Upload a portrait image URL and a driving video URL. Puppetry transfers the motion from the driving video to the portrait.",
        "tags": ["Video Generation"],
        "security": [{ "apiKey": [] }],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["imageURL", "inputVideoURL"],
                "properties": {
                  "imageURL": {
                    "type": "string",
                    "format": "uri"
                  },
                  "inputVideoURL": {
                    "type": "string",
                    "format": "uri",
                    "description": "URL of the driving video"
                  },
                  "outputFormat": {
                    "type": "string",
                    "enum": ["mp4", "gif", "webm"],
                    "default": "mp4"
                  },
                  "authKey": { "type": "string" }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Video generation task created",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/AnimationResponse" }
              }
            }
          }
        }
      }
    },
    "/api/v1/task/{taskId}": {
      "get": {
        "operationId": "getTaskStatus",
        "summary": "Check video generation task status",
        "description": "Poll this endpoint to check if your video is ready. Returns status and video URL when complete.",
        "tags": ["Tasks"],
        "security": [{ "apiKey": [] }],
        "parameters": [
          {
            "name": "taskId",
            "in": "path",
            "required": true,
            "schema": { "type": "string" },
            "description": "The task ID returned from an animation request"
          }
        ],
        "responses": {
          "200": {
            "description": "Task status",
            "content": {
              "application/json": {
                "schema": { "$ref": "#/components/schemas/TaskStatus" }
              }
            }
          }
        }
      }
    },
    "/api/v1/voices": {
      "get": {
        "operationId": "getVoices",
        "summary": "List available AI voices",
        "description": "Returns all available TTS voices with language, gender, and preview URLs.",
        "tags": ["Voices"],
        "responses": {
          "200": {
            "description": "List of available voices",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": { "$ref": "#/components/schemas/Voice" }
                }
              }
            }
          }
        }
      }
    }
  },
  "components": {
    "securitySchemes": {
      "apiKey": {
        "type": "apiKey",
        "in": "header",
        "name": "Authorization",
        "description": "Your Puppetry API key"
      }
    },
    "schemas": {
      "AnimationResponse": {
        "type": "object",
        "properties": {
          "taskId": {
            "type": "string",
            "description": "Unique task identifier for polling status"
          },
          "task_id": {
            "type": "string",
            "description": "Backend task ID"
          },
          "status": {
            "type": "string",
            "enum": ["PENDING", "PROCESSING", "SUCCESS", "FAILURE"]
          },
          "video_url": {
            "type": "string",
            "format": "uri",
            "description": "URL of the generated video (available when status is SUCCESS)"
          }
        }
      },
      "TaskStatus": {
        "type": "object",
        "properties": {
          "status": {
            "type": "string",
            "enum": ["PENDING", "PROCESSING", "SUCCESS", "FAILURE"]
          },
          "progress": {
            "type": "number",
            "minimum": 0,
            "maximum": 100,
            "description": "Generation progress percentage"
          },
          "video_url": {
            "type": "string",
            "format": "uri"
          },
          "error": {
            "type": "string",
            "description": "Error message if status is FAILURE"
          }
        }
      },
      "Voice": {
        "type": "object",
        "properties": {
          "id": { "type": "string" },
          "name": { "type": "string" },
          "language": { "type": "string" },
          "gender": { "type": "string", "enum": ["male", "female"] },
          "previewUrl": { "type": "string", "format": "uri" },
          "source": {
            "type": "string",
            "enum": ["ElevenLabs", "PlayHT", "Cartesia"]
          }
        }
      },
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": { "type": "string" },
          "message": { "type": "string" }
        }
      }
    }
  }
}
