Happy Pony API Get an API key →

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.

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:

Limits

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": "…" } }
  ]
}

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

  1. 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.
  2. 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.
  3. 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.
  4. 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.

上传文件

POST /api/v1/agent/runs/uploads(multipart/form-data)

适用于没有公开 URL 的媒体:先上传,再把返回的 url 填入发起 video-agent run 的任一 *_url 字段:reference_image_urls、reference_video_urls、reference_audio_urls、first_frame_url 或 last_frame_url。每次请求上传一个文件。

表单字段 是否必填 说明
file 是 图片、视频或音频文件。
kind 否 image、video 或 audio。省略时根据文件的 content type 推断(content type 为 application/octet-stream 时根据扩展名推断)。
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 }

响应状态码为 201。

状态码 error 触发条件
400 invalid_request 没有 multipart file 字段。
400 invalid_media code 为 bad_type(类型不支持,或与你指定的 kind 不符)或 too_large;field 为 file。
401 unauthorized 缺少、错误或已吊销的 API key。
502 media_failed 文件无法保存。请重试。

把两张本地图片放进同一次 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}"

发起 video-agent run

价格:video-agent run

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"
}

响应状态码为 202。未知字段会被拒绝(400),因此拼写错误不会悄悄改变渲染内容。

字段 类型 说明
job video | character_swap | background_replace agent 要做的事。默认 video。后两者使用不同的字段和 hint,见角色替换 run和换背景 run。
prompt string,必填 你的指令,最多 8000 个字符。
reference_image_urls string[] ≤ 9 主体、产品、风格。每张都可以单独作为参考(参考生视频最多接受 9 张);同一主体的多个视角可能会被 agent 拼成参考图板。
reference_video_urls string[] ≤ 1 动作 / 身份参考。渲染模型只接受一个。
reference_audio_urls string[] ≤ 3 声音 / 音效参考。
first_frame_url, last_frame_url string 固定开场 / 结尾画面。
hints.duration int 5–20 秒。固定时长;若允许 agent 调整时长(见下文),则为首选时长。必须与画布(resolution、aspect_ratio)匹配。
hints.adjust_duration bool 是否允许 agent 自行决定时长。给出 duration_min 或 duration_max 时默认为 true,否则为 false。
hints.duration_min, hints.duration_max int 5–20 agent 选择时长的范围。默认为 5 秒到画布允许的最长时长。
hints.aspect_ratio auto 21:9 16:9 4:3 1:1 3:4 9:16
hints.resolution 480p 768p 1080p 视频的短边。1080p 由原生渲染放大得到。
hints.short_edge 480 768 1080 同一设置,以像素表示。resolution 与 short_edge 二选一。
hints.tier turbo | quality 默认 quality。run 中的所有渲染都使用该档位,agent 不会切换。
hints.language string 语音和画面文字的语言。
variants int 1–4,默认 1 对同一需求相互独立的多个版本,每个版本由各自的 agent 负责。
feedback_loops int 0–3 一次完成的渲染最多可以被审查并重做几次。未提供时:若设置了 max_credits,次数由预算决定;否则 character_swap 和 background_replace 为 1,视频为 0。
max_credits int 1–100000 本次 run 最多可花费的积分,在各 variants 间平均分配。agent 会在此预算内争取最好的结果,超出的花费会被拒绝。未提供时使用默认预算:见 video-agent run 价格。预算不足以让每个版本渲染一次时返回 400 budget_too_low(含 minimum)。创建、状态和结果响应中会返回该值。
uncensored bool,默认 false 所有 variant 使用无审查模型。每次渲染有附加费:见 video-agent run 价格。服务器未提供该模型时返回 400 uncensored_unavailable。创建、状态和结果响应中会回显 uncensored: true。

你给出的 hint 具有约束力:agent 无法覆盖。没有给出的部分由 agent 自行决定。

视频时长:

你发送 每个视频的时长
不发送 由 agent 决定,5–15 秒
duration: 10 正好 10 秒
duration_min: 8, duration_max: 15 在 8–15 秒内,按内容所需
duration: 10, duration_min: 8, duration_max: 15 在 8–15 秒内,首选 10 秒
duration: 10, adjust_duration: true 5 秒到该分辨率和宽高比允许的最长时长,首选 10 秒

设置 duration_min 或 duration_max 即允许 agent 自行调整时长;同时发送 adjust_duration: false 会返回 400。

给出范围时,agent 会统计提示词中的镜头、动作和台词字数,选择不显仓促的最短时长;服务器保证每次渲染都在该范围内。范围上限不超过画布允许的时长(768p 16:9 为 15 秒,480p 为 20 秒)。余额预检按范围上限计价。

