---
name: h3gen-video
description: Generate MiniMax H3 videos (text-to-video, image-to-video with first/last frame, omni reference with images, videos and audio; 480p–2K, 4–30 s, native sound) and H3-Image 4K images through the H3Gen API. Use when the user asks to create, animate or render a video or image with MiniMax H3 / H3Gen, turn a photo into a video, or make a clip from reference images, clips or a song.
license: Proprietary. Use with an H3Gen account (https://h3gen.io).
compatibility: Needs Node.js 18+ and network access to https://h3gen.io. Requires the H3GEN_API_KEY environment variable (create a key at https://h3gen.io/settings/apikeys).
metadata:
  homepage: https://h3gen.io
  api: https://h3gen.io/openapi.json
  version: "1.0.0"
---

# H3Gen video & image generation

Generations spend the user's H3Gen credits. Failed tasks are refunded automatically.

## Before you start

1. Check `H3GEN_API_KEY` is set. If not, ask the user to create a key at https://h3gen.io/settings/apikeys and export it. Never print the key.
2. Run `node scripts/h3gen.mjs account` to see the credit balance. `api_access: false` means the account needs a credit pack or subscription (https://h3gen.io/pricing).

## Workflow

1. **Media first.** Frames and references must be H3Gen-hosted:
   - local file: `node scripts/h3gen.mjs upload ./photo.png`
   - public link: `node scripts/h3gen.mjs import https://example.com/photo.png`
   Use the returned `url` in the request.
2. **Estimate, then confirm.** `node scripts/h3gen.mjs estimate '<json>'`. Tell the user the credit cost and get a yes before spending, unless they already set a budget. Always pass `max_credits` and a fresh `client_request_id` (any unique string) when spending: retrying with the same id returns the original tasks instead of charging again.
3. **Start.** `node scripts/h3gen.mjs video '<json>'` or `node scripts/h3gen.mjs image '<json>'`. Returns task ids.
4. **Wait.** `node scripts/h3gen.mjs wait <task_id>` polls until the task succeeds or fails (videos take 1–5 minutes). Never resubmit while a task is running.
5. **Deliver.** `node scripts/h3gen.mjs download <task_id> ./out.mp4`, or give the user `output.url` (valid 24 hours).

## Video request (`video` / `estimate`)

| field | values |
|---|---|
| `prompt` | required. Subject, action, camera move, lighting, sound. |
| `resolution` | `480p` `768p` `1080p` `2k` (default `2k`) |
| `duration` | 4–30 seconds (2k max 15; above 15 s costs 2×). Default 5. |
| `ratio` | `16:9` `9:16` `1:1` `4:3` `3:4` `21:9` (text / reference mode) |
| `image`, `image_end` | first frame (+ optional last frame) for image-to-video |
| `image_task_id` | use a finished `image` task of this account as the first frame |
| `ref_images` | ≤ 9 reference images (beyond 5 cost 1 credit each) |
| `ref_videos` | ≤ 3 clips, 2–15 s each, ≤ 15 s total; their seconds are billed |
| `ref_audios` | ≤ 3 audio clips (MP3/WAV), e.g. a song for a music video |
| `count` | 1–4 videos, each billed |
| `prompt_optimizer` | `true` lets the model expand the prompt (+1 credit) |
| `max_credits` | refuse instead of charging above this |
| `client_request_id` | unique id; a retry with the same id is not charged again |

Frames work with `ref_images`, but not with `ref_videos` / `ref_audios`.

Credits per second: 480p 4 · 768p 6 · 1080p 8 · 2k 10. Run `node scripts/h3gen.mjs models` for the live price table.

## Image request (`image`)

`prompt` (required), `resolution` `1k` `2k` `4k` (8 / 12 / 24 credits), `ratio` `1:1` `16:9` `9:16` `4:3` `3:4` `3:2` `2:3` `21:9`, `ref_images` (≤ 3, to edit or combine; the third costs 2 credits more), `max_credits`, `client_request_id`. Estimate with `{"type":"image",...}`. To animate a result, pass its task id as `image_task_id` in a video request.

## Examples

```bash
# text to video, 768p, 6 s
node scripts/h3gen.mjs estimate '{"prompt":"A street violinist at dusk, slow push-in, crowd murmur","resolution":"768p","duration":6}'
node scripts/h3gen.mjs video '{"prompt":"A street violinist at dusk, slow push-in, crowd murmur","resolution":"768p","duration":6,"max_credits":40}'

# photo to video
node scripts/h3gen.mjs upload ./product.jpg
node scripts/h3gen.mjs video '{"prompt":"The bottle rotates on wet stone, rain, macro lens","image":"<url>","resolution":"1080p","duration":5,"max_credits":45}'

# song + cover art to a music video
node scripts/h3gen.mjs upload ./chorus.mp3
node scripts/h3gen.mjs upload ./cover.png
node scripts/h3gen.mjs video '{"prompt":"The singer from the cover performs the chorus on a neon rooftop, lip-synced","ref_images":["<cover url>"],"ref_audios":["<mp3 url>"],"ratio":"9:16","resolution":"1080p","duration":10,"max_credits":90}'
```

## Prompt tips

Write one shot: who/what, the action over time, the camera (push-in, orbit, handheld, crane), lens and light, then the sound (dialogue in quotes, ambience, music). Name the references as "the woman in image 1", "the motion of the reference clip".

## Errors

- `401`: missing or revoked key.
- `402 payment_required`: no credit pack or subscription yet.
- `402 insufficient_credits`: top up at https://h3gen.io/pricing.
- `400`: fix the field named in the message.
- `429`: slow down and retry.
- A failed task: credits already refunded. Adjust the prompt or inputs, then try again.
