> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# API pembuatan video

> Pilih rute video CometAPI untuk alur kerja Seedance, HappyHorse, Sora 2, Veo 3, Wan, xAI, Vidu, Omni, Kling, dan Runway.

Gunakan dokumentasi model video CometAPI dengan memilih alur kerja penyedia yang sesuai dengan jenis tugas Anda. Sebagian besar endpoint video membuat task asinkron, jadi simpan task ID dan gunakan polling untuk mengambil hasil. Tambahkan callback hanya jika halaman khusus model mendokumentasikan dukungan callback.

## Pilih API video

<CardGroup cols={2}>
  <Card title="Buat video Seedance" icon="sparkles" href="/api/video/seedance/create">
    Buat task video Seedance.
  </Card>

  <Card title="Buat video HappyHorse" icon="sparkles" href="/api/video/happyhorse/create">
    Buat job text-to-video HappyHorse.
  </Card>

  <Card title="Buat video Sora 2" icon="film" href="/api/video/sora-2/create">
    Buat job video Sora 2.
  </Card>

  <Card title="Ambil video Sora 2" icon="refresh" href="/api/video/sora-2/retrieve">
    Kueri job video Sora.
  </Card>

  <Card title="Buat video Veo 3" icon="film" href="/api/video/veo3/create">
    Buat job video Veo.
  </Card>

  <Card title="Buat video Wan" icon="sparkles" href="/api/video/wan/create">
    Buat job text-to-video Wan.
  </Card>

  <Card title="Buat video xAI" icon="film" href="/api/video/xai/video-generation">
    Hasilkan job video xAI.
  </Card>

  <Card title="Buat video Vidu" icon="sparkles" href="/api/video/vidu/create">
    Buat job text-to-video Vidu.
  </Card>

  <Card title="Buat video Omni (Beta)" icon="sparkles" href="/api/video/omni/create">
    Buat job video Omni beta.
  </Card>

  <Card title="Buat task text-to-video Kling" icon="film" href="/api/video/kling/text-to-video">
    Hasilkan video Kling dari prompt teks.
  </Card>

  <Card title="Buat task image-to-video Runway" icon="film" href="/api/video/runway/official-format/runway-images-raw-video">
    Hasilkan video Runway dari gambar.
  </Card>
</CardGroup>

## Membuat dan memantau task video

