Ad pack
Ad pack from one photo
One product photo and one line about it in, a pack of finished ads out: UGC photos, talking clips and store videos.
- From
- 299 crfor 4 ads
- Endpoint
POST /api/v1/studio/pack/runs- Workflow id
pack
Real outputs of this workflow.
The request
# 0. Upload your file first. Its id goes in the body.
MEDIA_ID=$(curl -s -X POST https://staglight.ai/api/v1/uploads \
-H "Authorization: Bearer $STAGLIGHT_API_KEY" -F file=@product.jpg | jq -r .id)
# 1. Price it. Free, nothing is charged.
PRICE=$(curl -s -X POST https://staglight.ai/api/v1/studio/pack/estimate \
-H "Authorization: Bearer $STAGLIGHT_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"product": {"media_id": "'"$MEDIA_ID"'", "description": "A vitamin C serum in a glass dropper bottle"},
"items": [
{"studio": "ugc_video", "card": "talk"},
{"studio": "ugc_fotos", "card": "ugc_mirror"},
{"studio": "wiggle", "card": "wiggle"},
{"studio": "ugc_fotos", "card": "ugc_kitchen"}
]
}' | jq .credits)
echo "$PRICE"
# 2. Start it. max_credits refuses anything above that price; the Idempotency-Key stops a double charge.
START=$(curl -s -X POST https://staglight.ai/api/v1/studio/pack/runs \
-H "Authorization: Bearer $STAGLIGHT_API_KEY" \
-H "Content-Type: application/json" \
-H "Idempotency-Key: $(uuidgen)" \
-d '{
"product": {"media_id": "'"$MEDIA_ID"'", "description": "A vitamin C serum in a glass dropper bottle"},
"items": [
{"studio": "ugc_video", "card": "talk"},
{"studio": "ugc_fotos", "card": "ugc_mirror"},
{"studio": "wiggle", "card": "wiggle"},
{"studio": "ugc_fotos", "card": "ugc_kitchen"}
],
"max_credits": '"$PRICE"'
}')
# 3. Wait until it finishes.
echo "$START" | jq -r '.runs[] | "\(.studio) \(.id)"' | while read S ID; do
while :; do
STATUS=$(curl -s "https://staglight.ai/api/v1/studio/$S/runs/$ID" -H "Authorization: Bearer $STAGLIGHT_API_KEY" | jq -r .status)
case "$STATUS" in succeeded|partial|failed) break ;; esac; sleep 10
done
# 4. Download every file in one zip.
curl -s -L -o "$ID.zip" "https://staglight.ai/api/v1/studio/$S/runs/$ID/outputs.zip" -H "Authorization: Bearer $STAGLIGHT_API_KEY"
done import os, time, uuid, requests
BASE = "https://staglight.ai"
HEADERS = {"Authorization": f"Bearer {os.environ['STAGLIGHT_API_KEY']}"}
# 0. Upload your file first. Its id goes in the body.
with open("product.jpg", "rb") as f:
media_id = requests.post(f"{BASE}/api/v1/uploads", headers=HEADERS, files={"file": f},
timeout=300).json()["id"]
# 1. Price it. Free, nothing is charged.
estimate = {
"product": {"media_id": media_id, "description": "A vitamin C serum in a glass dropper bottle"},
"items": [
{"studio": "ugc_video", "card": "talk"},
{"studio": "ugc_fotos", "card": "ugc_mirror"},
{"studio": "wiggle", "card": "wiggle"},
{"studio": "ugc_fotos", "card": "ugc_kitchen"}
]
}
price = requests.post(f"{BASE}/api/v1/studio/pack/estimate", headers=HEADERS, json=estimate, timeout=60).json()["credits"]
print(price)
# 2. Start it. max_credits refuses anything above that price; the Idempotency-Key stops a double charge.
body = {
"product": {"media_id": media_id, "description": "A vitamin C serum in a glass dropper bottle"},
"items": [
{"studio": "ugc_video", "card": "talk"},
{"studio": "ugc_fotos", "card": "ugc_mirror"},
{"studio": "wiggle", "card": "wiggle"},
{"studio": "ugc_fotos", "card": "ugc_kitchen"}
],
"max_credits": 299
}
body["max_credits"] = price
r = requests.post(f"{BASE}/api/v1/studio/pack/runs", json=body, timeout=60,
headers={**HEADERS, "Idempotency-Key": str(uuid.uuid4())})
r.raise_for_status()
start = r.json()
# 3. Wait until it finishes.
for run in start["runs"]:
url = f"{BASE}/api/v1/studio/{run['studio']}/runs/{run['id']}"
while requests.get(url, headers=HEADERS, timeout=60).json()["status"] not in ("succeeded", "partial", "failed"):
time.sleep(10)
# 4. Download every file in one zip.
with open(f"{run['id']}.zip", "wb") as out:
out.write(requests.get(url + "/outputs.zip", headers=HEADERS, timeout=300).content) // Node 18 or newer. Save as run.mjs: top-level await needs a module.
const BASE = "https://staglight.ai";
const headers = { Authorization: `Bearer ${process.env.STAGLIGHT_API_KEY}` };
const json = { ...headers, "Content-Type": "application/json" };
// 0. Upload your file first. Its id goes in the body.
import { readFile } from "node:fs/promises";
const form = new FormData();
form.append("file", new Blob([await readFile("product.jpg")]), "product.jpg");
const { id: mediaId } = await (await fetch(`${BASE}/api/v1/uploads`, { method: "POST", headers, body: form })).json();
// 1. Price it. Free, nothing is charged.
const estimate = {
"product": {"media_id": mediaId, "description": "A vitamin C serum in a glass dropper bottle"},
"items": [
{"studio": "ugc_video", "card": "talk"},
{"studio": "ugc_fotos", "card": "ugc_mirror"},
{"studio": "wiggle", "card": "wiggle"},
{"studio": "ugc_fotos", "card": "ugc_kitchen"}
]
};
const price = await (await fetch(`${BASE}/api/v1/studio/pack/estimate`, { method: "POST", headers: json, body: JSON.stringify(estimate) })).json();
console.log(price.credits);
// 2. Start it. max_credits refuses anything above that price; the Idempotency-Key stops a double charge.
const body = {
"product": {"media_id": mediaId, "description": "A vitamin C serum in a glass dropper bottle"},
"items": [
{"studio": "ugc_video", "card": "talk"},
{"studio": "ugc_fotos", "card": "ugc_mirror"},
{"studio": "wiggle", "card": "wiggle"},
{"studio": "ugc_fotos", "card": "ugc_kitchen"}
],
"max_credits": 299
};
body.max_credits = price.credits;
const res = await fetch(`${BASE}/api/v1/studio/pack/runs`, {
method: "POST", headers: { ...json, "Idempotency-Key": crypto.randomUUID() }, body: JSON.stringify(body),
});
if (!res.ok) throw new Error((await res.json()).error.message);
const start = await res.json();
// 3. Wait until it finishes.
for (const run of start.runs) {
const url = `${BASE}/api/v1/studio/${run.studio}/runs/${run.id}`;
while (!["succeeded", "partial", "failed"].includes((await (await fetch(url, { headers })).json()).status)) {
await new Promise((r) => setTimeout(r, 10000));
}
// 4. Download every file in one zip.
console.log(`${url}/outputs.zip`);
} Use the Staglight API to run the workflow "Ad pack from one photo" from server code.
Docs: https://staglight.ai/llms.txt
This workflow: https://staglight.ai/en/api/workflows/pack
Key: read it from the STAGLIGHT_API_KEY environment variable. Never put it in browser code.
1. Price it for free first: POST /api/v1/studio/pack/estimate
2. Start it: POST /api/v1/studio/pack/runs, with an Idempotency-Key header and max_credits.
Body: {"product": {"media_id": "med_your_upload_id", "description": "A vitamin C serum in a glass dropper bottle"}, "items": [{"studio": "ugc_video", "card": "talk"}, {"studio": "ugc_fotos", "card": "ugc_mirror"}, {"studio": "wiggle", "card": "wiggle"}, {"studio": "ugc_fotos", "card": "ugc_kitchen"}], "max_credits": 299}
Files are media ids from POST /api/v1/uploads.
3. After a timeout, check the job list before you retry, and retry with the same Idempotency-Key.
4. Poll the run until it finishes, then download its outputs.zip. What it costs
| Template | Price |
|---|---|
| UGC Video / Talks about it | 169 cr |
| UGC Shots / Mirror Selfie | 18 cr |
| Wiggle Clip / The wiggle clip | 94 cr |
| UGC Shots / Kitchen Counter | 18 cr |
Prices from the server at the default settings. The estimate call gives the exact price for your inputs, for free.
Inputs
| Name | Type | Allowed |
|---|---|---|
product.media_idrequiredThe product photo | media id | Image |
product.descriptionOne line about the product | string | |
itemsrequiredThe templates in the pack | object[] | Up to 12, each {studio, card} from GET /api/v1/studio/pack |
Files are media ids from POST /api/v1/uploads. View documentation
Try it by hand
The same workflow runs in the studio, on the same balance. Use it to see the result before you write code.