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

# Kling 3.0 Turbo 動画生成

>  - 非同期処理モード。後続のクエリ用にタスクIDを返します
- テキストから動画、画像から動画（最初のフレーム制御）に対応
- 720P / 1080P の2種類の解像度に対応
- 3〜15秒の動画長に対応
- マルチショット分割（固定フォーマットのプロンプトで表現）に対応 

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.apimart.ai/v1/videos/generations \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "kling-3.0-turbo",
      "prompt": "海辺を走るコーギー、映画のような雰囲気、夕暮れの光",
      "aspect_ratio": "16:9",
      "resolution": "1080p",
      "duration": 5
    }'
  ```

  ```python Python theme={null}
  import requests

  url = "https://api.apimart.ai/v1/videos/generations"

  payload = {
      "model": "kling-3.0-turbo",
      "prompt": "海辺を走るコーギー、映画のような雰囲気、夕暮れの光",
      "aspect_ratio": "16:9",
      "resolution": "1080p",
      "duration": 5
  }

  headers = {
      "Authorization": "Bearer <token>",
      "Content-Type": "application/json"
  }

  response = requests.post(url, json=payload, headers=headers)

  print(response.json())
  ```

  ```javascript JavaScript theme={null}
  const url = "https://api.apimart.ai/v1/videos/generations";

  const payload = {
    model: "kling-3.0-turbo",
    prompt: "海辺を走るコーギー、映画のような雰囲気、夕暮れの光",
    aspect_ratio: "16:9",
    resolution: "1080p",
    duration: 5
  };

  const headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
  };

  fetch(url, {
    method: "POST",
    headers: headers,
    body: JSON.stringify(payload)
  })
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));
  ```

  ```go Go theme={null}
  package main

  import (
      "bytes"
      "encoding/json"
      "fmt"
      "io/ioutil"
      "net/http"
  )

  func main() {
      url := "https://api.apimart.ai/v1/videos/generations"

      payload := map[string]interface{}{
          "model":        "kling-3.0-turbo",
          "prompt":       "海辺を走るコーギー、映画のような雰囲気、夕暮れの光",
          "aspect_ratio": "16:9",
          "resolution":   "1080p",
          "duration":     5,
      }

      jsonData, _ := json.Marshal(payload)

      req, _ := http.NewRequest("POST", url, bytes.NewBuffer(jsonData))
      req.Header.Set("Authorization", "Bearer <token>")
      req.Header.Set("Content-Type", "application/json")

      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()

      body, _ := ioutil.ReadAll(resp.Body)
      fmt.Println(string(body))
  }
  ```

  ```java Java theme={null}
  import java.net.http.HttpClient;
  import java.net.http.HttpRequest;
  import java.net.http.HttpResponse;
  import java.net.URI;

  public class Main {
      public static void main(String[] args) throws Exception {
          String url = "https://api.apimart.ai/v1/videos/generations";

          String payload = """
          {
            "model": "kling-3.0-turbo",
            "prompt": "海辺を走るコーギー、映画のような雰囲気、夕暮れの光",
            "aspect_ratio": "16:9",
            "resolution": "1080p",
            "duration": 5
          }
          """;

          HttpClient client = HttpClient.newHttpClient();
          HttpRequest request = HttpRequest.newBuilder()
              .uri(URI.create(url))
              .header("Authorization", "Bearer <token>")
              .header("Content-Type", "application/json")
              .POST(HttpRequest.BodyPublishers.ofString(payload))
              .build();

          HttpResponse<String> response = client.send(request,
              HttpResponse.BodyHandlers.ofString());

          System.out.println(response.body());
      }
  }
  ```

  ```php PHP theme={null}
  <?php

  $url = "https://api.apimart.ai/v1/videos/generations";

  $payload = [
      "model" => "kling-3.0-turbo",
      "prompt" => "海辺を走るコーギー、映画のような雰囲気、夕暮れの光",
      "aspect_ratio" => "16:9",
      "resolution" => "1080p",
      "duration" => 5
  ];

  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_POST, true);
  curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload));
  curl_setopt($ch, CURLOPT_HTTPHEADER, [
      "Authorization: Bearer <token>",
      "Content-Type: application/json"
  ]);

  $response = curl_exec($ch);
  curl_close($ch);

  echo $response;
  ?>
  ```

  ```ruby Ruby theme={null}
  require 'net/http'
  require 'json'
  require 'uri'

  url = URI("https://api.apimart.ai/v1/videos/generations")

  payload = {
    model: "kling-3.0-turbo",
    prompt: "海辺を走るコーギー、映画のような雰囲気、夕暮れの光",
    aspect_ratio: "16:9",
    resolution: "1080p",
    duration: 5
  }

  http = Net::HTTP.new(url.host, url.port)
  http.use_ssl = true

  request = Net::HTTP::Post.new(url)
  request["Authorization"] = "Bearer <token>"
  request["Content-Type"] = "application/json"
  request.body = payload.to_json

  response = http.request(request)
  puts response.body
  ```

  ```swift Swift theme={null}
  import Foundation

  let url = URL(string: "https://api.apimart.ai/v1/videos/generations")!

  let payload: [String: Any] = [
      "model": "kling-3.0-turbo",
      "prompt": "海辺を走るコーギー、映画のような雰囲気、夕暮れの光",
      "aspect_ratio": "16:9",
      "resolution": "1080p",
      "duration": 5
  ]

  var request = URLRequest(url: url)
  request.httpMethod = "POST"
  request.setValue("Bearer <token>", forHTTPHeaderField: "Authorization")
  request.setValue("application/json", forHTTPHeaderField: "Content-Type")
  request.httpBody = try? JSONSerialization.data(withJSONObject: payload)

  let task = URLSession.shared.dataTask(with: request) { data, response, error in
      if let error = error {
          print("Error: \(error)")
          return
      }

      if let data = data, let responseString = String(data: data, encoding: .utf8) {
          print(responseString)
      }
  }

  task.resume()
  ```

  ```csharp C# theme={null}
  using System;
  using System.Net.Http;
  using System.Text;
  using System.Threading.Tasks;

  class Program
  {
      static async Task Main(string[] args)
      {
          var url = "https://api.apimart.ai/v1/videos/generations";

          var payload = @"{
              ""model"": ""kling-3.0-turbo"",
              ""prompt"": ""海辺を走るコーギー、映画のような雰囲気、夕暮れの光"",
              ""aspect_ratio"": ""16:9"",
              ""resolution"": ""1080p"",
              ""duration"": 5
          }";

          using var client = new HttpClient();
          client.DefaultRequestHeaders.Add("Authorization", "Bearer <token>");

          var content = new StringContent(payload, Encoding.UTF8, "application/json");
          var response = await client.PostAsync(url, content);
          var result = await response.Content.ReadAsStringAsync();

          Console.WriteLine(result);
      }
  }
  ```
</RequestExample>

<ResponseExample>
  ```json 200 theme={null}
  {
    "code": 200,
    "data": [
      {
        "status": "submitted",
        "task_id": "task_xxxxxxxxxx"
      }
    ]
  }
  ```

  ```json 400 theme={null}
  {
    "error": {
      "code": 400,
      "message": "リクエストパラメータが無効です",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 401 theme={null}
  {
    "error": {
      "code": 401,
      "message": "認証に失敗しました。APIキーを確認してください",
      "type": "authentication_error"
    }
  }
  ```

  ```json 402 theme={null}
  {
    "error": {
      "code": 402,
      "message": "アカウント残高が不足しています。チャージ後に再試行してください",
      "type": "payment_required"
    }
  }
  ```

  ```json 429 theme={null}
  {
    "error": {
      "code": 429,
      "message": "リクエストが多すぎます。しばらくしてから再試行してください",
      "type": "rate_limit_error"
    }
  }
  ```

  ```json 500 theme={null}
  {
    "error": {
      "code": 500,
      "message": "サーバー内部エラーです。しばらくしてから再試行してください",
      "type": "server_error"
    }
  }
  ```
</ResponseExample>

## 認証

<ParamField header="Authorization" type="string" required>
  すべてのインターフェースで Bearer Token による認証が必要です

  API キーの取得：

  [API キー管理ページ](https://apimart.ai/keys) にアクセスして API キーを取得してください

  使用時にはリクエストヘッダーに追加します：

  ```
  Authorization: Bearer YOUR_API_KEY
  ```
</ParamField>

## リクエストパラメータ

<ParamField body="model" type="string" required>
  動画生成モデル名

  対応モデル：

  * `kling-3.0-turbo` - Kling 3.0 Turbo
</ParamField>

<ParamField body="prompt" type="string" required>
  テキストプロンプト

  上流の制限は 3072 文字以内、2500 文字以内を推奨します。

  例：`"海辺を走るコーギー、映画のような雰囲気、夕暮れの光"`
</ParamField>

<ParamField body="first_frame_image" type="string">
  **画像 URL** または **Base64** に対応。

  <Warning>
    最初のフレーム画像の上流制限：

    * 形式：`.jpg` / `.jpeg` / `.png`
    * サイズ：≤ 50MB
    * 幅・高さ：≥ 300px
    * アスペクト比：`1:2.5` \~ `2.5:1`
  </Warning>
</ParamField>

<ParamField body="aspect_ratio" type="string" default="16:9">
  動画のアスペクト比

  選択可能な値：

  * `16:9` - 横向き
  * `9:16` - 縦向き
  * `1:1` - 正方形

  デフォルト値：`16:9`

  <Note>
    **テキストから動画でのみ有効**。画像から動画の場合はこのフィールドは無効で、動画の比率は最初のフレーム画像によって決まります。
  </Note>
</ParamField>

<ParamField body="resolution" type="string" default="720p">
  動画の解像度

  選択可能な値：

  * `720p`
  * `1080p`

  デフォルト値：`720p`
</ParamField>

<ParamField body="duration" type="integer" default="5">
  動画の長さ（秒）

  値の範囲：3〜15（最短 3 秒、最長 15 秒）

  デフォルト値：`5`

  **⚠️ 注意：** 純粋な数値（例：`6`）を入力してください。引用符を付けるとエラーになります
</ParamField>

<ParamField body="watermark" type="boolean">
  ウォーターマークを追加するかどうか

  明示的に渡された場合のみ上流に送信されます。渡さない場合はウォーターマークは追加されません。
</ParamField>

## テキストから動画 vs 画像から動画

システムは `first_frame_image` が指定されているかどうかに応じて生成モードを**自動判定**します。最初のフレーム画像がある場合は画像から動画、ない場合はテキストから動画となり、ユーザーが明示的に宣言する必要はありません。

| パラメータ               | テキストから動画   | 画像から動画                     |
| ------------------- | ---------- | -------------------------- |
| `prompt`            | ✅ 必須       | ✅ 任意（空欄の場合は最初のフレーム画像のみで生成） |
| `first_frame_image` | ❌ 渡さない     | ✅ 必須                       |
| `aspect_ratio`      | ✅ 任意       | ❌ 無効（比率は最初のフレーム画像によって決まる）  |
| `resolution`        | ✅ 任意       | ✅ 任意                       |
| `duration`          | ✅ 任意（3〜15） | ✅ 任意（3〜15）                 |
| `watermark`         | ✅ 任意       | ✅ 任意                       |

## レスポンス

<ResponseField name="code" type="integer">
  レスポンスステータスコード。成功時は 200
</ResponseField>

<ResponseField name="data" type="array">
  返されるデータ配列

  <Expandable title="配列要素">
    <ResponseField name="status" type="string">
      タスクステータス。初回送信時は `submitted`
    </ResponseField>

    <ResponseField name="task_id" type="string">
      タスクの一意の識別子。タスクのステータスと結果のクエリに使用します
    </ResponseField>
  </Expandable>
</ResponseField>

## 使用シーン

### シーン 1：テキストから動画（1080P）

```json theme={null}
{
  "model": "kling-3.0-turbo",
  "prompt": "海辺を走るコーギー、映画のような雰囲気、夕暮れの光",
  "aspect_ratio": "16:9",
  "resolution": "1080p",
  "duration": 5
}
```

### シーン 2：テキストから動画（縦向き 720P）

```json theme={null}
{
  "model": "kling-3.0-turbo",
  "prompt": "東京・渋谷の交差点、雨の夜、濡れた地面に映るネオン、傘をさして行き交う人々",
  "aspect_ratio": "9:16",
  "resolution": "720p",
  "duration": 10
}
```

### シーン 3：画像から動画（最初のフレーム画像）

```json theme={null}
{
  "model": "kling-3.0-turbo",
  "prompt": "カメラがゆっくりとズームイン、人物が微笑む",
  "first_frame_image": "https://cdn.example.com/first.jpg",
  "resolution": "720p",
  "duration": 5
}
```

### シーン 4：最初のフレーム画像のみで動画生成（プロンプトなし）

```json theme={null}
{
  "model": "kling-3.0-turbo",
  "first_frame_image": "https://cdn.example.com/first.jpg",
  "resolution": "1080p",
  "duration": 5
}
```

### シーン 5：マルチショット分割（テキストから動画）

```json theme={null}
{
  "model": "kling-3.0-turbo",
  "prompt": "ショット 1,2,海辺をコーギーが走る；ショット 2,3,カメラがズームインして人物が微笑む；",
  "aspect_ratio": "16:9",
  "resolution": "1080p",
  "duration": 5
}
```

<Note>
  **タスク結果のクエリ**

  動画生成は非同期タスクです。送信後に `task_id` が返されます。[タスクステータスの取得](/ja/api-reference/tasks/status) インターフェースを使用して生成の進捗と結果をクエリしてください。
</Note>
