Skip to main content

Overview

A template is a video you design once in HeyGen Studio and reuse by swapping in different values. You mark the parts you want to change per video, the script, the voice, the avatar, the background, as variables, give each one a name, then use the API to fill those variables and generate a new video for every set of values. One idea ties Studio and the API together: the name you give a variable in Studio is the exact key you send in the API. Name a variable name in the editor, and you fill it with "name": { ... } in your request. This guide walks the full loop: build the template in Studio, then drive it from the API.
For the complete variable-type schema (text, image, video, audio, voice, character), asset inputs, scenes, and every generate option, see the Studio Template reference.

Prerequisites

Part 1 — Build the template in Studio

You’ll build a one-scene welcome video with four variables: the viewer’s name (text), the voiceover, the presenter (avatar), and the background.
1

Open the template editor

In HeyGen Studio, create a new video (or open an existing one) and lay out your avatar, script, and background as usual. This layout is what every generated video will share.
HeyGen Studio editor with an avatar on the canvas
2

Turn script text into a variable

In the Script pane, wrap any word you want to change per video in double braces. Here the script is Hi {{name}}, Welcome to HeyGen, so name becomes a text variable you fill at generate time.
Script with the name token typed as a variable
The text between the braces is the variable name, and it is the exact key you send in the API.
3

Make the voice a variable

Open the three-dots menu on the script and choose API Variable. Name it voiceover and click Save. The voice for the scene can now be set per request.
Three-dots menu with API Variable, naming the voice variable voiceover
4

Make the avatar a variable

Select the avatar on the canvas, then click the API button in the hover toolbar. Name it presenter and Save. You can now swap the avatar per video.
Avatar selected with the API button, naming the character variable presenter
5

Make the background a variable

Click the background directly (not the avatar), then click the API button in its toolbar. Name it background and Save. The scene background can now be set per request.
Background selected with the API button, naming the image variable background
6

Save the template

Click Done Editing. Your template is now API-ready and will appear in the templates list.
Template saved successfully
You now have a template with four named variables, name, voiceover, presenter, and background. Those names are exactly the keys you use next.

Part 2 — Generate videos from the API

The flow is four calls: find the template, read its variables, fill them, then poll for the finished video.
1

Find your template

List the API-ready templates in your workspace and grab the id of the one you built.
Response
2

Read the variable schema

Fetch the template to see the variables you named in Studio, with their types and current defaults.
Response
Each variable comes back in the same shape a generate request accepts, so you can take this object, swap the values, and send it straight back.
3

Fill the variables and generate

Send the variables keyed by the names you set in Studio. Here we personalize name to “Alex” and set a new background.
Response
Only include the variables you want to change, any you omit keep their template defaults. Add "test": true to render a lower-quality test video with no credit charge while you wire things up.
4

Poll for the finished video

Generation is asynchronous. Poll the video by the id returned above until its status is completed, then read video_url.
Response
Instead of polling, set a callback_url on the generate request to be notified when the video is ready. See Webhooks.

Troubleshooting

Only templates that have at least one variable defined appear in GET /v3/templates, and the detail endpoint supports templates built in the current editor (draft version 4). Make sure you marked and saved at least one variable in Studio.
The keys in your variables object must match the variable names you set in Studio exactly (case-sensitive). Read GET /v3/templates/{template_id} to confirm the names.
A text variable can be empty in the schema (an unfilled default), but it must be non-empty when you generate.

Next steps

Studio Template reference

Every variable type, asset input, scenes, and generate options.

Webhooks

Get notified when a video finishes instead of polling.