Video-agent quick start
Pricing: Video-agent runs
The example below is a complete run: two reference images, one prompt, two
independent takes (variants: 2), each reviewed and redone once
(feedback_loops: 1). You need curl and jq; the full examples
at the end of this section do the same in Python, TypeScript and Node.js.
1. Get an API key
Create a key at www.happypony.io → API Keys and export it. The full key is shown once.
export HP_KEY=hp_…
2. Your images
Reference images are passed by URL. Either:
Use any public
https://image URL as it is. These two long-lived samples work right now:https://resource.pipelet.net/images/test/selfie3.pnghttps://resource.pipelet.net/images/test/selfie5.png
Or upload a local file and use the URL it returns:
curl -X POST https://api.happypony.io/api/v1/agent/runs/uploads \ -H "Authorization: Bearer $HP_KEY" -F file=@me.png # → {"url":"https://…signed…","kind":"image","expires_in":259200}That
urlis a presigned link, private to you and valid for 72 hours. It only has to be valid until you start the run: the file is copied into the run at that moment, so it does not matter that the link expires later.
3. Start the video-agent run
RUN=$(curl -s -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": [
"https://resource.pipelet.net/images/test/selfie3.png",
"https://resource.pipelet.net/images/test/selfie5.png"
],
"variants": 2,
"feedback_loops": 1
}')
echo "$RUN"
STATUS_URL=$(jq -r .status_url <<<"$RUN"); RESPONSE_URL=$(jq -r .response_url <<<"$RUN")
The 202 response carries request_id, status_url, response_url and
cancel_url. Use the last three as they are.
4. Poll the status
Every 15 seconds or so, until status is COMPLETED, FAILED or CANCELLED
(a run takes several minutes):
curl -s -H "Authorization: Bearer $HP_KEY" "$STATUS_URL" | jq '{status, phase, credits_used}'
5. Get the result and download the videos
curl -s -H "Authorization: Bearer $HP_KEY" "$RESPONSE_URL" > result.json
jq -r '.videos[] | select(.final) | "\(.variant) \(.url)"' result.json |
while read -r v url; do curl -s -o "video-$v.mp4" "$url"; done
videos[].final marks the render delivered for each variant; total_credits
is what the run cost. The video urls are presigned for 72 hours: to download
later, fetch response_url again for fresh links.
Full examples
Each one reads the key from HP_KEY, starts the run above, polls every 15
seconds, prints the credits and saves every video. upload() is only needed for
a local file: pass its result in reference_image_urls instead of a sample URL.
curl (bash)
#!/usr/bin/env bash
# Needs curl and jq. Usage: HP_KEY=hp_… ./run.sh
set -euo pipefail
API=https://api.happypony.io/api/v1/agent/runs
AUTH="Authorization: Bearer $HP_KEY"
call() { # prints the body; on an HTTP error prints it to stderr and fails
local out code body
out=$(curl -sS -w '\n%{http_code}' -H "$AUTH" "$@")
code=${out##*$'\n'}; body=${out%$'\n'*}
[[ $code == 2* ]] || { echo "HTTP $code: $body" >&2; return 1; }
echo "$body"
}
upload() { call -X POST "$API/uploads" -F "file=@$1" | jq -r .url; } # optional: local file → URL
RUN=$(call -X POST "$API" -H 'Content-Type: application/json' -d '{
"prompt": "The two girls have a bar fight",
"reference_image_urls": [
"https://resource.pipelet.net/images/test/selfie3.png",
"https://resource.pipelet.net/images/test/selfie5.png"],
"variants": 2, "feedback_loops": 1}')
STATUS_URL=$(jq -r .status_url <<<"$RUN"); RESPONSE_URL=$(jq -r .response_url <<<"$RUN")
while :; do
STATUS=$(call "$STATUS_URL" | jq -r .status); echo "status: $STATUS"
case $STATUS in COMPLETED|FAILED|CANCELLED) break ;; esac
sleep 15
done
call "$RESPONSE_URL" > result.json
echo "total credits: $(jq .total_credits result.json)"
jq -r '.videos[] | "\(.variant) \(.iteration) \(.final) \(.url)"' result.json |
while read -r v i final url; do
curl -sS --fail -o "video-v$v-i$i.mp4" "$url" && echo "saved video-v$v-i$i.mp4 (final=$final)"
done
Python
# pip install requests | HP_KEY=hp_… python run.py
import os, sys, time, requests
API = "https://api.happypony.io/api/v1/agent/runs"
HEADERS = {"Authorization": f"Bearer {os.environ['HP_KEY']}"}
def check(r: requests.Response) -> dict:
if not r.ok:
sys.exit(f"HTTP {r.status_code}: {r.text}")
return r.json()
def upload(path: str) -> str: # optional: local file -> presigned URL (valid 2 h)
with open(path, "rb") as f:
return check(requests.post(f"{API}/uploads", headers=HEADERS, files={"file": f}))["url"]
run = check(requests.post(API, headers=HEADERS, json={
"prompt": "The two girls have a bar fight",
"reference_image_urls": [
"https://resource.pipelet.net/images/test/selfie3.png",
"https://resource.pipelet.net/images/test/selfie5.png",
],
"variants": 2,
"feedback_loops": 1,
}))
while True:
status = check(requests.get(run["status_url"], headers=HEADERS))["status"]
print("status:", status)
if status in ("COMPLETED", "FAILED", "CANCELLED"):
break
time.sleep(15)
result = check(requests.get(run["response_url"], headers=HEADERS))
print("total credits:", result["total_credits"])
for v in result["videos"]:
name = f"video-v{v['variant']}-i{v['iteration']}.mp4"
r = requests.get(v["url"]) # presigned: no auth header
r.raise_for_status()
open(name, "wb").write(r.content)
print("saved", name, "final" if v["final"] else "")
TypeScript
// Node 18+ (or Deno/Bun). Run with: HP_KEY=hp_… npx tsx run.ts
import { readFile, writeFile } from "node:fs/promises";
import { basename } from "node:path";
const API = "https://api.happypony.io/api/v1/agent/runs";
const AUTH = { Authorization: `Bearer ${process.env.HP_KEY}` };
interface Created { request_id: string; status_url: string; response_url: string; cancel_url: string }
type Status = "IN_QUEUE" | "IN_PROGRESS" | "COMPLETED" | "FAILED" | "CANCELLED";
interface Video { variant: number; iteration: number; final: boolean; url: string; credits: number; prompt_used: string }
interface Result { status: Status; videos: Video[]; total_credits: number }
async function call<T>(url: string, init: RequestInit = {}): Promise<T> {
const res = await fetch(url, { ...init, headers: { ...AUTH, ...init.headers } });
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
return (await res.json()) as T;
}
// Optional: upload a local file, get a presigned URL (valid 2 h) for reference_image_urls.
async function upload(path: string): Promise<string> {
const form = new FormData();
form.append("file", new Blob([await readFile(path)]), basename(path));
return (await call<{ url: string }>(`${API}/uploads`, { method: "POST", body: form })).url;
}
const run = await call<Created>(API, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
prompt: "The two girls have a bar fight",
reference_image_urls: [
"https://resource.pipelet.net/images/test/selfie3.png",
"https://resource.pipelet.net/images/test/selfie5.png",
],
variants: 2,
feedback_loops: 1,
}),
});
let status: Status;
do {
status = (await call<{ status: Status }>(run.status_url)).status;
console.log("status:", status);
if (["COMPLETED", "FAILED", "CANCELLED"].includes(status)) break;
await new Promise((r) => setTimeout(r, 15_000));
} while (true);
const result = await call<Result>(run.response_url);
console.log("total credits:", result.total_credits);
for (const v of result.videos) {
const name = `video-v${v.variant}-i${v.iteration}.mp4`;
const res = await fetch(v.url); // presigned: no auth header
if (!res.ok) throw new Error(`download failed: HTTP ${res.status}`);
await writeFile(name, Buffer.from(await res.arrayBuffer()));
console.log("saved", name, v.final ? "(final)" : "");
}
Node.js
// Node 18+ (built-in fetch / FormData / Blob). Save as run.mjs: HP_KEY=hp_… node run.mjs
import { readFileSync, writeFileSync } from "node:fs";
import { basename } from "node:path";
const API = "https://api.happypony.io/api/v1/agent/runs";
const AUTH = { Authorization: `Bearer ${process.env.HP_KEY}` };
async function call(url, init = {}) {
const res = await fetch(url, { ...init, headers: { ...AUTH, ...init.headers } });
if (!res.ok) throw new Error(`HTTP ${res.status}: ${await res.text()}`);
return res.json();
}
// Optional: upload a local file, get a presigned URL (valid 2 h) for reference_image_urls.
async function upload(path) {
const form = new FormData();
form.append("file", new Blob([readFileSync(path)]), basename(path));
return (await call(`${API}/uploads`, { method: "POST", body: form })).url;
}
const run = await call(API, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
prompt: "The two girls have a bar fight",
reference_image_urls: [
"https://resource.pipelet.net/images/test/selfie3.png",
"https://resource.pipelet.net/images/test/selfie5.png",
],
variants: 2,
feedback_loops: 1,
}),
});
let status;
while (true) {
({ status } = await call(run.status_url));
console.log("status:", status);
if (["COMPLETED", "FAILED", "CANCELLED"].includes(status)) break;
await new Promise((r) => setTimeout(r, 15_000));
}
const result = await call(run.response_url);
console.log("total credits:", result.total_credits);
for (const v of result.videos) {
const name = `video-v${v.variant}-i${v.iteration}.mp4`;
const res = await fetch(v.url); // presigned: no auth header
if (!res.ok) throw new Error(`download failed: HTTP ${res.status}`);
writeFileSync(name, Buffer.from(await res.arrayBuffer()));
console.log("saved", name, v.final ? "(final)" : "");
}