Video generation
Start a video job, follow it until it finishes, download the file, cancel it, and understand what a video costs, including failed and cancelled jobs.
MarkdownOn this page
Videos take from tens of seconds to several minutes to generate, so a video is a job: you start it with one request and read its status until it finishes. Field by field reference: POST /videos, GET /videos/{id}, GET /videos/{id}/content, POST /videos/{id}/cancel and GET /videos.
Start a job
curl https://api.getlykia.com/v1/videos \
-H "Authorization: Bearer $LYKIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "bytedance/seedance-1.0-pro",
"prompt": "Waves rolling onto a quiet beach at dusk, slow camera pan",
"duration": 5,
"resolution": "720p",
"aspect_ratio": "16:9"
}'import os
import requests
response = requests.post(
"https://api.getlykia.com/v1/videos",
headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
json={
"model": "bytedance/seedance-1.0-pro",
"prompt": "Waves rolling onto a quiet beach at dusk, slow camera pan",
"duration": 5,
"resolution": "720p",
"aspect_ratio": "16:9",
},
timeout=60,
)
response.raise_for_status()
job = response.json()
print(job["id"], job["status"]) # keep the id: it is how you follow the jobconst response = await fetch("https://api.getlykia.com/v1/videos", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.LYKIA_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
model: "bytedance/seedance-1.0-pro",
prompt: "Waves rolling onto a quiet beach at dusk, slow camera pan",
duration: 5,
resolution: "720p",
aspect_ratio: "16:9",
}),
});
if (!response.ok) throw new Error(`Lykia returned ${response.status}: ${await response.text()}`);
const job = (await response.json()) as { id: string; status: string };
console.log(job.id, job.status); // keep the id: it is how you follow the jobThe answer comes back right away with the job object and status: "queued". Its id (gen-…) is the job id, and also the id of the request record once the job ends.
curl https://api.getlykia.com/v1/videos \
-H "Authorization: Bearer $LYKIA_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "bytedance/seedance-1.0-pro",
"prompt": "Waves rolling onto a quiet beach at dusk, slow camera pan",
"duration": 5,
"resolution": "720p",
"aspect_ratio": "16:9"
}'import os
import requests
response = requests.post(
"https://api.getlykia.com/v1/videos",
headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
json={
"model": "bytedance/seedance-1.0-pro",
"prompt": "Waves rolling onto a quiet beach at dusk, slow camera pan",
"duration": 5,
"resolution": "720p",
"aspect_ratio": "16:9",
},
timeout=60,
)
response.raise_for_status()
job = response.json()
print(job["id"], job["status"]) # keep the id: it is how you follow the jobconst response = await fetch("https://api.getlykia.com/v1/videos", {
method: "POST",
headers: { Authorization: `Bearer ${process.env.LYKIA_API_KEY}`, "Content-Type": "application/json" },
body: JSON.stringify({
model: "bytedance/seedance-1.0-pro",
prompt: "Waves rolling onto a quiet beach at dusk, slow camera pan",
duration: 5,
resolution: "720p",
aspect_ratio: "16:9",
}),
});
if (!response.ok) throw new Error(`Lykia returned ${response.status}: ${await response.text()}`);
const job = (await response.json()) as { id: string; status: string };
console.log(job.id, job.status); // keep the id: it is how you follow the job{
"id": "gen-1795463406-qOWSYdRnX7cEsv8q",
"object": "video",
"status": "queued",
"progress": 0,
"model": "bytedance/seedance-1.0-pro",
"provider": "bytedance",
"created_at": 1795463406,
"completed_at": null,
"expires_at": null,
"duration_seconds": null,
"params": {
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "720p",
"image": false,
"last_frame": false,
"reference_images": 0
}
}The job lifecycle
queued ──> in_progress ──> completed
│ ├──────> failed
└─────────────┴──────> cancelledqueued: accepted. The job may wait in Lykia's queue when Lykia's connection to the provider is running as many jobs as it can at once; it is sent as soon as there is room.in_progress: the provider is generating it.progressgoes from 0 to 100 when the provider reports it.completed: the video is ready;outputdescribes the file andusage.costis the final cost.failed: the provider could not make it, or it took longer than Lykia's time limit for a job.errorsays why.cancelled: you cancelled it.
Wait for the result
Read the job with GET /videos/{id} every few seconds until the status is completed, failed or cancelled:
import os
import time
import requests
BASE = "https://api.getlykia.com/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"}
job = requests.post(
f"{BASE}/videos",
headers=HEADERS,
json={
"model": "bytedance/seedance-1.0-pro",
"prompt": "A paper boat drifting down a rainy street, close-up",
"duration": 5,
"resolution": "720p",
},
timeout=60,
).json()
print("started", job["id"])
# Poll until the job reaches a final state; video jobs usually take minutes
deadline = time.time() + 30 * 60
while job["status"] in ("queued", "in_progress"):
if time.time() > deadline:
raise TimeoutError(f"{job['id']} is still {job['status']}")
time.sleep(5)
job = requests.get(f"{BASE}/videos/{job['id']}", headers=HEADERS, timeout=30).json()
print(job["status"], job.get("progress"))
if job["status"] != "completed":
error = job.get("error") or {}
raise SystemExit(f"{job['status']}: {error.get('message')} (cost {job['usage']['cost']} USD)")
print("cost (USD):", job["usage"]["cost"])
# The link is signed for one hour; read the job again for a fresh one
print("download:", job["output"]["url"])const BASE = "https://api.getlykia.com/v1";
const headers = { Authorization: `Bearer ${process.env.LYKIA_API_KEY}`, "Content-Type": "application/json" };
type VideoJob = {
id: string;
status: "queued" | "in_progress" | "completed" | "failed" | "cancelled";
progress: number;
error?: { message: string; code: string; billed_by_provider?: boolean };
usage?: { cost: number };
output?: { url: string | null; expires_at?: string; mime_type?: string };
};
const created = await fetch(`${BASE}/videos`, {
method: "POST",
headers,
body: JSON.stringify({
model: "bytedance/seedance-1.0-pro",
prompt: "A paper boat drifting down a rainy street, close-up",
duration: 5,
resolution: "720p",
}),
});
if (!created.ok) throw new Error(`Lykia returned ${created.status}: ${await created.text()}`);
let job = (await created.json()) as VideoJob;
console.log("started", job.id);
// Poll until the job reaches a final state; video jobs usually take minutes
const deadline = Date.now() + 30 * 60_000;
while (job.status === "queued" || job.status === "in_progress") {
if (Date.now() > deadline) throw new Error(`${job.id} is still ${job.status}`);
await new Promise((resolve) => setTimeout(resolve, 5000));
job = (await (await fetch(`${BASE}/videos/${job.id}`, { headers })).json()) as VideoJob;
console.log(job.status, job.progress);
}
if (job.status !== "completed") throw new Error(`${job.status}: ${job.error?.message} (cost ${job.usage?.cost} USD)`);
console.log("cost (USD):", job.usage?.cost);
// The link is signed for one hour; read the job again for a fresh one
console.log("download:", job.output?.url);package main
import (
"bytes"
"encoding/json"
"fmt"
"io"
"net/http"
"os"
"time"
)
const base = "https://api.getlykia.com/v1"
type videoJob struct {
ID string `json:"id"`
Status string `json:"status"`
Progress int `json:"progress"`
Error *struct {
Message string `json:"message"`
} `json:"error"`
Usage *struct {
Cost float64 `json:"cost"`
} `json:"usage"`
Output *struct {
URL *string `json:"url"`
ExpiresAt string `json:"expires_at"`
} `json:"output"`
}
func call(method, path string, body []byte) videoJob {
req, err := http.NewRequest(method, base+path, bytes.NewReader(body))
if err != nil {
panic(err)
}
req.Header.Set("Authorization", "Bearer "+os.Getenv("LYKIA_API_KEY"))
req.Header.Set("Content-Type", "application/json")
resp, err := http.DefaultClient.Do(req)
if err != nil {
panic(err)
}
defer resp.Body.Close()
raw, _ := io.ReadAll(resp.Body)
if resp.StatusCode != http.StatusOK {
panic(fmt.Sprintf("Lykia returned %d: %s", resp.StatusCode, raw))
}
var job videoJob
if err := json.Unmarshal(raw, &job); err != nil {
panic(err)
}
return job
}
func main() {
payload, _ := json.Marshal(map[string]any{
"model": "bytedance/seedance-1.0-pro",
"prompt": "A paper boat drifting down a rainy street, close-up",
"duration": 5,
"resolution": "720p",
})
job := call(http.MethodPost, "/videos", payload)
fmt.Println("started", job.ID)
// Poll until the job reaches a final state; video jobs usually take minutes
deadline := time.Now().Add(30 * time.Minute)
for job.Status == "queued" || job.Status == "in_progress" {
if time.Now().After(deadline) {
panic(job.ID + " is still " + job.Status)
}
time.Sleep(5 * time.Second)
job = call(http.MethodGet, "/videos/"+job.ID, nil)
fmt.Println(job.Status, job.Progress)
}
if job.Status != "completed" {
message := ""
if job.Error != nil {
message = job.Error.Message
}
panic(job.Status + ": " + message)
}
fmt.Println("cost (USD):", job.Usage.Cost)
if job.Output != nil && job.Output.URL != nil {
// The link is signed for one hour; read the job again for a fresh one
fmt.Println("download:", *job.Output.URL)
}
}When the job is completed, output has the file's url, mime_type, bytes and, when known, width and height:
curl https://api.getlykia.com/v1/videos/gen-1795463406-qOWSYdRnX7cEsv8q \
-H "Authorization: Bearer $LYKIA_API_KEY"import os
import requests
VIDEO_ID = "gen-1795463406-qOWSYdRnX7cEsv8q"
response = requests.get(
f"https://api.getlykia.com/v1/videos/{VIDEO_ID}",
headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
timeout=30,
)
response.raise_for_status()
job = response.json()
print(job["status"], job["progress"])
if job["status"] == "completed":
print(job["output"]["url"], "valid until", job["output"]["expires_at"])const VIDEO_ID = "gen-1795463406-qOWSYdRnX7cEsv8q";
const response = await fetch(`https://api.getlykia.com/v1/videos/${VIDEO_ID}`, {
headers: { Authorization: `Bearer ${process.env.LYKIA_API_KEY}` },
});
if (!response.ok) throw new Error(`Lykia returned ${response.status}: ${await response.text()}`);
const job = (await response.json()) as { status: string; progress: number; output?: { url: string | null; expires_at?: string } };
console.log(job.status, job.progress);
if (job.status === "completed") console.log(job.output?.url, "valid until", job.output?.expires_at);{
"id": "gen-1795463406-qOWSYdRnX7cEsv8q",
"object": "video",
"status": "completed",
"progress": 100,
"model": "bytedance/seedance-1.0-pro",
"provider": "bytedance",
"created_at": 1795463406,
"completed_at": 1795463439,
"expires_at": 1796068239,
"duration_seconds": 5,
"params": {
"duration": 5,
"aspect_ratio": "16:9",
"resolution": "720p",
"image": false,
"last_frame": false,
"reference_images": 0
},
"usage": {
"cost": 0.2574,
"is_byok": false,
"cost_details": {
"upstream_cost": 0.2574,
"platform_fee": 0,
"is_byok": false
}
},
"output": {
"url": "https://files.example.com/media/gen-1795463406-qOWSYdRnX7cEsv8q/0.mp4?X-Amz-Expires=3600&X-Amz-Signature=5f0c9e…",
"expires_at": "2026-11-23T20:50:41.145Z",
"mime_type": "video/mp4",
"bytes": 310368
}
}duration_seconds is the length of the video, and expires_at (a Unix time) is when Lykia deletes the file. Lykia keeps outputs for a limited time set by the platform; download what you want to keep before expires_at.
Download the file
output.url is a signed link to the file in Lykia's storage, valid for one hour. Each time you read the job, Lykia signs a new link, so an expired link is fixed by reading the job again. The link needs no API key.
GET /videos/{id}/content gives you the file directly: it redirects (302) to a fresh signed link, so a client that follows redirects downloads the file in one step.
# Follows the redirect to the signed file and saves it
curl -L https://api.getlykia.com/v1/videos/gen-1795463406-qOWSYdRnX7cEsv8q/content \
-H "Authorization: Bearer $LYKIA_API_KEY" \
-o beach.mp4import os
import requests
VIDEO_ID = "gen-1795463406-qOWSYdRnX7cEsv8q"
# redirect=false returns the signed link as JSON instead of redirecting to it
link = requests.get(
f"https://api.getlykia.com/v1/videos/{VIDEO_ID}/content",
headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
params={"redirect": "false"},
timeout=30,
)
link.raise_for_status()
info = link.json()
print(info["mime_type"], "valid until", info["expires_at"])
# The signed link needs no Lykia key
video = requests.get(info["url"], timeout=300)
video.raise_for_status()
with open("beach.mp4", "wb") as f:
f.write(video.content)
print("saved beach.mp4,", len(video.content), "bytes")Add ?redirect=false to receive the link as JSON instead of being redirected:
{
"url": "https://files.example.com/media/gen-1795463406-qOWSYdRnX7cEsv8q/0.mp4?X-Amz-Expires=3600&X-Amz-Signature=5f0c9e…",
"expires_at": "2026-11-23T20:50:41.269Z",
"mime_type": "video/mp4"
}Asking for the content of a job that is not completed returns 409 with the code video_not_ready; after expires_at it returns 410 with video_expired.
First frame, last frame and references
image: a first frame. The video starts from this image (image to video).last_frame: a last frame, together withimage. The video moves from the first frame to this one.reference_images: images whose subject or style the video should keep, for models that take them.
Images can be public https:// URLs or data URIs. What a model supports is in its media.capabilities in GET /models?kind=video: operations (text_to_video, image_to_video, first_last_frame, reference_to_video), firstFrame, lastFrame and maxInputImages.
Duration, resolution and audio
duration: the length in seconds.durationsin the capabilities gives the range (min,max) or the exactvaluesa model allows.resolutionandaspect_ratio: fromresolutionsandaspectRatios.audio:trueorfalsefor models where sound can be turned on or off.audioin the capabilities isalwayswhen the model always produces sound,nonewhen it never does.
A value the model does not support returns 400 with the code unsupported_input and metadata.param naming the field, before the job is created.
Cancel a job
POST /videos/{id}/cancel stops a job. A job still waiting in Lykia's queue is always cancelled; a job already with the provider is cancelled when the provider allows it at that stage. A job that cannot be cancelled, or has already finished, returns 409 with job_not_cancellable.
curl -X POST https://api.getlykia.com/v1/videos/gen-1795463449-mbcwAk5o21bdfuKi/cancel \
-H "Authorization: Bearer $LYKIA_API_KEY"import os
import requests
VIDEO_ID = "gen-1795463449-mbcwAk5o21bdfuKi"
response = requests.post(
f"https://api.getlykia.com/v1/videos/{VIDEO_ID}/cancel",
headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
timeout=30,
)
if response.status_code == 409:
# Already finished, or the provider cannot stop it at this stage
print(response.json()["error"]["code"])
else:
response.raise_for_status()
print(response.json()["status"]) # "cancelled"; a cancelled job is freeA cancelled job costs nothing.
List jobs
GET /videos lists the project's video jobs, newest first, 20 at a time by default and up to 100 with limit. Filter with status, and page with after set to the previous page's next_cursor while has_more is true.
curl "https://api.getlykia.com/v1/videos?limit=20&status=completed" \
-H "Authorization: Bearer $LYKIA_API_KEY"import os
import requests
params = {"limit": 20}
while True:
page = requests.get(
"https://api.getlykia.com/v1/videos",
headers={"Authorization": f"Bearer {os.environ['LYKIA_API_KEY']}"},
params=params,
timeout=30,
).json()
for job in page["data"]:
print(job["id"], job["status"], job["model"])
if not page["has_more"]:
break
params["after"] = page["next_cursor"]What a video costs
The price of a video model is in media.pricing in the catalog, usually per second of video, per video, or per token for models whose provider bills tokens, with tiers by resolution, audio or duration. When the job starts, Lykia reserves the highest amount it can cost; when it completes, Lykia charges what the provider reports, never more than the reservation.
- Completed: you pay the job's cost, shown in
usage.cost. - Failed, timed out or cancelled: you pay nothing, and the reservation is released.
- Exception: some providers charge for a request they reject, for example on content grounds. Lykia passes that real cost on; the job's
error.billed_by_provideris thentrueandusage.costshows the amount.
If a job runs past Lykia's time limit it fails with error.code: "timeout" and is not charged, even if the provider finishes it later.
Errors
| Code | Status | When |
|---|---|---|
unsupported_input | 400 | A value the model does not support, or an option combination that is not priced yet. metadata.param names the field. |
unsupported_model | 400 | The model does not generate videos. |
platform_sales_disabled | 403 | The model's provider is not offered on Lykia credits yet. Add your own key for that provider to the project. |
video_not_ready | 409 | Content asked for before the job completed. |
job_not_cancellable | 409 | The job has finished or the provider cannot cancel it now. |
video_expired | 410 | The file has been deleted after expires_at. |
media_queue_full | 429 | The project already has the most jobs Lykia lets it keep waiting. Try again when some have started. |
See Errors for the error body and the other status codes.