Tutorial
HeyGen Avatar 6 Turbo Ref Video-to-Video API: Working curl and Python Request
A practical integration path from first call to a finished video
On this page
When reference video-to-video fits your pipeline
Most avatar generation starts from a still image: you upload a portrait, the model animates it, and you get a talking head. That works well when you only have a photo. But it throws away motion, framing, and body language that already exist in footage you shot. heygen-avatar-6-turbo/ref-video-to-video is built for the case where your source material is a video, not a still.
In this mode, a reference clip drives the output: its timing, movement, and overall structure act as the template, while the target identity you supply is rendered into that performance. Think of it as a re-render rather than a from-scratch generation. If your pipeline already produces a performance clip — a presenter reading a script, a spokesperson demo, a product walkthrough with a person on camera — and you need that same performance delivered by a different identity or a cleaned-up synthetic presenter, reference video-to-video is the natural fit.
It is the wrong tool in a few clear cases. If all you have is a single headshot, use image-driven avatar generation instead. If you need to change the spoken content itself, generate new audio first and treat this model as the visual layer. And if you need frame-accurate editing control over every shot, this is a generative pass, not a timeline editor — expect the model to interpret the reference rather than clone it pixel for pixel.
The practical decision rule: does your input already contain the motion you want? If yes, reference video-to-video saves you from describing motion in a prompt. If no, you are better served generating from an image and letting the model drive the performance.
One integration note up front: this is a long-running job, not a synchronous call. Plan your architecture around submit → handle → retrieve from the start, and the rest of this walkthrough will line up cleanly. The model page at heygen-avatar-6-turbo/ref-video-to-video is the canonical reference for the current parameter surface.
What you need before the first request
Four things must be in place before you write a single line of request code. Getting these right up front eliminates most first-call failures.
1. A HiAPI API key. All requests authenticate against the HiAPI unified interface, so you need an account and an API key issued from it. Keep the key server-side — never ship it in client code or commit it to a repo. Load it from an environment variable such as HIAPI_API_KEY so local runs and CI behave the same way.
2. The exact model path. The identifier is heygen-avatar-6-turbo/ref-video-to-video. It is a path, not a display name: the vendor segment, the model name, and the mode are joined by slashes. Typos here are the single most common cause of a rejected request, and they usually surface as a generic "model not found" rather than a helpful message. Copy the string from the model page rather than retyping it.
3. The source media. This mode consumes a reference video, so you need a clip the service can fetch — a publicly reachable HTTPS URL is the most portable option. Check that the URL resolves without authentication, returns the video bytes directly (not an HTML viewer page), and uses a container and codec that browsers play natively. Clips that work when you open them in a tab but fail in a request are almost always redirect chains or signed links that expired.
4. Output settings. Decide the shape of the finished asset before submitting: the aspect ratio you need for the target channel, and whether you want audio carried through from the reference or handled separately. The exact accepted values live on the model page and can change as the model is updated, so treat that page — not a blog post — as the source of truth for parameter names and allowed values.
Two smaller items worth settling now: a callback URL if you want push notification instead of polling, and a storage location for the finished file, since output URLs from generation services are typically temporary. Neither is mandatory for a first test call, but wiring them in later means touching your job-handling code twice.
Submitting a job with curl
Start with the smallest possible request that proves your credentials and model path are correct. Send a POST with a JSON body carrying your reference video and output settings.
curl -X POST "$HIAPI_BASE_URL/v1/generations" \
-H "Authorization: Bearer $HIAPI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "heygen-avatar-6-turbo/ref-video-to-video",
"input": {
"reference_video_url": "https://your-bucket.example.com/clips/presenter-take-3.mp4",
"output": {
"aspect_ratio": "9:16"
}
}
}'
A few habits that make this reproducible. Keep the base URL in an environment variable rather than pasting a host into your shell history, and quote $HIAPI_API_KEY so a stray character cannot break the header. Write the body to a file (-d @payload.json) once it grows past a couple of fields — debugging a malformed heredoc is a waste of an afternoon.
The response to a successful submit is a job envelope, not a finished video. It carries an identifier for the job and a status field, something like:
{
"id": "job_01H...",
"status": "queued",
"model": "heygen-avatar-6-turbo/ref-video-to-video"
}
Capture id immediately and log it alongside your own request identifier. Everything downstream — polling, retries, support questions — keys off that value.
If you would rather not poll at all, add a callback field to the request body pointing at an HTTPS endpoint you control. The service then notifies you when the job reaches a terminal state. Callbacks are the better choice for production volume; polling is better for a first test because it needs no public endpoint.
The same request in Python
The Python port should stay boring. Use requests for the transport and the standard library for everything else.
import os
import requests
API_KEY = os.environ["HIAPI_API_KEY"]
BASE_URL = os.environ["HIAPI_BASE_URL"]
payload = {
"model": "heygen-avatar-6-turbo/ref-video-to-video",
"input": {
"reference_video_url": "https://your-bucket.example.com/clips/presenter-take-3.mp4",
"output": {"aspect_ratio": "9:16"},
},
}
response = requests.post(
f"{BASE_URL}/v1/generations",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
},
json=payload,
timeout=60,
)
response.raise_for_status()
job = response.json()
print(job["id"], job["status"])
Three details matter more than they look. First, raise_for_status() turns an HTTP error into an exception at the point of failure, which is far easier to triage than a downstream KeyError on a missing id. Second, an explicit timeout prevents a hung connection from stalling a worker forever — sixty seconds is generous for a submit call. Third, pass the body with json=payload rather than data=; letting the library serialize and set the content type removes a whole class of encoding bugs.
Wrap the whole thing in a small function that returns the job id, and keep the payload construction separate from the transport. When you later add parameters, you change one dict instead of hunting through call sites.
Handling the async result
Treat this model as a long-running job and your code will stay honest. The lifecycle has three states you care about: submitted, terminal-success, terminal-failure. Anything else is "keep waiting."
Capture the handle. The submit response gives you the job id. Persist it — a database row, a queue message, a log line at minimum. If your process dies between submit and poll, that id is your only way back to the result.
Choose your wait strategy. With a callback, your endpoint receives the job id and terminal status and you fetch the output once. With polling, call the job-status endpoint for that id on an interval with a bounded number of attempts. Back off between attempts — start short, grow the gap, cap it — and always set a maximum total wait. Unbounded polling loops are how a harmless slow job becomes an incident.
Retrieve the output on success. A terminal-success payload contains the location of the finished asset. Download it to your own storage immediately, before the reference expires, and record the content type and size you actually received. Do not hand a temporary generation URL straight to end users.
Fail loudly on terminal-failure. Log the job id, the status, and the error detail as a unit. A failed job that only logs "something went wrong" costs more time than the generation itself.
The rule that saves the most pain: only ever act on terminal states. A queued or running response means your loop continues; it is never a partial result you can render.
Troubleshooting common failures
Work the checklist in this order. It moves from the cheapest checks to the most expensive.
Auth first. A 401 or 403 means the key is missing, malformed, or not being sent. Confirm the Authorization header carries the Bearer prefix, that the environment variable actually resolved in the shell or process that made the call, and that you are not sending a stale key from a different environment.
Then the model path. A 404 or a model-not-found error is almost always a typo in heygen-avatar-6-turbo/ref-video-to-video, a missing vendor prefix, or the wrong mode segment. Compare against the model page character by character.
Then the input media. A 400 with an input-related message usually means the URL was unreachable, required authentication, returned HTML instead of video bytes, or pointed at a format the service cannot decode. Test the URL with a plain curl -I from a machine outside your network — signed links that work locally frequently fail there.
Then the parameter shape. A 422 or a validation error means a field is missing or a value is outside the accepted set. Re-read the model page for the current parameter names; do not carry names forward from an older integration.
Then timeouts. A submit that hangs or 504s is often a large file: reference clips get fetched and processed server-side, so trim the source to the segment you actually need. If the job submits but never completes, check your polling against the job-status response rather than assuming the job died.
Finally, malformed polling. The classic version: polling the wrong endpoint, using the model path as the job id, treating the submit response as the final result, or exhausting a retry budget on a job that was still working. Log every status transition with timestamps — the shape of that log tells you instantly whether you gave up too early or never had a valid handle.
Get credentials, model path, and input media right, and the rest is a straightforward wait. The model page remains the reference for anything parameter-related that changes after this was written.
Related articles
View all articles →-
Tutorial
How to Call heygen-avatar-6-turbo/identity-to-video via the HiAPI API
9 min read -
Tutorial
Midjourney Niji 8 in Practice: Inputs, Settings, and Acceptance for Four Types of Japanese-Style Illustration Delivery Tasks
From game characters to light novel illustrations, use structured fields to complete image selection and acceptance
-
Tutorial
5 GLM 5.4 Use Cases for Developers: From Large Codebases to 3D
3 min read