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

# Sora 2 API hızlı başlangıç: CometAPI ile videolar oluşturun

> CometAPI ile bir Sora 2 video işi oluşturun, durumu sorgulayın ve tamamlanan video içeriğini curl, Python veya Node.js ile indirin.

## Ne oluşturacaksınız

Bir Sora 2 video işi gönderecek, döndürülen video ID değerini saklayacak, iş tamamlanana kadar durumu sorgulayacak ve tamamlanan video içeriğini indireceksiniz.

## Önkoşullar

* `COMETAPI_KEY` içinde saklanan bir CometAPI API anahtarı
* `requests` ile Python 3.10+ veya Node.js 18+
* Polling için sunucu tarafında çalışan bir worker ya da iş kuyruğu

## API anahtarı, temel URL, kimlik doğrulama

Sora işleri oluşturmak için:

```text theme={null}
POST https://api.cometapi.com/v1/videos
```

Durumu sorgulamak için:

```text theme={null}
GET https://api.cometapi.com/v1/videos/<video_id>
```

Tamamlanan içeriği indirmek için:

```text theme={null}
GET https://api.cometapi.com/v1/videos/<video_id>/content
```

Bir Bearer token ile kimlik doğrulayın:

```text theme={null}
Authorization: Bearer $COMETAPI_KEY
```

## Kod örnekleri

Aşağıdaki sekmeleri kullanarak cURL, Python ve Node.js için kopyalanabilir örneklere ulaşabilirsiniz.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.cometapi.com/v1/videos \
    -H "Authorization: Bearer $COMETAPI_KEY" \
    -F model=sora-2 \
    -F "prompt=A paper boat drifts across a calm pond at sunrise" \
    -F seconds=4 \
    -F size=1280x720

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

  curl "https://api.cometapi.com/v1/videos/<video_id>/content" \
    -H "Authorization: Bearer $COMETAPI_KEY" \
    --output sora-result.mp4
  ```

  ```python Python theme={null}
  import os
  import time
  from pathlib import Path

  import requests

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

  create_response = requests.post(
      "https://api.cometapi.com/v1/videos",
      headers=headers,
      data={
          "model": "sora-2",
          "prompt": "A paper boat drifts across a calm pond at sunrise",
          "seconds": "4",
          "size": "1280x720",
      },
      timeout=60,
  )
  create_response.raise_for_status()
  video_id = create_response.json()["id"]

  for _ in range(60):
      status_response = requests.get(
          f"https://api.cometapi.com/v1/videos/{video_id}",
          headers=headers,
          timeout=30,
      )
      status_response.raise_for_status()
      status = status_response.json()
      if status["status"] == "completed":
          content_response = requests.get(
              f"https://api.cometapi.com/v1/videos/{video_id}/content",
              headers=headers,
              timeout=120,
          )
          content_response.raise_for_status()
          Path("sora-result.mp4").write_bytes(content_response.content)
          break
      if status["status"] == "failed":
          raise RuntimeError(status)
      time.sleep(5)
  else:
      raise TimeoutError("Sora job did not finish in time")
  ```

  ```javascript Node.js theme={null}
  import fs from "node:fs/promises";

  const form = new FormData();
  form.append("model", "sora-2");
  form.append("prompt", "A paper boat drifts across a calm pond at sunrise");
  form.append("seconds", "4");
  form.append("size", "1280x720");

  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 { id } = await createResponse.json();

  for (let attempt = 0; attempt < 60; attempt += 1) {
    const statusResponse = await fetch(`https://api.cometapi.com/v1/videos/${id}`, {
      headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` },
    });

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

    const status = await statusResponse.json();
    if (status.status === "completed") {
      const contentResponse = await fetch(
        `https://api.cometapi.com/v1/videos/${id}/content`,
        { headers: { Authorization: `Bearer ${process.env.COMETAPI_KEY}` } },
      );
      const videoBuffer = Buffer.from(await contentResponse.arrayBuffer());
      await fs.writeFile("sora-result.mp4", videoBuffer);
      break;
    }
    if (status.status === "failed") {
      throw new Error(JSON.stringify(status));
    }
    await new Promise((resolve) => setTimeout(resolve, 5000));
  }
  ```
</CodeGroup>

## Akış açıklaması

Sora üretimi asenkrondur. Oluşturma endpoint'i bir video ID ve başlangıç durumunu döndürür. `status` değeri `completed` veya `failed` olana kadar `GET /v1/videos/<video_id>` isteğini poll edin. İş tamamlandığında, dosyayı `GET /v1/videos/<video_id>/content` ile indirin.

Tam olarak `WxH` boyutlarını kullanın. Sora API referansı, standart yatay ve dikey boyutları ve Pro model iş akışları için daha büyük Pro boyutlarını belgeler.

## Yaygın parametreler

| Parametre         | Kullanım                                                                      |
| ----------------- | ----------------------------------------------------------------------------- |
| `model`           | Sora model ID. Referans örneği `sora-2` kullanır.                             |
| `prompt`          | Video için metin Prompt'u.                                                    |
| `seconds`         | Klip süresi. API referansı `4`, `8`, `12`, `16` ve `20` değerlerini belgeler. |
| `size`            | `1280x720` veya `720x1280` gibi tam `WxH` çıktı boyutu.                       |
| `input_reference` | İlk kare iş akışları için isteğe bağlı referans görsel dosyası.               |

## Sorun giderme / SSS

<AccordionGroup>
  <Accordion title="Oluşturma isteği başarısız oluyor">
    multipart form data kullanın. Referanstaki Sora oluşturma istekleri JSON body değil, form alanları kullanır.
  </Accordion>

  <Accordion title="İçerik indirme başarısız oluyor">
    İçeriği yalnızca durum endpoint'i `completed` bildirdikten sonra indirin. Tamamlanan dosyayı kendi depolamanızda saklayın.
  </Accordion>

  <Accordion title="Bir Pro boyutu çalışmıyor">
    Daha büyük Pro boyutlarını yalnızca bir Pro model iş akışıyla kullanın. İlk istek için `1280x720` ile başlayın.
  </Accordion>
</AccordionGroup>

## Sonraki adımlar

* [Create a Sora 2 video API reference](/api/video/sora-2/create) belgesini okuyun.
* [Retrieve a Sora 2 video](/api/video/sora-2/retrieve) ile yoklama yapın.
* [Retrieve Sora 2 video content](/api/video/sora-2/retrieve-content) ile indirin.
* [Models](/tr/overview/models) içinde kullanılabilir video modellerini bulun.
* [Use polling and webhooks for video generation](/tr/guides/webhook-and-polling-for-video-generation) belgesini inceleyin.
* [Estimate request cost before calling a model](/tr/guides/how-to-estimate-cost-before-calling-a-model) ile bir modeli çağırmadan önce görev maliyetini tahmin edin.
