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

# Kling API hızlı başlangıç: CometAPI ile video oluşturun

> CometAPI üzerinden bir Kling metinden videoya görevi oluşturun, görev durumunu sorgulayın ve callback tabanlı tamamlamayı yönetin.

## Ne oluşturacaksınız

Bir Kling metinden videoya görevi gönderecek, döndürülen task ID değerini saklayacak, eşleşen Kling görev endpoint'ini sorgulayacak ve push bildirimleri için ne zaman `callback_url` ekleyeceğinize karar vereceksiniz.

## Ön koşullar

* `COMETAPI_KEY` içinde saklanan bir CometAPI API anahtarı
* `requests` ile Python 3.10+ veya Node.js 18+
* Polling için sunucu tarafı bir worker ya da webhook'lar için bir HTTPS callback endpoint'i

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

Aşağıdaki ile bir Kling metinden videoya görevi oluşturun:

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

Görevi aşağıdaki ile sorgulayın:

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

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şın.

<CodeGroup>
  ```bash cURL theme={null}
  curl https://api.cometapi.com/kling/v1/videos/text2video \
    -H "Authorization: Bearer $COMETAPI_KEY" \
    -H "Content-Type: application/json" \
    -d '{
      "prompt": "A small ceramic cup on a wooden table, steam rising in soft morning light",
      "model_name": "kling-v3",
      "mode": "std",
      "duration": "5",
      "sound": "off"
    }'

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

  ```python Python theme={null}
  import os
  import time

  import requests

  api_key = os.environ["COMETAPI_KEY"]
  headers = {
      "Authorization": f"Bearer {api_key}",
      "Content-Type": "application/json",
  }

  create_response = requests.post(
      "https://api.cometapi.com/kling/v1/videos/text2video",
      headers=headers,
      json={
          "prompt": "A small ceramic cup on a wooden table, steam rising in soft morning light",
          "model_name": "kling-v3",
          "mode": "std",
          "duration": "5",
          "sound": "off",
      },
      timeout=60,
  )
  create_response.raise_for_status()
  task_id = create_response.json()["data"]["task_id"]

  for _ in range(60):
      task_response = requests.get(
          f"https://api.cometapi.com/kling/v1/videos/text2video/{task_id}",
          headers={"Authorization": f"Bearer {api_key}"},
          timeout=30,
      )
      task_response.raise_for_status()
      task = task_response.json()["data"]
      if task["task_status"] in {"succeed", "failed"}:
          print(task)
          break
      time.sleep(5)
  else:
      raise TimeoutError("Kling task did not finish in time")
  ```

  ```javascript Node.js theme={null}
  const createResponse = await fetch(
    "https://api.cometapi.com/kling/v1/videos/text2video",
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        prompt: "A small ceramic cup on a wooden table, steam rising in soft morning light",
        model_name: "kling-v3",
        mode: "std",
        duration: "5",
        sound: "off",
      }),
    },
  );

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

  const created = await createResponse.json();
  const taskId = created.data.task_id;

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

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

    const task = (await taskResponse.json()).data;
    if (["succeed", "failed"].includes(task.task_status)) {
      console.log(task);
      break;
    }
    await new Promise((resolve) => setTimeout(resolve, 5000));
  }
  ```
</CodeGroup>

## Akış açıklaması

Kling video üretimi asenkron çalışır. Oluşturma endpoint’i bir `data.task_id` döndürür. `data.task_status` değeri `succeed` veya `failed` olana kadar `GET /kling/v1/videos/text2video/<task_id>` isteğiyle sorgulama yapın. Görev başarılı olduğunda, kalıcı erişime ihtiyacınız varsa tamamlanan varlık URL’sini `data.task_result` içinden alıp kendi depolamanıza kopyalayın.

Durum güncellemelerinin sizin kontrol ettiğiniz bir HTTPS endpoint’ine gönderilmesini istediğinizde `callback_url` ekleyin. Mutabakat ve kaçırılan callback teslimatları için polling’i kullanılabilir durumda tutun.

## Yaygın parametreler

| Parametre      | Kullanım                                                                                |
| -------------- | --------------------------------------------------------------------------------------- |
| `prompt`       | Video görevi için metin prompt’u.                                                       |
| `model_name`   | Kling model ID. Referans örnek `kling-v3` kullanır.                                     |
| `mode`         | Üretim modu. Daha yüksek maliyetli modları test etmeden önce `std` ile başlayın.        |
| `duration`     | Çıktı süresi. Referans sayfa ilk istek için `5` kullanır.                               |
| `sound`        | Desteklenen model izlerinde, deterministik ve sessiz bir ilk istek için `off` kullanın. |
| `callback_url` | Görev durumu callback’leri için isteğe bağlı HTTPS URL’si.                              |

## Sorun giderme / SSS

<AccordionGroup>
  <Accordion title="Yanıt yapısı OpenAI video route’larından farklı">
    Kling, `data.task_id`, `data.task_status` ve `data.task_result` gibi sağlayıcıya özgü JSON alanları kullanır. Bunu OpenAI uyumlu `/v1/videos` route’ları gibi ayrıştırmayın.
  </Accordion>

  <Accordion title="Görev hiçbir zaman succeed durumuna ulaşmıyor">
    Sınırlı polling kullanın ve bir görev başarısız olduğunda `data.task_status_msg` alanını inceleyin. Daha sonra tanılama yapabilmek için task ID’yi saklayın.
  </Accordion>

  <Accordion title="callback_url mı yoksa polling mi kullanmalıyım">
    Temel yaklaşım olarak polling kullanın. Push teslimatı için `callback_url` ekleyin, ardından son durumu polling ile mutabık hale getirin.
  </Accordion>
</AccordionGroup>

## Sonraki adımlar

* [Kling text-to-video API referansını](/api/video/kling/text-to-video) okuyun.
* [Get a Kling task](/api/video/kling/individual-queries) ile polling yapın.
* [Use Kling callback URLs](/api/video/kling/callback_url) ile callback’leri yapılandırın.
* [Models](/tr/overview/models) içinde Kling video modellerini bulun.
* [Use polling and webhooks for video generation](/tr/guides/webhook-and-polling-for-video-generation) sayfasını inceleyin.
* [Estimate request cost before calling a model](/tr/guides/how-to-estimate-cost-before-calling-a-model) ile model çağrısı yapmadan önce görev maliyetini tahmin edin.
