# Generate Video from Template

Generates a video based on the specified template, including scene IDs to define the sequence of scenes and variable values for replacement.

<Callout icon="📘" theme="info">
  **Note:**

  * Scroll down to the **Response** section below and expand the status code(s) to view the detailed response schema.
  * Refer to the **RESPONSE** section on the right and choose an example to see how the API response appears for each status code.
</Callout>

# OpenAPI definition

```json
{
  "openapi": "3.1.0",
  "info": {
    "title": "heygen-api",
    "version": "4.0.8"
  },
  "servers": [
    {
      "url": "https://api.heygen.com"
    }
  ],
  "components": {
    "securitySchemes": {
      "sec0": {
        "type": "apiKey",
        "name": "x-api-key",
        "in": "header",
        "x-default": "<your-api-key>"
      }
    }
  },
  "security": [
    {
      "sec0": []
    }
  ],
  "paths": {
    "/v2/template/{template_id}/generate": {
      "post": {
        "summary": "Generate Video from Template",
        "description": "",
        "operationId": "generate-from-template-v2",
        "parameters": [
          {
            "name": "template_id",
            "in": "path",
            "schema": {
              "type": "string"
            },
            "required": true,
            "description": "Unique identifier of the template. Can be retrieved from the <a href=\"https://docs.heygen.com/reference/list-templates-v2\" target=\"_blank\">List Templates</a> endpoint."
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "caption": {
                    "type": "boolean",
                    "description": "Whether to enable captions in the video. ",
                    "default": false
                  },
                  "title": {
                    "type": "string",
                    "description": "Title of the video."
                  },
                  "variables": {
                    "type": "string",
                    "description": "Dynamic variables used within the template.",
                    "format": "json"
                  },
                  "dimension": {
                    "type": "object",
                    "description": "Custom dimensions for the output video. Must match the aspect ratio of the template (e.g., `landscape` or `portrait`).",
                    "properties": {
                      "width": {
                        "type": "integer",
                        "default": 1280,
                        "format": "int32",
                        "description": "Width of the output video."
                      },
                      "height": {
                        "type": "integer",
                        "default": 720,
                        "format": "int32",
                        "description": "Height of the output video."
                      }
                    }
                  },
                  "include_gif": {
                    "type": "boolean",
                    "description": "Whether to include a GIF preview URL in the webhook response.",
                    "default": false
                  },
                  "enable_sharing": {
                    "type": "boolean",
                    "description": "Whether to make the video publicly shareable immediately after creation."
                  },
                  "folder_id": {
                    "type": "string",
                    "description": "Unique identifier of the folder where the video is stored. Can be retrieved from the <a href=\"https://docs.heygen.com/reference/list-folders\" target=\"_blank\">List Folders</a> endpoint if folder already exists, or from the response of the <a href=\"https://docs.heygen.com/reference/create-folder\" target=\"_blank\">Create Folder</a> endpoint after creating a new folder."
                  },
                  "brand_voice_id": {
                    "type": "string",
                    "description": "Unique identifier of the Brand Glossary. It is used to apply predefined translation and pronunciation rules such as translation exclusions, enforced terms, vocabulary mappings, and tone preferences. Can be retrieved from <a href= \"https://docs.heygen.com/reference/list-brand-voices\" target=\"_blank\"> List Brand Voices </a> endpoint. "
                  },
                  "callback_url": {
                    "type": "string",
                    "description": "URL to notify when video rendering is complete, useful when your callback endpoint is dynamic and each video requires a separate callback. Using a webhook endpoint is still the recommended approach, as it provides more customization options such as secrets, event filtering, and more. If both webhook and callback_url are used, events will be sent to both endpoints."
                  },
                  "keep_text_vertically_centered": {
                    "type": "boolean",
                    "description": "When true, text elements that are replaced will be vertically centered based on their actual rendered height."
                  }
                },
                "required": [
                  "variables"
                ]
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Video generated successfully - Expand to view the detailed response schema.",
            "content": {
              "application/json": {
                "examples": {
                  "Result": {
                    "value": {
                      "error": null,
                      "data": {
                        "video_id": "763fca2469b98a65b351eqr8c449f4e8"
                      }
                    }
                  }
                },
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "description": "Displays error message when the request fails; null if the request is successful."
                    },
                    "data": {
                      "type": "object",
                      "properties": {
                        "video_id": {
                          "type": "string",
                          "description": "Unique identifier of the generated video. "
                        }
                      },
                      "description": "Contains the video ID. "
                    }
                  }
                }
              }
            }
          }
        },
        "deprecated": false
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": true,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true
}
```