Happy Pony API Get an API key →

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:

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)" : "");
}

video-agent 快速开始

价格:video-agent run

下面的示例是一次完整的 run:两张参考图、一条提示词、两个相互独立的版本(variants: 2),每个版本审查后最多重做一次(feedback_loops: 1)。你需要 curl 和 jq;本节末尾的完整示例用 Python、TypeScript 和 Node.js 做了同样的事。

1. 获取 API key

在 www.happypony.io → API Keys 创建 key 并导出为环境变量。完整的 key 只显示一次。

export HP_KEY=hp_…

2. 准备图片

参考图通过 URL 传入。两种方式任选:

3. 发起 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")

202 响应包含 request_id、status_url、response_url 和 cancel_url。后三个 URL 直接原样使用即可。

4. 轮询状态

大约每 15 秒一次,直到 status 变为 COMPLETED、FAILED 或 CANCELLED(一次 run 需要几分钟):

curl -s -H "Authorization: Bearer $HP_KEY" "$STATUS_URL" | jq '{status, phase, credits_used}'

5. 获取结果并下载视频

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 标记每个版本最终交付的那次渲染;total_credits 是这次 run 的花费。视频 url 的预签名有效期为 72 小时:如需稍后下载,请重新请求 response_url 获取新的链接。

完整示例

每个示例都从 HP_KEY 读取 key,发起上面的 run,每 15 秒轮询一次,打印积分并保存所有视频。upload() 仅在使用本地文件时需要:把它的返回值放进 reference_image_urls,代替示例 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)" : "");
}