Disclosure: Written by the minimax3 team. We run an independent third-party MiniMax H3 (Hailuo 3) video generator and are not affiliated with, endorsed by, or operated by MiniMax or Hailuo.
The first time you build anything around a text-to-video model, it's tempting to treat it like a text API: send a prompt, get a result, done. That works for a demo. It falls apart the moment someone asks for "a 45-second product video," a retry fires twice, or a job fails at 2 a.m.
Short-clip video models behave more like a render farm than a chat endpoint. Jobs are slow, they cost money, they have hard limits, and the output is a file you still have to inspect. This post is about the engineering around the prompt: planning shots as data, chaining clips through a last frame, and scripting jobs safely. The examples use MiniMax H3, but most of the habits carry over to other models.
Know the envelope, then encode it
Before you write any glue code, write down the constraints and enforce them in your own validation. For MiniMax H3, the officially documented envelope is:
- Duration: 4–15 seconds, whole numbers only
- Output: 768P or 2K, 24 fps
- Prompt: up to 7,000 characters
- References: up to 9 images, 3 videos and 3 audio files, 12 files total
- Audio: native stereo at 32 kHz, per the official model card
- Modes: text-to-video, first- and last-frame image-to-video, and reference-to-video
Two things here matter most for design. First, 15 seconds is the ceiling. Anything longer is several jobs, not one, and your product copy and UI should never suggest otherwise. Second, integer durations mean a slider that allows 7.5 s is a bug waiting to happen. Reject bad input at the edge, not after you've already spent credits.
Treat a video as a shot list, not a prompt
A single prompt describing a whole minute of video will disappoint you. A list of shots, each fitting the envelope, gives you something you can review, regenerate and reorder.
Here's the kind of planning file we keep next to a project. This is our own format, not an API schema. It's just data your script reads:
{ "project": "latte-demo", "aspect_ratio": "16:9", "shots": [ { "id": "s01", "duration": 5, "mode": "text-to-video", "prompt": "A barista in a green apron pours steamed milk into a white cup, drawing a leaf pattern. Static close-up at counter height. Warm window light from the left. Sound: soft café chatter, milk jug hiss. Ends on the finished leaf, centered." }, { "id": "s02", "duration": 6, "mode": "image-to-video", "start_from": "s01.last_frame", "prompt": "The barista slides the cup across the counter toward the camera. Camera stays static. Same light. Sound: ceramic scraping on wood. Ends with the cup stopping in the foreground." } ] } A few rules make this work:
- Every shot states its ending. If the prompt doesn't say how the shot ends, the next shot has nothing to continue from.
- Durations live in the plan. Your validator checks each one is an integer from 4 to 15 before anything gets submitted.
- Prompts are direction, in a fixed order: subject, action, camera, light, sound, ending. Put the most important constraint early. A consistent structure also makes diffs between prompt versions readable in code review.
Chain clips through the last frame
The usual way to make several short clips feel like one sequence is to continue from the previous clip's last frame. Image-to-video takes a starting image, and optionally an ending frame, so the pipeline looks like this:
- Generate shot 1.
- Pull its final frame out as a still.
- Use that still as the starting image for shot 2.
- Repeat.
Extracting the last frame is a standard ffmpeg job:
ffmpeg -sseof -1 -i s01.mp4 -update 1 -q:v 1 s01_last.jpg That seeks to about one second before the end and keeps overwriting the output until the final decoded frame is the one left. Look at that still before you build on it. If it's blurred mid-motion, shot 2 will start from a blur. That's why every shot in the plan ends on a clear, held moment.
When you go through the site API (more below), image inputs are passed as HTTPS URLs, so your pipeline needs somewhere to host the extracted frame before the next job is submitted.
Scripting jobs: async, idempotent, polite
For browser use, the generator on minimax h3 needs no API key. For scripts, we also run a site API that's available to verified customers with a payment history. It spends the same credits as the website. We won't paste the full reference here, since docs change and you should read the current version. These are the properties that shape your code:
It's asynchronous. You create a task (POST /api/v1/videos), poll its status (GET /api/v1/videos/{task_id}) until it reaches succeeded, then download the result. The docs suggest polling about every 5 seconds. Don't hammer it.
Creates should be idempotent. Send a unique Idempotency-Key header with every create. Repeating the same request with the same key returns the original task without charging credits twice. That's what makes retries safe. A good pattern is to derive the key from your plan, such as latte-demo-s02-v3, so a crashed script that restarts can't double-submit a shot.
Respect the default limits. As documented: 5 create requests per minute, 2 active video jobs per account, 60 status requests per minute, and up to 3 active API keys. With only two jobs in flight at once, a ten-shot sequence needs a small queue, not a Promise.all.
Downloads are private. The returned video_url is private, so download it with the same Bearer key. Don't hand it to a browser and expect it to load.
A create body, as shown in the docs, looks like this:
{ "model": "minimax-h3", "mode": "text-to-video", "prompt": "A cinematic product reveal with a slow camera move", "duration": 5, "aspect_ratio": "16:9", "resolution": "2K" } duration defaults to 5 if you leave it out. Image-to-video uses image_url, plus an optional last_frame_url, and reference mode accepts up to nine reference_image_urls. Note that the site's model value is minimax-h3, while the official MiniMax model ID is MiniMax-H3. Third-party identifiers often differ, so keep the model string in config.
Failure, cost, and the "success" state
Failed jobs vs. bad clips. On our site, a failed generation is recorded and its credits are supposed to be returned automatically. A clip that technically succeeded but looks wrong is not refunded. Your retry logic should tell the two apart: retry failures automatically, but route bad clips to a human.
Don't hard-code prices. Cost depends mainly on duration. Read the live pricing page rather than baking a credits-per-second number into your app. Accounts start with free credits, then move to a subscription or a one-time credit pack.
Check the file before you say "done." Native audio is part of the official description, but audio output can still vary by provider, prompt and language. If your UI promises a soundtrack, check that the downloaded file actually has an audio stream before you show a green checkmark. ffprobe will tell you in one line.
A pre-production checklist
Before you ship an integration, make sure you can answer yes to each of these:
- [ ] Durations are validated as integers from 4 to 15 before submit
- [ ] Nothing in the UI or copy promises a single clip longer than 15 s
- [ ] Every create sends a deterministic, unique
Idempotency-Key - [ ] A queue respects 2 active jobs and the per-minute limits
- [ ] Polling backs off at about 5 s, with a timeout
- [ ] Downloads use the Bearer key, and files are stored on your side
- [ ] Output is probed for resolution, duration and audio before it's marked successful
- [ ] Failed jobs and unwanted-but-successful clips take different paths
- [ ] Model ID and pricing come from config, not constants
- [ ] Auth, rate limits, safety behavior and file constraints were checked on a real paid test account
Most of the hard problems with AI video aren't about the model. They're about everything around it. Plan in shots, chain them on purpose, make every submit safe to repeat, and check the file before you call it finished.
— The minimax3 team
