Skip to content

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.

Markdown
On 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"
  }'

The 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.

Request
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"
  }'
Response200
{
    "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

text
queued ──> in_progress ──> completed
   │             ├──────> failed
   └─────────────┴──────> cancelled
  • queued: 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. progress goes from 0 to 100 when the provider reports it.
  • completed: the video is ready; output describes the file and usage.cost is the final cost.
  • failed: the provider could not make it, or it took longer than Lykia's time limit for a job. error says 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"])

When the job is completed, output has the file's url, mime_type, bytes and, when known, width and height:

Request
curl https://api.getlykia.com/v1/videos/gen-1795463406-qOWSYdRnX7cEsv8q \
  -H "Authorization: Bearer $LYKIA_API_KEY"
Response200
{
    "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.mp4

Add ?redirect=false to receive the link as JSON instead of being redirected:

200 OK
{
    "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 with image. 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. durations in the capabilities gives the range (min, max) or the exact values a model allows.
  • resolution and aspect_ratio: from resolutions and aspectRatios.
  • audio: true or false for models where sound can be turned on or off. audio in the capabilities is always when the model always produces sound, none when 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"

A 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"

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_provider is then true and usage.cost shows 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

CodeStatusWhen
unsupported_input400A value the model does not support, or an option combination that is not priced yet. metadata.param names the field.
unsupported_model400The model does not generate videos.
platform_sales_disabled403The model's provider is not offered on Lykia credits yet. Add your own key for that provider to the project.
video_not_ready409Content asked for before the job completed.
job_not_cancellable409The job has finished or the provider cannot cancel it now.
video_expired410The file has been deleted after expires_at.
media_queue_full429The 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.