角色替换 run

使用 "job": "character_swap" 时,agent 会把视频中的人换成图片中的角色,其余一切(动作、声音、背景)保持不变。它会先查看视频、选出要替换的人,可能用图片制作角色设定图,再为整帧重绘渲染器(默认任务)写出逐镜头的视频描述;设置 feedback_loops 时,它会逐帧对比结果与原视频并重试:先修正描述,仍不行时才改用遮罩任务。

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
  }'
字段 类型 说明
reference_video_urls string[],恰好 1 个 源视频。
reference_image_urls string[] 1–3 每个要换入的人一张图片,按顺序。
prompt string,可选 替换谁、要保留什么。不提供时,agent 为每张图片替换画面中最显眼的人。
hints.duration int 1–20 处理视频的秒数。默认为视频长度,最多 20 秒。
hints.resolution 480 | 600 | 704 | 768(也接受 480p / 600p / 704p / 768p) 渲染分辨率。默认 480。768(适合小脸、倒影)要求 hints.duration ≤ 15;只有提供它,agent 才能提出 768 的替换,否则 768 替换会超出 run 的单个视频预算。
hints.lipsync auto | on | off 固定每次替换的口型同步。auto(默认)在视频有声音时让口型对齐原声;唱歌或配音视频用 off。
hints.mode regen | masked(也接受 nomask / sequential) 含义同角色替换。默认由 agent 决定:先用 regen,masked 用于修复。
hints.mask object 固定每次替换的遮罩,取代 agent 自己的设置:即遮罩参数(expand、temporal、largest、cuts、shots、detect_time、frames、subtract、boxes)。设置后每次替换都是 masked 任务,因此与 hints.mode regen 同时提供会返回 400。默认由 agent 自行调整遮罩。
hints.keep_outfit boolean true:每个换入的角色都保留视频中的服装(只从图片中取脸、发型和身份);false:穿图片中的服装。默认由 agent 根据你的 prompt 和图片决定。
hints.seed integer 固定每次替换的 seed。
hints.swap_strength number:0,或 0.5–2.0 固定替换强度(0 关闭换脸 LoRA)。默认由 agent 决定,从任务的默认值开始(regen 为 1.0,masked 为 1.6)。
hints.language string 日志中 agent 消息的语言。视频描述始终为简体中文,遮罩任务的提示词始终为英文。

替换 run 不接受 first_frame_url、last_frame_url、reference_audio_urls 以及视频类 hint(aspect_ratio、short_edge、tier、adjust_duration、duration_min、duration_max),会返回 400;视频 run 不接受替换类 hint(mode、seed、swap_strength、lipsync、mask、keep_outfit),同样返回 400。

结果的 parameters 给出替换使用的 mode、swap_strength、resolution、duration、seed,以及设置了时 agent 写的 description、instruction(由渲染器写描述时你的原话)、keep_outfit、prompts、targets、sam_text、mask、window_prompts、window、reference_background、lipsync 和 paste_back。整帧替换的评审还会查看描述中每个镜头的中间帧,因此没有被替换者的短镜头也会被检查。

当 agent 为较难的替换(多人、镜子、脸前有物体、人物离开画面)改用遮罩任务时,可能先请求一次遮罩预览:一次试运行,显示哪些像素会被替换以及逐帧覆盖率,几秒完成。它会查看预览、调整遮罩,然后再渲染。预览不是渲染:不占用反馈轮次、不经过评审、不会出现在 videos 中,也永远不是 final。每个版本最多两次,第三次会被拒绝。预览进行中时,该版本的状态带有 previewing_mask: true,mask_previews 记录已做的次数。

换背景 run

使用 "job": "background_replace" 时,agent 会完整保留视频中的人物及其声音,并替换人物周围的一切。人物手持或使用的物品(杯子、书、球、椅子等)会和人物一起保留。它会先查看视频,使用你提供的背景图或自行制作一张,在有人接触物品或视频较复杂时预览遮罩,然后渲染。之后它会逐帧对比结果与原视频,并在 feedback_loops 和预算允许时重试:默认重试一次。

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
  }'
字段 类型 说明
reference_video_urls string[] 必填,恰好一个:源视频。
reference_image_urls string[] 最多一个:背景图,即空无一人的新场景图片。不提供时 agent 根据 prompt 制作。
prompt string 新场景及其他要求。除非提供了背景图,否则必填。
hints.duration integer 从视频开头起处理的秒数,1 到 20(768 时最多 15)。默认为视频长度。
hints.resolution 480 | 768 默认 480。
hints.variant auto | M | R 默认由 agent 决定。见换背景。
hints.seed integer 固定随机种子。
hints.keep object 固定保留内容,格式同换背景中的 keep。默认由 agent 决定。
hints.lipsync boolean 将音频行固定为原视频音频。
hints.language string agent 消息使用的语言。
max_credits integer 本次 run 最多可花费的积分。默认值及详情见 video-agent run 价格。

