BYOK is live — 1,000,000 free BYOK requests every month, no top-up requiredLearn more

Video production7 min read

AI Video API: Batch-Generate Short Drama Clips in Python

An AI video API turns a storyboard into footage without clicking through a web interface dozens of times per episode. A short-drama episode is fifteen to thirty clips, each generated more than once, and a season is hundreds of requests. Doing that by hand is slow and error-prone; doing it with a short script is routine. This guide explains how BoostRail's AI video API works, gives a complete Python script that generates a whole scene in one run, and covers failures, downloads and cost control.

How the AI video API works

Video generation takes minutes, so the API is asynchronous. A request does not return a video; it returns a task, and you check the task until it finishes. The flow has three steps:

  1. Submit. POST /v1/videos with the model, the prompt, the clip length in seconds and the size. The response comes back immediately with a task id and a status.
  2. Poll. GET /v1/videos/{id} returns the task's current status. While the clip renders, the status is pending or running. It ends as succeeded, failed, cancelled or expired.
  3. Download. When the status is succeeded, data[0].url holds a signed download link for the MP4. The link is valid for 10 minutes; poll the task again to get a fresh one.

Billing follows the task. When you submit, the expected cost is held from your balance; when the clip succeeds, the actual cost is settled. Failed, cancelled and expired tasks are not charged, and the hold is released. A request rejected before it starts, for example with a parameter the model does not accept or a balance too low to cover the hold, is not charged either. The Docs quickstart lists the endpoints, and each model's page, such as MiniMax H3, shows which sizes, lengths and options it accepts.

A script that generates a whole scene

The script below takes one scene from the storyboard, submits every clip, polls them together and downloads each clip as soon as it is ready. It uses only the requests library. The prompts follow the sectioned format from the guide on AI video prompts, with frozen style, place and character lines reused in every clip.

import time
import requests

API = "https://api.boostrail.com/v1"
HEADERS = {"Authorization": "Bearer YOUR_API_KEY"}

STYLE = "STYLE: realistic drama, soft film grain, muted teal and amber palette."
PLACE = "PLACE: a narrow apartment kitchen at night, one warm ceiling light, rain on the window."
LIN = "CHARACTER: Lin - woman, about 28, straight black hair to the shoulders, long red wool coat."

# One scene, one clip per storyboard row. Style, place and character lines are frozen and reused.
SHOTS = [
    {"name": "s01-shot01", "seconds": 5, "prompt": "\n".join([
        STYLE, "SHOT: medium close-up, eye level, camera static. Vertical frame.", PLACE, LIN,
        "BLOCKING: Lin stands at the counter, facing the window, phone in her right hand.",
        "BEATS: 0-2s she reads a message on the phone. 2-5s she lowers the phone slowly.",
        "SOUND: rain on the glass. No dialogue. No background music.",
    ])},
    {"name": "s01-shot02", "seconds": 5, "prompt": "\n".join([
        STYLE, "SHOT: close-up, slightly low angle, slow push-in. Vertical frame.", PLACE, LIN,
        "BLOCKING: Lin faces the camera, the phone lowered at her side.",
        "BEATS: 0-2s she looks up, eyes wet. 2-5s she speaks quietly.",
        'SOUND: dialogue, Lin, quiet and steady: "You knew all along." Rain on the glass.',
    ])},
]


def submit(shot):
    r = requests.post(f"{API}/videos", headers=HEADERS, json={
        "model": "minimax-h3",
        "prompt": shot["prompt"],
        "seconds": shot["seconds"],
        "size": "768p",
        "upstream_options": {"aspect_ratio": "9:16"},
    })
    r.raise_for_status()  # 4xx = rejected before it started, nothing charged
    return r.json()["id"]


# Submit the whole scene first, then poll every task until it finishes.
tasks = {submit(shot): shot["name"] for shot in SHOTS}
pending = set(tasks)
while pending:
    time.sleep(15)
    for task_id in list(pending):
        status = requests.get(f"{API}/videos/{task_id}", headers=HEADERS).json()
        if status["status"] not in ("succeeded", "failed", "cancelled", "expired"):
            continue
        pending.discard(task_id)
        name = tasks[task_id]
        if status["status"] == "succeeded":
            video = requests.get(status["data"][0]["url"])  # signed link, valid for 10 minutes
            video.raise_for_status()
            with open(f"{name}.mp4", "wb") as f:
                f.write(video.content)
            print(name, "saved, charged", status["settled_amount"])
        else:
            print(name, status["status"], status["error"])  # not charged; change the prompt before retrying

