KozeKoze
โ† Back to Blog
Tutorial2026ๅนด6ๆœˆ28ๆ—ฅยท็ฎก็†ๅ‘˜

Video Generation API Call Documentation

Kozeai provides a video generation interface compatible with OpenAI Sora, using an asynchronous task mode: first submit the task to get the `task_id`, then poll the task status, and download the video content upon completion.

Video Generation API Call Documentation

kozeai provides a video generation interface compatible with OpenAI Sora, using an **asynchronous task** mode: first submit the task to obtain the `task_id`, then poll the task status, and download the video content upon completion.

Authentication

All requests are authenticated using `Authorization: Bearer `. Use this after creating an API token in the console.

export KOZEAI_API_KEY="sk-your-token"
export KOZEAI_BASE_URL="https://api.kozeai.com"

Interface Overview

mp4
Method Path Purpose
POST /v1/videos/generations Create Video Task
GET /v1/videos/{task_id} Query Task Status
GET /v1/videos/{task_id}/content Play Online or Download

Task ID in the form of task_12345, returned by the submission interface, belongs only to the current user.


1. Create video task

curl "$KOZEAI_BASE_URL/v1/videos/generations" \
  -H "Authorization: Bearer $KOZEAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "video-ds-2.0",
    "prompt": "A cinematic 9:16 video of a cat running through warm sunlight",
    "seconds": 15,
    "aspect_ratio": "9:16"
  }'

Request Parameters

Parameters Type Required Description
model string Yes Video model name, such as video-ds-2.0
prompt string Yes Video content description
seconds integer No Video duration (seconds), based on upstream model support range
aspect_ratio string No Aspect ratio, commonly used 9:16, 16:9, 1:1
images array No Reference images URL or base64
videos array No Reference Video URL
audios array No Reference Audio URL

Different upstream models may support different parameters. Parameters not listed will be passed through according to the upstream protocol.

Image-generated video (with reference images)

Pass in the images array to generate a video based on the reference images:

curl "$KOZEAI_BASE_URL/v1/videos/generations" \

-H "Authorization: Bearer $KOZEAI_API_KEY" \

-H "Content-Type: application/json" \

-d '{

"model": "video-ds-2.0",
    "prompt": "Use the reference image style and create a smooth product video",
    "seconds": 15,
    "aspect_ratio": "9:16",
    "images": ["https://example.com/input.png"],
    "videos": ["https://example.com/input.mp4"],
    "audios": ["https://example.com/input.mp3"]
  }'
  • images supports image URLs or base64.
  • videos / audios are optional reference materials.
  • When calling through the chat autocomplete interface (see end of article), simply attach the image to the message; the system will automatically convert it to the images parameter.

Response (submission successful)

{
  "id": "task_12345",
  "task_id": "task_12345",
  "object": "video",
  "model": "video-ds-2.0",
  "status": "queued",
  "progress": 0,
  "created_at": 

}

status Values: queued (queued), in_progress (in progress), completed (completed), failed (failed).


2. Polling Task Status

Use the id returned by the submission to poll, with a recommended interval of 3-5 seconds.

curl "$KOZEAI_BASE_URL/v1/videos/task_12345" \
  -H "Authorization: Bearer $KOZEAI_API_KEY"

Response (generating)

{
  "id": "task_12345",
  "object": "video",
  "model": "video-ds-2.0",
  "status": "in_progress",
  "progress": 45,
  "created_at": 1751000000
}

Response (Complete)

{
  "id": "task_12345",
  "object": "video",
  "model": "video-ds-2.0",
  "status": "completed",
  "progress": 100,
  "created_at": 1751000000,
  

After completion, `metadata.content_url` provides the directly accessible video address; it can also be downloaded using the content interface below.

Response (failed)

{
  "id": "task_12345",
  "object": "video",
  "status": "failed",
  "error": { "message": "Failure reason" }
}

3. Download video content

curl -L "$KOZEAI_BASE_URL/v1/videos/task_12345/content" \
  -H "Authorization: Bearer $KOZEAI_API_KEY" \
  -o result.mp4

  • Returns 409 Conflict if task is not completed (Still in queue/generating).
  • Supports segmented download/drag-and-drop playback using the request header.
  • Returns .

Full example

JavaScript (fetch + polling)

const BASE = process.env.KOZEAI_BASE_URL;
const KEY = process.env.KOZEAI_API_KEY;
const headers = { Authorization: `Bearer ${KEY}` };

// 1. Submit task
const submit = await fetch(`${BASE}/v1/videos/generations`, {
  method: 'POST',
  headers: { ...headers, 'Content-Type': 'application/json' },
  body: JSON.stringify({
    model: 'video-ds-2.0',
    prompt: 'A smooth commercial video of a perfume bottle on glass',
    seconds: 15,
    aspect_ratio: '9:16',
  }),
});
const task = await submit.json();
const taskId = task.id;

// 2. Poll until completed
async function poll() {
  while (true) {
    const res = await fetch(`${BASE}/v1/videos/${taskId}`, { headers });
    const data = await res.json();
    if (data.status === 'completed') return data;
    if (data.status === 'failed') throw new Error(data.error?.message || 'failed');
    await new Promise((r) => setTimeout(r, 5000));
  }
}
const done = await poll();

// 3. Get the video address
console.log('Video address:', done.metadata?.content_url
  || `${BASE}/v1/videos/${taskId}/content`);

Python (requests + polling)

import os, time, requests

BASE = os.environ["KOZEAI_BASE_URL"]
KEY = os.environ["KOZEAI_API_KEY"]
headers = {"Authorization": f"Bearer {KEY}"}

# 1. Submit task
resp = requests.post(
    f"{BASE}/v1/videos/generations",
    headers=headers,
    json={
        "model": "video-ds-2.0",
        "prompt": "A cinematic 9:16 video of a cat running through warm sunlight",
        "seconds": 15,
        "aspect_ratio": "9:16",
    },
)
task_id = resp.json()["id"]

# 2. Polling
while True:
    data = requests.get(f"{BASE}/v1/videos/{task_id}", headers=headers).json()
    if data["status"] == "completed":
        break
    if data["status"] == "failed":
        raise RuntimeError(data.get("error", {}).get("message", "failed"))
    time.sleep(5)

# 3. Download
mp4 = requests.get(f"{BASE}/v1/videos/{task_id}/content", headers=headers)
with open("result.mp4", "wb") as f: f.write(mp4.content)


Called in the chat completion interface (compatible usage)

The video model can also be called via /v1/chat/completions, facilitating the reuse of chat clients.

When making a request, simply pass the video model name in `model`, and the system will automatically convert it into a video task:
curl $KOZEAI_BASE_URL/v1/chat/completions

\ -H Authorization: Bearer $KOZEAI_API_KEY \ -H Content-Type: application/json \ -d { Model: } `

returns "video-ds-2.0

, "messages: [{"role: "user, "content: "a cat running in the sunlight, cinematic, 9:16}] }

Returns chat completion

The format is `message.content`, which contains the task status and a link `/v1/videos/{task_id}`. This link will play the video once it completes. The chat lobby page uses this method.

Both entry points (/v1/videos/generations and /v1/chat/completions) share the same task system and do not conflict with each other. For direct integration, it is recommended to use the standard `/v1/videos/*` interface.


Error Code

Status Code Meaning
401 Token missing, expired, or invalid
403 Insufficient balance, or the current group does not have permission for this model
404 Task ID Does not exist, or does not belong to the current user; or the model is not configured.
409 Video content is not ready (task is still queuing/generating)
429 Triggering rate limit
502 Upstream supplier failed or returned invalid result