Gunakan model ID yang mendukung video dari [halaman Models](/id/overview/models) atau [direktori model](https://www.cometapi.com/models/). Contoh di bawah membuat task video dengan `POST /v1/videos`, lalu memantau task ID yang dikembalikan hingga task mencapai status terminal.

<Note>
  Contoh-contoh ini menggunakan placeholder `your-video-model-id`. Ganti dengan model ID video yang tersedia dari [halaman Models](/id/overview/models) atau [direktori model](https://www.cometapi.com/models/) sebelum Anda menjalankan request.
</Note>

<Tip>
  Buka [Create a Seedance video](/api/video/seedance/create) dan [Retrieve a Seedance video](/api/video/seedance/query) untuk menggunakan API playground dan skema endpoint.
</Tip>

<CodeGroup>
  ```python Python theme={null}
  import os
  import time
  import requests

  headers = {"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]}

  create_response = requests.post(
      "https://api.cometapi.com/v1/videos",
      headers=headers,
      data={
          "model": "your-video-model-id",
          "prompt": "A calm camera move across a desk with a paper airplane",
      },
      timeout=30,
  )
  create_response.raise_for_status()
  task = create_response.json()
  task_id = task["id"]

  terminal_statuses = {"completed", "failed", "error"}

  while True:
      poll_response = requests.get(
          f"https://api.cometapi.com/v1/videos/{task_id}",
          headers=headers,
          timeout=30,
      )
      poll_response.raise_for_status()
      result = poll_response.json()
      print(result["status"], result.get("progress"))

      if result["status"] in terminal_statuses:
          print(result.get("video_url"))
          break

      time.sleep(10)
  ```

  ```javascript Node.js theme={null}
  const form = new FormData();
  form.append("model", "your-video-model-id");
  form.append("prompt", "A calm camera move across a desk with a paper airplane");

  const createResponse = await fetch("https://api.cometapi.com/v1/videos", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
    },
    body: form,
  });

  if (!createResponse.ok) {
    throw new Error(await createResponse.text());
  }

  const task = await createResponse.json();
  const terminalStatuses = new Set(["completed", "failed", "error"]);

  while (true) {
    const pollResponse = await fetch(
      `https://api.cometapi.com/v1/videos/${task.id}`,
      {
        headers: {
          Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
        },
      },
    );

    if (!pollResponse.ok) {
      throw new Error(await pollResponse.text());
    }

    const result = await pollResponse.json();
    console.log(result.status, result.progress);

    if (terminalStatuses.has(result.status)) {
      console.log(result.video_url);
      break;
    }

    await new Promise((resolve) => setTimeout(resolve, 10_000));
  }
  ```

  ```bash cURL theme={null}
  curl https://api.cometapi.com/v1/videos \
    -H "Authorization: Bearer $COMETAPI_KEY" \
    -F "model=your-video-model-id" \
    -F "prompt=A calm camera move across a desk with a paper airplane"

  curl https://api.cometapi.com/v1/videos/task_example \
    -H "Authorization: Bearer $COMETAPI_KEY"
  ```
</CodeGroup>

## Contoh response

Response pembuatan yang berhasil dapat terlihat seperti ini. Simpan task ID sebelum melakukan polling:

```json theme={null}
{
  "id": "task_example",
  "task_id": "task_example",
  "object": "video",
  "model": "your-video-model-id",
  "status": "queued",
  "progress": 0,
  "created_at": 1779872000
}
```

Response polling yang berhasil dapat terlihat seperti ini. Response yang completed dapat menyertakan `video_url`; beberapa format provider menggunakan field hasil khusus model atau route konten video saat route tersebut didokumentasikan:

```json theme={null}
{
  "id": "task_example",
  "object": "video",
  "model": "your-video-model-id",
  "status": "completed",
  "progress": 100,
  "completed_at": 1779872300,
  "video_url": "https://example.com/generated-video.mp4"
}
```

## Contoh rekaman model

<Info>
  Respons katalog model contoh ini menampilkan envelope `/api/models` dan bentuk satu rekaman model video. Ini bukan daftar model yang lengkap.
</Info>

```bash cURL theme={null}
curl https://api.cometapi.com/api/models
```

```json theme={null}
{
  "success": true,
  "page": 1,
  "page_size": 20,
  "total": 302,
  "data": [
    {
      "created": 1767529753,
      "id": "your-video-model-id",
      "code": "your-video-model-id",
      "provider": "ExampleProvider",
      "provider_code": "example",
      "name": "Example video model",
      "model_type": "video",
      "features": [
        "text-to-video"
      ],
      "endpoints": "{\n  \"seedance\": {\n    \"path\": \"/v1/videos\",\n    \"method\": \"POST\"\n  }\n}",
      "pricing": {
        "currency": "USD / M Tokens",
        "input": null,
        "output": null,
        "per_request": null,
        "per_second": 0.024
      }
    }
  ]
}
```

## Error umum

<AccordionGroup>
  <Accordion title="Task ID hilang">
    Simpan ID dari respons pembuatan sebelum mengembalikan hasil dari job handler Anda.
  </Accordion>

  <Accordion title="Polling terlalu cepat">
    Tambahkan jeda dan backoff di antara pemeriksaan status.
  </Accordion>

  <Accordion title="Durasi atau ukuran tidak didukung">
    Gunakan field durasi dan resolusi yang didokumentasikan untuk endpoint video yang dipilih.
  </Accordion>

  <Accordion title="video_url hilang">
    Perlakukan `video_url` sebagai opsional dan gunakan field hasil khusus model atau content route jika tersedia.
  </Accordion>

  <Accordion title="Callback tidak diterima">
    Gunakan polling sebagai sumber kebenaran dan verifikasi bahwa URL callback Anda menerima permintaan POST.
  </Accordion>
</AccordionGroup>

## Kode error dan strategi retry

<AccordionGroup>
  <Accordion title="400">
    Jangan retry sampai field prompt, file, durasi, atau ukuran diperbaiki.
  </Accordion>

  <Accordion title="401">
    Jangan retry sampai API key tersedia dan valid.
  </Accordion>

  <Accordion title="404">
    Periksa task ID, base URL, path, dan model ID sebelum retry.
  </Accordion>

  <Accordion title="413">
    Kurangi ukuran upload sebelum retry.
  </Accordion>

  <Accordion title="429">
    Retry dengan exponential backoff dan kurangi konkurensi pembuatan atau polling.
  </Accordion>

  <Accordion title="500 or 503">
    Retry pembuatan task dengan backoff; tetap lakukan polling pada task yang sudah ada kecuali task mencapai error terminal.
  </Accordion>
</AccordionGroup>

<Tip>
  Untuk pola implementasi, lihat [Kode error dan strategi retry](/id/guides/error-codes-and-retry-strategy), [Rate limits dan konkurensi](/id/guides/rate-limits-and-concurrency), dan [Webhook dan polling untuk pembuatan video](/id/guides/webhook-and-polling-for-video-generation).
</Tip>

## Harga dan direktori model

<CardGroup cols={3}>
  <Card title="Halaman model" icon="list" href="/overview/models">
    Pelajari bagaimana CometAPI mengekspos model ID di dokumentasi.
  </Card>

  <Card title="Direktori model" icon="puzzle-piece" href="https://www.cometapi.com/models/">
    Telusuri ketersediaan dan kapabilitas model.
  </Card>

  <Card title="Harga" icon="tag" href="https://www.cometapi.com/pricing/">
    Periksa harga sebelum Anda memanggil model.
  </Card>
</CardGroup>
