Upload a file
POST /api/v1/agent/runs/uploads (multipart/form-data)
For media that isn't at a public URL: upload it first, then pass the returned
url in any *_url field of Start a video-agent run —
reference_image_urls, reference_video_urls, reference_audio_urls,
first_frame_url or last_frame_url. Upload one file per request.
| Form field | Required | Notes |
|---|---|---|
file |
yes | The image, video or audio file. |
kind |
no | image, video or audio. Inferred from the file's content type (or its extension, when the type is application/octet-stream) if left out. |
curl -X POST https://api.happypony.io/api/v1/agent/runs/uploads \
-H "Authorization: Bearer $HP_KEY" \
-F file=@selfie.png
{ "url": "https://…signed…", "kind": "image", "expires_in": 259200 }
The response is 201.
urlis a presigned link to your private copy, valid forexpires_inseconds (72 hours). Start the run before it expires; once the run is created the file is attached to it and the link no longer matters.- Accepted types: images
jpg/png/webp, videomp4/mov/webm/mkv, audiowav/mp3/m4a/aac/ogg/flac. - Size caps: image 20 MB, audio 30 MB, video 200 MB.
| Status | error |
When |
|---|---|---|
| 400 | invalid_request |
No multipart file field. |
| 400 | invalid_media |
code is bad_type (unsupported type, or not the kind you named) or too_large; field is file. |
| 401 | unauthorized |
Missing, wrong or revoked API key. |
| 502 | media_failed |
The file could not be stored. Retry. |
Two local images into one run:
up() { curl -s -X POST https://api.happypony.io/api/v1/agent/runs/uploads \
-H "Authorization: Bearer $HP_KEY" -F "file=@$1" | jq -r .url; }
A=$(up selfie3.png); B=$(up selfie4.png)
curl -X POST https://api.happypony.io/api/v1/agent/runs \
-H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
-d "{\"prompt\": \"The two girls have a bar fight\", \"reference_image_urls\": [\"$A\", \"$B\"], \"variants\": 2, \"feedback_loops\": 1}"
Start a video-agent run
Pricing: Video-agent runs
POST /api/v1/agent/runs
curl -X POST https://api.happypony.io/api/v1/agent/runs \
-H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
-d '{
"prompt": "A 15 second ad for this trail shoe: a runner at dawn, energetic, ends on the logo.",
"reference_image_urls": ["https://cdn.example.com/shoe-front.png", "https://cdn.example.com/shoe-side.png"],
"reference_audio_urls": ["https://cdn.example.com/voice.mp3"],
"hints": { "duration": 15, "aspect_ratio": "9:16", "short_edge": 768, "tier": "quality", "language": "en" },
"variants": 2,
"feedback_loops": 1
}'
{
"request_id": "6f1c…",
"status": "IN_QUEUE",
"status_url": "https://api.happypony.io/api/v1/agent/runs/6f1c…/status",
"response_url": "https://api.happypony.io/api/v1/agent/runs/6f1c…",
"cancel_url": "https://api.happypony.io/api/v1/agent/runs/6f1c…/cancel"
}
The response is 202. Unknown fields are rejected (400), so a typo never
silently changes what is rendered.
| Field | Type | Notes |
|---|---|---|
job |
video | character_swap | background_replace |
What the agent does. Default video. The other two take other fields and hints: see Character swap runs and Background replace runs. |
prompt |
string, required | Your instructions, up to 8000 characters. |
reference_image_urls |
string[] ≤ 9 | Subjects, products, style. Each can be its own reference (reference to video takes 9); several views of one subject may be collated into a reference sheet by the agent. |
reference_video_urls |
string[] ≤ 1 | Motion / identity reference. The render model takes one. |
reference_audio_urls |
string[] ≤ 3 | Voice / sound references. |
first_frame_url, last_frame_url |
string | Pin the opening / closing frame. |
hints.duration |
int 5–20 | Seconds. Fixed, unless the agent may adjust the length (below); then it is the preferred length. Must fit the canvas (resolution, aspect_ratio). |
hints.adjust_duration |
bool | Whether the agent may pick the length itself. Default true when duration_min or duration_max is given, otherwise false. |
hints.duration_min, hints.duration_max |
int 5–20 | The range the agent picks the length from. Default 5 and the longest the canvas allows. |
hints.aspect_ratio |
auto 21:9 16:9 4:3 1:1 3:4 9:16 |
|
hints.resolution |
480p 768p 1080p |
The video's short edge. 1080p is upscaled from the native render. |
hints.short_edge |
480 768 1080 |
The same setting in pixels. Send resolution or short_edge, not both. |
hints.tier |
turbo | quality |
Default quality. Every render in the run uses this tier; the agent never switches it. |
hints.language |
string | Language of speech and on-screen text. |
variants |
int 1–4, default 1 | Independent takes on the brief, each its own agent. |
feedback_loops |
int 0–3 | How many times a finished render may be reviewed and redone. Left out: as many as max_credits pays for when you set it; otherwise 1 for character_swap and background_replace, 0 for video. |
max_credits |
int 1–100000 | The most this run may spend, split evenly between variants. The agent works to get the best result within it and is refused anything over it. Left out, a default budget applies: see Video-agent runs pricing. 400 budget_too_low (with minimum) when it cannot hold one render per variant. Echoed on the create, status and result responses. |
uncensored |
bool, default false |
Run every variant on the uncensored model. Adds a surcharge per render: see Video-agent runs pricing. 400 uncensored_unavailable when this server does not offer it. Echoed as uncensored: true on the create, status and result responses. |
A hint you give is binding: the agent cannot override it. Anything you leave out, the agent chooses.
How long the videos are:
| You send | Each video is |
|---|---|
| nothing | the agent's choice, 5–15 s |
duration: 10 |
exactly 10 s |
duration_min: 8, duration_max: 15 |
whatever length the content needs, within 8–15 s |
duration: 10, duration_min: 8, duration_max: 15 |
within 8–15 s, 10 s preferred |
duration: 10, adjust_duration: true |
anywhere from 5 s to the longest the resolution and aspect ratio allow, 10 s preferred |
Setting duration_min or duration_max lets the agent adjust the length by
itself; sending them with adjust_duration: false is a 400.
With a range, the agent counts the shots, actions and spoken words in your prompt and picks the shortest length that tells it without rushing; the server keeps every render inside the range. The range's upper end is capped at what the canvas allows (15 s at 768p 16:9, 20 s at 480p).
Character swap runs
With "job": "character_swap" the agent swaps a person in your clip for a
character from a picture and keeps everything else (motion, voice,
background). It looks at the clip, picks who to replace, may make a character
sheet from a picture, writes a shot-by-shot description of the clip for the
whole-frame renderer (the default job), and, with feedback_loops, compares
the result with the source frame by frame and tries again, by fixing the
description first and only then falling back to the masked job.
curl -X POST https://api.happypony.io/api/v1/agent/runs \
-H "Authorization: Bearer $HP_KEY" -H "Content-Type: application/json" \
-d '{
"job": "character_swap",
"prompt": "Replace the dancer on the left; keep her red scarf.",
"reference_video_urls": ["https://cdn.example.com/dance.mp4"],
"reference_image_urls": ["https://cdn.example.com/hero.png"],
"hints": { "duration": 10, "keep_outfit": true },
"feedback_loops": 1
}'
| Field | Type | Notes |
|---|---|---|
reference_video_urls |
string[], exactly 1 | The source clip. |
reference_image_urls |
string[] 1–3 | One picture per person swapped in, in order. |
prompt |
string, optional | Who to swap and anything to keep. Without it the agent swaps the most prominent person for each picture. |
hints.duration |
int 1–20 | Seconds of the clip to process. Default: the clip's length, up to 20. |
hints.resolution |
480 | 600 | 704 | 768 (480p / 600p / 704p / 768p accepted) |
Render resolution. Default 480. 768 (small faces, reflections) needs hints.duration ≤ 15, and is the only way the agent may propose a 768 swap: without it a 768 swap is over the run's per-video budget. |
hints.lipsync |
auto | on | off |
Fixes lip sync for every swap. auto (the default) pins the mouth to the source audio when the clip has some; off for singing or dubbed clips. |
hints.mode |
regen | masked (nomask / sequential accepted) |
As in Character swap. Default: the agent's choice, regen first and masked as a repair. |
hints.mask |
object | Fixes the mask for every swap, replacing the agent's own: the mask levers (expand, temporal, largest, cuts, shots, detect_time, frames, subtract, boxes). Makes every swap a masked job, so hints.mode regen with it is a 400. Default: the agent tunes the mask itself. |
hints.keep_outfit |
boolean | true: every swapped-in character keeps the clothes of the clip (only face, hair and identity come from the picture); false: they wear the clothes of their picture. Default: the agent decides from your prompt and the pictures. |
hints.seed |
integer | Pins the seed of every swap. |
hints.swap_strength |
number: 0, or 0.5–2.0 | Pins the swap strength (0 turns the swap LoRA off). Default: the agent's choice, starting from the job's default (1.0 on regen, 1.6 on masked). |
hints.language |
string | Language of the agent's messages in the log. The clip description is always Simplified Chinese and masked prompts always English. |
first_frame_url, last_frame_url, reference_audio_urls and the video
hints (aspect_ratio, short_edge, tier, adjust_duration,
duration_min, duration_max) are a 400 on a swap run, and the swap hints
(mode, seed, swap_strength, lipsync, mask, keep_outfit) are a 400 on a video run.
A result's parameters show the swap's mode, swap_strength,
resolution, duration, seed and, when set, the description the agent
wrote, instruction (your words, when the renderer wrote the description),
keep_outfit, prompts, targets, sam_text, mask, window_prompts,
window, reference_background, lipsync and paste_back. The review of a
whole-frame swap also looks at the middle of every shot the description lists,
so a short shot without the replaced person is checked.
When it falls back to the masked job for a tricky swap (several people,
mirrors, an object in front of the face, a person who leaves the frame) the
agent may first ask for a mask preview: a dry run that shows which pixels would be
swapped, with per-frame coverage, in seconds. It reads the
preview, adjusts the mask and then renders. A preview is not a render: it does
not use up a feedback loop, is not reviewed, never appears under videos and
is never final. At most two per variant; a third is refused. While one runs,
the variant's status has previewing_mask: true, and mask_previews counts
those made.
Background replace runs
With "job": "background_replace" the agent keeps the people in your clip
exactly as they are, with their voices, and replaces everything around them.
Anything the people hold or use (a cup, a book, a ball, a chair) is kept with
them. The agent looks at the clip, uses your plate or makes one, previews the
mask when someone touches an object or the clip is tricky, then renders. It
compares the result frame by frame with the source and tries again while
feedback_loops and your budget allow: by default one retry.
curl -X POST https://api.happypony.io/api/v1/agent/runs \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"job": "background_replace",
"prompt": "A rainy neon street in Tokyo at night",
"reference_video_urls": ["https://example.com/clip.mp4"],
"feedback_loops": 1
}'
| Field | Type | Description |
|---|---|---|
reference_video_urls |
string[] | Required. Exactly one: the clip. |
reference_image_urls |
string[] | At most one: the plate, an image of the empty new scene. Without it the agent makes a plate from prompt. |
prompt |
string | The new scene and anything else to respect. Required unless a plate is given. |
hints.duration |
integer | Seconds processed from the start of the clip, 1 to 20 (15 at 768). Default: the clip's length. |
hints.resolution |
480 | 768 |
Default 480. |
hints.variant |
auto | M | R |
Default: the agent's choice. See Background replace. |
hints.seed |
integer | Fixes the seed. |
hints.keep |
object | Fixes what is kept, as keep in Background replace. Default: the agent's choice. |
hints.lipsync |
boolean | Pins the audio rows to the source audio. |
hints.language |
string | Language of the agent's messages. |
max_credits |
integer | The most this run may spend. Default and details: Video-agent runs pricing. |
reference_audio_urls, first_frame_url, last_frame_url and every other
hint are a 400 on this job.
A result's parameters show title, scene, people, prompt, variant,
keep, resolution, upscale, paste_back, grade, lipsync, duration
and seed, each when set. Mask previews work as in
Character swap runs: at most two per variant, never
under videos.
Media URLs
Files you uploaded are passed the same way, by their URL.
Each URL is downloaded when the run is created and stored as a private
attachment, so a bad URL fails the request (400 invalid_media, naming the
field) instead of a run later. The rules:
https://only, default port, no credentials in the URL.- The host must resolve to public addresses only (loopback, private, link-local, carrier-NAT and multicast ranges are refused, including after redirects). Up to 3 redirects, each re-checked.
- Content type must match the field: images
jpg/png/webp, videomp4/mov/webm/mkv, audiowav/mp3/m4a/aac/ogg/flac.application/octet-streamis accepted when the file extension says so. - Size caps: image 20 MB, audio 30 MB, video 200 MB. Timeouts: 30 s / 45 s / 120 s.
Limits
- Balance. A run whose quote is above your balance is
402 insufficient_credits, withrequiredandavailable. How the quote is worked out is in Video-agent runs pricing. - Duration and size. The agent will not propose a video longer or larger than the hints it was budgeted for: give
hints.duration/resolutionfor longer or larger videos. - Concurrency. At most 3 active (
IN_QUEUE/IN_PROGRESS) runs per user; the fourth is429 too_many_runs.
Poll for status
GET /api/v1/agent/runs/:id/status
{
"request_id": "6f1c…",
"status": "IN_PROGRESS",
"phase": "rendering",
"created_at": "2026-09-28T10:00:00.000Z",
"started_at": "2026-09-28T10:00:03.000Z",
"completed_at": null,
"variants": [
{ "variant": 1, "state": "running", "phase": "rendering", "iteration": 1, "max_iterations": 2,
"renders_finished": 0, "render_status": "pending", "queue_position": 3, "eta_seconds": 240 },
{ "variant": 2, "state": "running", "phase": "analysing", "iteration": 0, "max_iterations": 2, "renders_finished": 0 }
],
"credits_used": 60,
"quoted_credits": 240,
"queue_position": 3,
"eta_seconds": 240,
"status_url": "…", "response_url": "…", "cancel_url": "…"
}
status uses the batch queue's names:
| Status | Meaning |
|---|---|
IN_QUEUE |
Accepted, not yet picked up by the agent runner. |
IN_PROGRESS |
The agent is working (see phase). |
COMPLETED |
Every variant that could finish has a final video. A variant that failed is listed in variant_errors; the run is still COMPLETED if at least one variant has a video. |
FAILED |
No variant produced a video. error says why. |
CANCELLED |
Cancelled by you. |
phase (run level: the most advanced running variant; null once finished):
| Phase | Meaning |
|---|---|
analysing |
The agent reads your material and writes a plan. |
planning |
The plan is being priced and submitted. |
rendering |
A render is queued or running. queue_position and eta_seconds come from the render queue. |
reviewing |
Frames of a finished render are being checked against your instructions. |
revising |
The agent is rewriting the plan after a review (or a content-check refusal). |
Per variant, iteration counts renders started and max_iterations is
feedback_loops + 1. state is running, done or failed.
On a character swap run a variant also carries
previewing_mask: true while a mask preview (a dry run) is in progress and
mask_previews, how many it has made; previews do not count in iteration
or renders_finished, and credits_used includes them and any character
sheets as soon as they are charged.
Polling every 10–30 s is plenty; there are no webhooks.
Get the result
GET /api/v1/agent/runs/:id
{
"request_id": "6f1c…",
"status": "COMPLETED",
"videos": [
{ "variant": 1, "iteration": 1, "final": false, "url": "https://…signed…", "activity_id": 812,
"credits": 120,
"parameters": { "title": "Trail shoe dawn run", "mode": "from references", "tier": "quality", "duration": 15,
"short_edge": 768, "aspect_ratio": "9:16", "inputs": "reference images img1, img2", "seed": 1804289383,
"brief": "A runner laces the shoe at dawn, then…" },
"prompt_used": "…",
"review": { "satisfied": false, "summary": "The shoe is not visible in the last shot.", "issues": ["logo missing"], "revision": "end on a close-up of the logo" } },
{ "variant": 1, "iteration": 2, "final": true, "url": "https://…signed…", "activity_id": 815,
"credits": 120, "parameters": { "…": "…" }, "prompt_used": "…" }
],
"total_credits": 240,
"variant_errors": [{ "variant": 2, "error": "the content check refused every plan (minor): …" }],
"log": [
{ "at": "2026-09-28T10:00:03.100Z", "kind": "run", "message": "Run started", "data": { "variants": 2, "feedback_loops": 1 } },
{ "at": "2026-09-28T10:00:20.400Z", "variant": 1, "kind": "plan", "message": "Proposed \"Trail shoe dawn run\" (120 credits)", "data": { "credits": 120, "settings": { }, "prompt": "…" } }
]
}
videoshas one entry per finished render.final: truemarks the render the run delivers for that variant: the one that satisfied the review, or the last one when the loops ran out (or when a later render failed). Usefinal, not the order.urlis a presigned download link, valid for 72 hours. Only the link expires, not the file: fetch the run again at any time for a fresh one.creditsis what that render cost;total_creditsis the run's total after refunds.parametersare the settings the render was submitted with, as the agent chose them (within yourhints):mode(text to video,from framesorfrom references),tier,duration(seconds),short_edge(pixels) andresolution(e.g.480p),aspect_ratio,inputs(which of your files it used, by label:img1is your first image),seed, andbrief, the agent's plan in plain words.prompt_usedis the full prompt the renderer received.- On a character swap run
parametersare the swap's instead:title,mode,swap_strength,resolution,duration,pictures(how many),seedand, when the agent set them,description,instruction,keep_outfit,prompts,targets,sam_text,mask,window_prompts,window,reference_background,lipsyncandpaste_back.prompt_usedis the description (as JSON) of a whole-frame swap, the prompts of a masked one. The character sheets and mask previews it made are not undervideos; their cost is intotal_credits, and the log shows previews asjobentries (Mask preview submitted/Mask preview ready) and sheets in the agent's ownagentmessages. reviewis present when that render was reviewed. The review sees sampled frames, not the audio. On a character swap run it compares the result's frames with the source clip's: identity, pose, mouth and everything outside the swap.logis every step in order, each{at, variant?, iteration?, kind, message, data?}. Kinds:run,phase,input,agent,plan,job,review,variant,cancel,error. It never contains signed URLs, the agent's system prompt or its private reasoning.
While a run is in progress the same endpoint returns the videos finished so far.
Runs also appear in the video agent's chat history on happypony.io, marked API: one read-only chat per run, with your instructions and each video's plan, render and review in order.
Cancel
PUT /api/v1/agent/runs/:id/cancel
{ "request_id": "6f1c…", "status": "CANCELLED", "renders_cancelled": 1, "renders_still_running": 0 }
The run stops within seconds. Renders still waiting in the render queue are
cancelled there and refunded. A render a worker has already started cannot be
stopped: it finishes, its credits stay spent, and it does not appear in the
run's videos. Cancelling a run that already finished is 409 not_cancellable.
Errors
| Status | error |
When |
|---|---|---|
| 400 | invalid_request |
Bad JSON, unknown field, out-of-range value. details lists every problem. |
| 400 | invalid_media |
A URL was refused or could not be downloaded. field names it, code is blocked, invalid_url, unreachable, too_large, bad_type or http_error. |
| 401 | unauthorized |
Missing, wrong or revoked API key. |
| 402 | insufficient_credits |
Balance below the worst case. Has required and available. |
| 404 | not_found |
No such run, or it is not yours. |
| 409 | not_cancellable |
The run is already finished. |
| 429 | too_many_runs |
Three runs are already active. |
| 502 | media_failed |
The media could not be stored. Retry. |
How a run works
- The request is validated, quoted and its media stored. Each variant gets its own private agent conversation (never shown in the chat history) starting from your instructions.
- A runner process claims the run (with a lease it keeps renewing, so a restart or another replica picks it up where it stopped, without submitting a render twice), and drives every variant in parallel: the agent analyses the material and proposes a video; the proposal is confirmed automatically at the quoted price and submitted to the render queue. On a character swap run the agent first inspects the clip's frames, may build a character sheet from a picture or check a mask preview, and then proposes the swap.
- When a render finishes and loops remain, sampled frames plus your instructions and the prompt go to the vision model for a structured critique. If it is satisfied the variant is done; otherwise the agent revises and proposes again.
- A content-check refusal is fed back to the agent, which revises the plan (up to 3 times per variant). Any other hard failure ends that variant only.