Video
Luo videoleikkeitä asynkronisella tehtävämallilla — lähetä kehote, tee tilakysely ja nouda tulos.
Videon generointi on asynkronista: lähetä prompt, vastaanota task id, pollaa sen statusta ja hae sitten valmis klippi. Text-to-video, image-to-video ja referenssitilat jakavat kaikki saman request-muodon.
Kestot, resoluutiot ja aspect ratiot, joita voit pyytää, riippuvat valitusta mallista — lue ne models-endpointista sen sijaan, että olettaisit kiinteän joukon.
Videon luonti toimii taustalla – suoratoistoa ei ole. Menettely on aina: luo tehtävä → kyselyn tila → lataa MP4. Tehtävät vanhenevat 24 tunnin kuluttua.
1. Luo tehtävä
Lähettää työn ja palauttaa task ID:n. Kustannus arvioidaan kestosta × mallin sekuntihinta ja veloitetaan, kun työ käsitellään.
https://api.airforce/v1/video/generationsVideo mallit
…· live| Parameter | Type | Required | Description |
|---|---|---|---|
| model | string | Required | Video model ID. Use /v1/models and filter by output_modalities.includes("video"). |
| prompt | string | Required | Scene description. |
| mode | string | Optional | "text" (default), "image" (animate a first-frame image), "reference" (style transfer from one or more frames). |
| duration_seconds | integer | Optional | Clip length. Range depends on the model — typically 5, 8 or 10 s. Defaults to the model's minimum. |
| aspect_ratio | string | Optional | "16:9", "9:16", "1:1", "4:3" — must be in the model's supported list. |
| quality | string | Optional | "480p", "720p", "1080p" — must be in the model's supported list. |
| input_images | array | Optional | [{ url? } | { b64_json? }] — required for "image" and "reference" modes. |
Kaikki muut avaimet (esim. seed, sound) välitetään upstream-palveluntarjoajalle sellaisenaan — niitä ei validoida täällä ja tuki on mallikohtaista.
Esimerkkejä
Tekstistä videoksi
curl https://api.airforce/v1/video/generations \
-H "Authorization: Bearer sk-air-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "wan-2.6",
"prompt": "A red fox darting across snowy hills at dawn",
"duration_seconds": 8,
"aspect_ratio": "16:9",
"quality": "720p",
"sound": true
}'Kuvasta videoon (ensimmäinen ruutu)
curl https://api.airforce/v1/video/generations \
-H "Authorization: Bearer sk-air-YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "kling-1",
"mode": "image",
"prompt": "Camera pulls back as the dragon takes off",
"duration_seconds": 5,
"aspect_ratio": "16:9",
"input_images": [{"url": "https://example.com/dragon.jpg"}]
}'Vastaus
| Parameter | Type | Required | Description |
|---|---|---|---|
| task_id | string | Optional | Persistent task identifier. Use it on every follow-up endpoint. |
| status | string | Optional | "queued" right after creation. |
| model | string | Optional | Echo of requested model. |
| created | integer | Optional | Unix timestamp. |
| expires_at | integer | Optional | Unix timestamp after which the result is purged (exactly created + 86400). |
| progress | integer | Optional | 0 right after creation. |
| cost_cents | number | Optional | Estimated cost for the job. Final billing is settled when the job is processed. |
{
"task_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"status": "queued",
"model": "wan-2.6",
"created": 1715000000,
"expires_at": 1715086400,
"progress": 0,
"cost_cents": 320
}2. Tilauskysely
Äänestys 5–15 sekunnin välein. Tehtävät valmistuvat yleensä 30 s – 4 min kestosta ja mallista riippuen. Sama päätepiste palauttaa tuloksen URL-osoitteen, kun tila vaihtuu "valmis".
https://api.airforce/v1/video/tasks/:task_id| Parameter | Type | Required | Description |
|---|---|---|---|
| status | string | Optional | "queued" | "processing" | "completed" | "failed" | "expired". |
| progress | integer | Optional | 0–100 while processing. |
| result_url | string | Optional | MP4 download URL once status is "completed", set by the upstream provider. Valid until expires_at. |
| error | string | Optional | Failure message. Set (non-null) when status is "failed". |
| cost_cents | number | Optional | Cost for the job, settled when it is processed. |
{
"task_id": "f47ac10b-58cc-4372-a567-0e02b2c3d479",
"status": "completed",
"progress": 100,
"result_url": "https://.../video.mp4",
"model": "wan-2.6",
"duration_seconds": 8,
"expires_at": 1715086400,
"cost_cents": 320
}2b. Suoratoiston edistyminen (valinnainen)
Ohita kyselysilmukka palvelimen lähettämät tapahtumat -streamilla. Lähettää yhden tapahtuman edistymismuutosta kohti ja sulkeutuu, kun tehtävä on päätetilassa. Sama hyötykuorman muoto kuin GET-päätepisteessä.
https://api.airforce/v1/video/tasks/:task_id/streamevent: state
data: {"task_id":"f47ac10b-...","status":"processing","progress":12}
event: state
data: {"task_id":"f47ac10b-...","status":"processing","progress":58}
event: state
data: {"task_id":"f47ac10b-...","status":"completed","progress":100,"result_url":"https://.../video.mp4"}
event: done
data: [DONE]3. Listaa ja poista
https://api.airforce/v1/video/tasksPalauttaa viimeaikaiset tehtäväsi (uusimmat ensin). Hyödyllinen kojelaudalle historianäkymän luomiseen.
Palauttaa enintään 100 viimeisintä taskiasi, uusin ensin, muodossa { "data": [ ...tasks ] }. Kyselyparametreja ei ole — suodata ja sivuta asiakaspuolella.
curl https://api.airforce/v1/video/tasks \
-H "Authorization: Bearer sk-air-YOUR_API_KEY"https://api.airforce/v1/video/tasks/:task_idPoistaa tehtävätietueen historiastasi.
Idempotentti — palauttaa aina { "deleted": true }. Tämä poistaa vain historiatietueesi; se ei erikseen tyhjennä tallennettua mediaa.
Kustannukset ja rajoitukset
Jokainen videomalli paljastaa ominaisuuksien metatiedot, joista voit lukea /v1/models:
| Parameter | Type | Required | Description |
|---|---|---|---|
| video_caps.aspect_ratios | array | Optional | Allowed aspect_ratio values. |
| video_caps.qualities | array | Optional | Allowed quality values. |
| video_caps.min_duration_s / max_duration_s | integer | Optional | Allowed range for duration_seconds. |
| video_caps.modes | array | Optional | Subset of ["text", "image", "reference"] supported. |
| video_caps.price_per_second_cents | integer | Optional | Cost = duration_seconds × this value. |
- Cost is estimated at creation and settled when the job is processed; failed or expired tasks are not charged.
- Max 4 concurrent video tasks per API key.
- Result URLs are pre-signed and stop working at
expires_at. Download or copy the MP4 to your own storage if you need it longer.
Päästä-päähän käsikirjoitus
async function generateVideo(prompt) {
const create = await fetch('https://api.airforce/v1/video/generations', {
method: 'POST',
headers: {
Authorization: `Bearer ${API_KEY}`,
'Content-Type': 'application/json',
},
body: JSON.stringify({
model: 'wan-2.6',
prompt,
duration_seconds: 8,
aspect_ratio: '16:9',
quality: '720p',
}),
}).then(r => r.json());
const { task_id } = create;
// Poll until done.
while (true) {
await new Promise(r => setTimeout(r, 8_000));
const task = await fetch(
`https://api.airforce/v1/video/tasks/${task_id}`,
{ headers: { Authorization: `Bearer ${API_KEY}` } },
).then(r => r.json());
if (task.status === 'completed') return task.result_url;
if (task.status === 'failed' || task.status === 'expired') {
throw new Error(task.error ?? task.status);
}
}
}