Skip to main content

Documentation Index

Fetch the complete documentation index at: https://developers.heygen.com/llms.txt

Use this file to discover all available pages before exploring further.

Overview

POST https://api.heygen.com/v2/template/{template_id}/generate Generates a video based on the specified template, replacing template placeholders with the values you supply via variables. You can also restrict generation to a subset of scenes, override the rendered dimension, attach subtitles, and more.

Path Parameters

ParameterTypeRequiredDescription
template_idstringYesUnique identifier of the template.

Request Body

ParameterTypeRequiredDescription
variablesobjectYesMap of variable name → variable object. Each entry replaces a template placeholder. See Variables below for the per-type schema.
captionbooleanNoEnable captions in the video. Default: false.
titlestringNoTitle of the video.
callback_idstringNoCustom ID for callback/webhook tracking.
callback_urlstringNoURL to notify when video rendering is complete. If both a webhook and callback_url are configured, events are sent to both.
dimensionobjectNoCustom output dimensions. Must match the template’s aspect ratio. If omitted, the template’s own dimension is used. Width and height must be even, between 128 and 4096.
dimension.widthintegerNoWidth of the output video.
dimension.heightintegerNoHeight of the output video.
fpsfloatNoOutput frame rate. Must be one of 25, 30, or 60. Default: 25.
scene_idsarray of stringsNoGenerate only this subset of scenes, in the given order. Repeats are allowed. If omitted, all scenes are generated.
reorder_musicbooleanNoWhen true (default), background-audio tracks move with their scenes. When false, tracks stay pinned to the original layout positions.
keep_text_vertically_centeredbooleanNoWhen true, replaced text elements are vertically centered based on their actual rendered height.
subtitlesobjectNoBurned-in subtitle overlay settings (see Subtitles below).
include_gifbooleanNoInclude a GIF preview URL in the webhook response. Default: false.
enable_sharingbooleanNoMake the video publicly shareable immediately after creation. Default: false.
folder_idstringNoFolder ID where the video is stored.
brand_voice_idstringNoBrand Glossary ID for applying predefined translation and pronunciation rules (translation exclusions, enforced terms, vocabulary mappings, tone preferences).
testbooleanNoRender in test mode (lower quality, no quota deduction). Default: false.

Variables

variables is an object keyed by variable name. Each value has the same outer shape:
FieldTypeRequiredDescription
namestringYesThe variable’s name. Must match the key it’s assigned to and a placeholder declared by the template.
typestringYesDiscriminator: text, image, video, audio, voice, or character. Determines the shape of properties.
propertiesobjectYesType-specific replacement payload — see the per-type tables below.

text variable

properties fieldTypeRequiredDescription
contentstringYesReplacement text. Maximum length: 10000 characters. Cannot be empty.

image variable

properties fieldTypeRequiredDescription
urlstringYes*Public URL of the image. Provide either url or asset_id, not both.
asset_idstringYes*Asset ID of an uploaded image. Provide either url or asset_id, not both.
fitstringNoHow the image fills the placeholder slot: contain (default), cover, crop, or none.

video variable

properties fieldTypeRequiredDescription
urlstringYes*Public URL of the video. Provide either url or asset_id, not both.
asset_idstringYes*Asset ID of an uploaded video. Provide either url or asset_id, not both.
play_stylestringNoPlayback mode: loop (default), freeze, or fit_to_scene.
fitstringNoHow the video fills the placeholder slot: contain (default), cover, crop, or none.
volumefloatNoVideo volume. Range: 0.01.0. Default: 1.0.

audio variable

properties fieldTypeRequiredDescription
urlstringYes*Public URL of the audio. Provide either url or asset_id, not both.
asset_idstringYes*Asset ID of an uploaded audio file. Provide either url or asset_id, not both.

voice variable

Replaces the voice that speaks the scene’s script. The script content itself comes from the template (or a text variable).
properties fieldTypeRequiredDescription
voice_idstringYesVoice identifier.
localestringNoVoice accent/locale (e.g., en-US, pt-BR).