Replace YOUR_API_KEY with a key from the console, add rows to SHOTS for the rest of the scene, and run it. Each finished clip is saved under its storyboard name, and the script prints what each one cost.

Why the script is shaped this way

Submit first, poll after. Submitting the whole scene before polling lets the clips render in parallel instead of one after another, so a scene takes roughly as long as its slowest clip.

Name files after the storyboard. A clip called s01-shot02.mp4 goes straight into the edit. A clip called by its task id has to be matched by hand.

Download immediately. Generated files are not kept forever; MiniMax H3 files are kept for less than 6 days, and the signed link itself lasts 10 minutes. Downloading inside the polling loop means nothing is lost if the script is left running overnight.

Print the settled amount. Keeping each clip's cost next to its file makes it easy to compare a scene's real cost with the estimate from the short-drama cost calculator.

Handling failures without paying twice

Three kinds of failure need different responses:

  • Rejected at submit. The API returns an error and no task is created, so nothing is charged. A parameter the model does not accept, such as a clip length outside its range, or a balance too low for the hold, ends here. Fix the request and resubmit.
  • Failed while generating. The task ends as failed and is not charged. Read the error. If the content was rejected or the prompt asked for something the model cannot do, change the prompt before trying again; resubmitting the same request usually fails the same way.
  • Succeeded but wrong. The clip is charged, because the model did what it was asked. This is where most money is lost, and it is a prompt problem rather than an API problem: decide which section of the prompt caused it and change that section.

For the general pattern of retries, timeouts and switching between models in API clients, the guide on LLM API fallback covers the same ideas for text models.

Running a whole episode

The same script scales from one scene to a full episode with a few habits rather than more code.

Work scene by scene. Run one scene, review the clips, fix the prompts that produced weak takes, then move on. Submitting the whole episode at once means that one mistake in a frozen description, such as the wrong coat, repeats across every clip before you see it.

Estimate before you submit. Before running a scene, add up the seconds in SHOTS and multiply by the price per second of the model and size you chose. If the total is more than the scene is worth, change the storyboard, not the script's error handling.

Keep a production log. Write each clip's name, task id, final status and settled amount to a spreadsheet or a CSV file as the script prints them. The log tells you which clips still need a retake, what the episode actually cost and which prompt version produced each kept take.

Rerun only what failed. When a clip fails or is rejected in review, change its prompt and keep only that row in SHOTS for the next run. Clips you have already kept are never generated again, so they are never paid for twice.

Mix models inside one scene. For a landscape insert or an establishing shot, set the row's model to wan-3.0, its size to 480p or higher, its length to 5 or 10 seconds, and leave out the aspect_ratio option, which Wan 3.0 does not take. The rest of the loop stays the same.

Practical limits to plan around

  • Clip lengths and options are per model. MiniMax H3 takes 5 to 15 seconds and the aspect_ratio option; Wan 3.0 takes 5 or 10 seconds and no aspect option. Submitting values outside those ranges is rejected before it starts.
  • Text prompts only, for now. The public short-drama models on BoostRail do not accept reference images yet, so the script sends prompts alone.
  • One key, one balance. Every clip draws from the same prepaid balance as your text model calls. For a studio producing steadily, the AI short-drama studios page explains volume pricing.

Frequently asked questions

How long does one clip take to generate?

Usually a few minutes, depending on the model, the length and the resolution. Submitting a whole scene at once means the scene takes about as long as its slowest clip, not the sum of all of them.

Is there a webhook, or do I have to poll?

Poll the task with GET /v1/videos/{id}. Polling every fifteen seconds or so is enough; finished clips stay available for download for a while, and every poll of a succeeded task returns a fresh signed link.

Am I charged for clips that fail?

No. Failed, cancelled and expired tasks are not charged, and requests rejected before they start are not charged either. Clips that succeed are charged for the seconds requested, whether or not you keep them.

Can I cancel a clip after submitting it?

Yes, with POST /v1/videos/{id}/cancel while it is still pending or running. A cancelled task is not charged.

Start with one API key.

BoostRail is one OpenAI-compatible API for 75 text, image and video models. An API key takes about a minute.

Last updated: 2026-11-10