在此任务中,reference_audio_urls、first_frame_url、last_frame_url 及其他 hint 都会返回 400。

结果的 parameters 包含 title、scene、people、prompt、variant、keep、resolution、upscale、paste_back、grade、lipsync、duration 和 seed(设置时才出现)。遮罩预览的规则同角色替换 run:每个版本最多两次,不会出现在 videos 中。

媒体 URL

通过上传得到的文件也以 URL 的方式传入。每个 URL 都会在 run 创建时下载,并保存为私有附件,因此错误的 URL 会让请求当场失败(400 invalid_media,并指出字段),而不是等到 run 之后才出错。规则如下:

限制

轮询状态

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 沿用批处理队列的命名:

状态 含义
IN_QUEUE 已接受,尚未被 agent runner 领取。
IN_PROGRESS agent 正在工作(见 phase)。
COMPLETED 每个能够完成的版本都有了最终视频。失败的版本会列在 variant_errors 中;只要至少有一个版本产出了视频,run 仍然是 COMPLETED。
FAILED 没有任何版本产出视频。error 说明原因。
CANCELLED 已被你取消。

phase(run 级别:取进度最靠前的运行中版本;结束后为 null):

阶段 含义
analysing agent 阅读你的素材并撰写方案。
planning 方案正在定价并提交。
rendering 渲染已排队或正在运行。queue_position 和 eta_seconds 来自渲染队列。
reviewing 正在对照你的指令检查已完成渲染的画面。
revising agent 在审查(或内容检查被拒)后重写方案。

对每个版本而言,iteration 是已开始的渲染次数,max_iterations 为 feedback_loops + 1。state 为 running、done 或 failed。在角色替换 run 中,版本还带有 previewing_mask: true(遮罩预览即试运行进行中)和 mask_previews(已做的预览次数);预览不计入 iteration 和 renders_finished,而预览和角色设定图一经扣费就计入 credits_used。建议每 10–30 秒轮询一次;不提供 webhook。

获取结果

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": "…" } }
  ]
}

run 进行中时,同一接口返回目前已完成的视频。

run 也会出现在 happypony.io 视频 agent 的聊天历史中,标记为 API:每个 run 对应一个只读聊天,按顺序展示你的指令以及每个视频的方案、渲染和审查。

取消

PUT /api/v1/agent/runs/:id/cancel

{ "request_id": "6f1c…", "status": "CANCELLED", "renders_cancelled": 1, "renders_still_running": 0 }

run 会在几秒内停止。仍在渲染队列中等待的渲染会在队列中取消并退款。已被 worker 开始的渲染无法停止:它会跑完,积分不退,也不会出现在 run 的视频中。取消已经结束的 run 会返回 409 not_cancellable。

错误

状态码 error 触发条件
400 invalid_request JSON 格式错误、未知字段、取值越界。details 列出所有问题。
400 invalid_media URL 被拒绝或无法下载。field 指出字段,code 为 blocked、invalid_url、unreachable、too_large、bad_type 或 http_error。
401 unauthorized 缺少、错误或已吊销的 API key。
402 insufficient_credits 余额低于最坏花费。包含 required 和 available。
404 not_found 没有这个 run,或它不属于你。
409 not_cancellable run 已经结束。
429 too_many_runs 已有三个 run 处于活跃状态。
502 media_failed 媒体无法保存。请重试。

run 的工作原理

  1. 请求先经过校验、报价,媒体被保存。每个版本都有自己的私有 agent 对话(不会出现在聊天历史中),从你的指令开始。
  2. runner 进程领取 run(持有会不断续期的租约,因此重启或由其他副本接手时会从中断处继续,且不会重复提交渲染),并并行驱动每个版本:agent 分析素材并提出一个视频方案;方案按报价自动确认并提交到渲染队列。在角色替换 run 中,agent 会先查看视频画面,可能用图片制作角色设定图或检查一次遮罩预览,然后再提出替换方案。
  3. 渲染完成且还有剩余循环次数时,抽样画面连同你的指令和提示词会交给视觉模型做结构化评审。如果满意,该版本完成;否则 agent 修改后重新提出方案。
  4. 内容检查被拒的反馈会回传给 agent,由它修改方案(每个版本最多 3 次)。其他任何严重失败只会终止该版本。