התחלה
התחלה מהירה
ממפתח לסרטון בנוי בשש קריאות. הדוגמאות כתובות ב-cURL עם jq, ובסוף העמוד יש את כל התהליך כסקריפט JavaScript אחד.
1. יוצרים מפתח#
בעמוד /developers יוצרים מפתח ומעתיקים אותו. הוא מוצג פעם אחת בלבד. שומרים אותו במשתנה סביבה, וגם את כתובת ה-API:
export WTFLOW_API_KEY="wtf_live_…"
export API="https://www.wtflow-studio.com/api/v1"2. בודקים שהמפתח עובד#
curl "$API/me" -H "Authorization: Bearer $WTFLOW_API_KEY"חוזרים האימייל, החבילה והיתרה. 401 אומר שהמפתח שגוי, ו-403 שהחבילה לא כוללת API.
3. יוצרים פרויקט#
PROJECT=$(curl -s -X POST "$API/projects" -H "Authorization: Bearer $WTFLOW_API_KEY" \
-H "Content-Type: application/json" \
-d '{"url": "https://brightdesk.example", "prompt": "A 30-second launch video for small support teams", "language": "en", "duration": 30, "aspect": "16:9"}' \
| jq -r .id)יצירת פרויקט לא עולה קרדיטים. אפשר לתת רק url, רק prompt, או את שניהם.
4. מריצים מחקר ומחכים#
curl -X POST "$API/projects/$PROJECT/research" -H "Authorization: Bearer $WTFLOW_API_KEY"
until [ "$(curl -s "$API/projects/$PROJECT" -H "Authorization: Bearer $WTFLOW_API_KEY" | jq -r .status.busy)" = "false" ]; do
sleep 5
doneאחר כך קוראים את research מתוך GET /projects/{id}. אם משהו בבריף לא נכון, מתקנים אותו עם PATCH /projects/{id}/research לפני האישור.
5. כיוון ותסריט#
curl -X POST "$API/projects/$PROJECT/research/approve" -H "Authorization: Bearer $WTFLOW_API_KEY"
until [ "$(curl -s "$API/projects/$PROJECT" -H "Authorization: Bearer $WTFLOW_API_KEY" | jq -r .status.busy)" = "false" ]; do
sleep 5
done
curl "$API/projects/$PROJECT/directions" -H "Authorization: Bearer $WTFLOW_API_KEY" | jq '.data[] | {id, title, hook}'
curl -X POST "$API/projects/$PROJECT/directions/d1/choose" -H "Authorization: Bearer $WTFLOW_API_KEY"
until [ "$(curl -s "$API/projects/$PROJECT" -H "Authorization: Bearer $WTFLOW_API_KEY" | jq -r .status.busy)" = "false" ]; do
sleep 5
done
curl "$API/projects/$PROJECT/script" -H "Authorization: Bearer $WTFLOW_API_KEY" | jq .scriptהתסריט הוא סצנה אחר סצנה. אפשר לשמור גרסה ערוכה שלו עם PUT לפני האישור.
6. בונים את הסצנות#
curl -X POST "$API/projects/$PROJECT/script/approve" -H "Authorization: Bearer $WTFLOW_API_KEY" \
-H "Content-Type: application/json" -d '{"withMotion": true}'
until [ "$(curl -s "$API/projects/$PROJECT" -H "Authorization: Bearer $WTFLOW_API_KEY" | jq -r .status.busy)" = "false" ]; do
sleep 5
done
curl "$API/projects/$PROJECT/composition" -H "Authorization: Bearer $WTFLOW_API_KEY" | jq '{duration, scenes: (.composition.scenes | length), editorUrl}'7. עריכה בצ׳אט#
curl -X POST "$API/projects/$PROJECT/messages" -H "Authorization: Bearer $WTFLOW_API_KEY" \
-H "Content-Type: application/json" -d '{"text": "Make the headline in scene 1 green and shorter"}'
# when the reply is no longer pending, it carries a proposal
curl "$API/projects/$PROJECT/messages?limit=2" -H "Authorization: Bearer $WTFLOW_API_KEY" | jq '.data[-1] | {id, pending, proposal}'
curl -X POST "$API/projects/$PROJECT/proposals/REPLY_ID/apply" -H "Authorization: Bearer $WTFLOW_API_KEY"כל התהליך ב-JavaScript#
make-video.mjs
// Node 18 or later: node make-video.mjs
const API = "https://www.wtflow-studio.com/api/v1";
const KEY = process.env.WTFLOW_API_KEY;
async function call(method, path, body) {
const res = await fetch(API + path, {
method,
headers: { Authorization: `Bearer ${KEY}`, "Content-Type": "application/json" },
body: body ? JSON.stringify(body) : undefined,
});
const data = await res.json();
if (!res.ok) throw new Error(`${res.status} ${data.error.code}: ${data.error.message}`);
return data;
}
// long steps run in the background: read the project until it is idle
async function settle(id) {
for (;;) {
const p = await call("GET", `/projects/${id}`);
if (!p.status.busy) {
if (p.status.error) throw new Error(p.status.error);
return p;
}
await new Promise((r) => setTimeout(r, 4000));
}
}
const project = await call("POST", "/projects", {
url: "https://brightdesk.example",
prompt: "A 30-second launch video for small support teams",
language: "en",
duration: 30,
aspect: "16:9",
});
await call("POST", `/projects/${project.id}/research`);
await settle(project.id);
await call("POST", `/projects/${project.id}/research/approve`);
const { directions } = await settle(project.id);
await call("POST", `/projects/${project.id}/directions/${directions[0].id}/choose`);
await settle(project.id);
await call("POST", `/projects/${project.id}/script/approve`, { withMotion: true });
await settle(project.id);
const { composition, editorUrl } = await call("GET", `/projects/${project.id}/composition`);
console.log(`${composition.scenes.length} scenes. Export the MP4 here: ${editorUrl}`);