character variable

Replaces an avatar or talking-photo placeholder in the template.
properties fieldTypeRequiredDescription
character_idstringYesThe avatar or talking-photo identifier to use as the replacement. Cannot be empty.
typestringYesavatar or talking_photo.
alignment_paramsobjectNoContainment and alignment for the replacement (see alignment_params below). When omitted, the replacement uses the template’s stored framing.
preserve_rounded_cornersbooleanNoOpt in to making the template’s rounded corners visible on the rendered video (see preserve_rounded_corners below). When unset, the template’s own setting is used.

alignment_params

Use alignment_params when the replacement avatar has a different aspect ratio or framing from the original and you want it confined to the original element’s box.
FieldTypeRequiredDescription
fitstringNonone (default) keeps the values returned by the replacement pipeline. contain rescales the replacement so it fits entirely inside the original element’s box.
alignstringNoWhen fit is contain, which edge of the replacement to pin: center (default), top, bottom, left, or right. Has no effect when fit is none.
{
  "alignment_params": {
    "fit": "contain",
    "align": "bottom"
  }
}

preserve_rounded_corners

Avatars rendered without a background (expressive avatars, custom avatars with matting disabled) reserve transparent room around the silhouette so outstretched arms or hands aren’t clipped. Because that bleed area extends past the visible display box, any rounded_corners baked into the template have nothing visible to round at the renderer’s edges and the corners appear missing on the final video. Setting preserve_rounded_corners: true on the variable opts that placeholder back into a tighter crop — the avatar is constrained to its display box so the rounded corners are visible — at the cost of clipping anything that extends beyond it (e.g. a wave or outstretched arms).
ValueBehaviour
trueThe renderer keeps the display-box crop. Rounded corners render visibly. Content outside the display box (arms, hands, etc.) may be clipped.
falseThe display-box crop is dropped. The full avatar silhouette is preserved, but the template’s rounded_corners will not be visible on the rendered video.
unsetInherit the template’s stored value. Defaults to false for templates that do not opt in.
{
  "avatar": {
    "name": "avatar",
    "type": "character",
    "properties": {
      "character_id": "Jason_public_3_20240312",
      "type": "avatar",
      "preserve_rounded_corners": true
    }
  }
}
If you don’t see the template’s rounded corners in your rendered video and the avatar has no background, set preserve_rounded_corners: true on the character variable for that placeholder.

Subtitles

ParameterTypeRequiredDescription
preset_namestringYesSubtitle preset name.
alignmentintegerNoSubtitle alignment code. Default: 2.
disable_highlightbooleanNoOverride the preset’s highlight style. Default: false.
font_sizeintegerNoFont size override.
positionobjectNoSubtitle position: { "x": 0.0, "y": 0.0 }.

Example Request

POST /v2/template/YOUR_TEMPLATE_ID/generate

{
  "title": "My Template Video",
  "caption": false,
  "dimension": {
    "width": 1920,
    "height": 1080
  },
  "variables": {
    "script": {
      "name": "script",
      "type": "text",
      "properties": {
        "content": "Hello, welcome to our product demo."
      }
    },
    "headline": {
      "name": "headline",
      "type": "text",
      "properties": {
        "content": "Product Overview"
      }
    },
    "avatar": {
      "name": "avatar",
      "type": "character",
      "properties": {
        "character_id": "Jason_public_3_20240312",
        "type": "avatar",
        "preserve_rounded_corners": true,
        "alignment_params": {
          "fit": "contain",
          "align": "bottom"
        }
      }
    }
  }
}

Response

200 — Success

{
  "error": null,
  "data": {
    "video_id": "763fca2469b98a65b351eqr8c449f4e8"
  }
}
FieldTypeDescription
errorstring | nullError message if the request fails; null on success.
data.video_idstringUnique identifier of the generated video.

Full API Reference

For complete details, see the Generate Video from Template (V2) endpoint documentation.