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

# Kling 4.0

> 3-30 秒の出力、複数キーフレーム、Omni 参照に対応する Kling 4.0 の動画生成。

Kling 4.0 はテキスト、キーフレーム画像、Omni 参照による動画生成と編集に対応します。API の出力は現在 720p と 1080p で、4k は含みません。Kling 4.0 Flash は別の提供形態であり、このモデル ID の機能とは見なしません。

MixRoute の Bearer キーで認証します。kling-4.0 は URL パスに指定し、ボディの model には指定しません。prompt/contents、settings、options のネイティブ構造を維持し、metadata で囲まないでください。これらの対応は 4.0 の motion-control 対応を意味しません。

## モデル仕様

| フィールド | 説明 |
| - | - |
| `ID` | kling-4.0 |
| `POST` | [テキストから動画を生成](https://mixroute.ai/docs/ja/api-reference/endpoint/kling-text-to-video.md) / [画像から動画を生成](https://mixroute.ai/docs/ja/api-reference/endpoint/kling-image-to-video.md) / [Omni 参照と編集](https://mixroute.ai/docs/ja/api-reference/endpoint/kling-omni-video.md) |

## 共通設定とオプション

| フィールド | 説明 |
| - | - |
| `settings.resolution` | 720p または 1080p。プロバイダーの既定値は 1080p ですが、MixRoute では旧ゲートウェイの既定値に依存せず明示してください。 |
| `settings.duration` | 3-30 秒の整数。プロバイダーでは明示設定、プロンプトで指定した長さ、10 秒の順に決定します。Omni 編集では 10 秒の前に base\_video の長さを整数に丸めて使います。明示設定で曖昧さを避けてください。 |
| `options` | 共通オプションは options.callback\_url、options.external\_task\_id、options.watermark\_info.enabled です。独自タスク ID は MixRoute の照会 ID ではなく、冪等性も保証しません。 |

英語のみは最大 26,000 文字、非英語のみは最大 11,000 文字。混在時は `E / 26000 + N / 11000 <= 1` を満たします。動作の順序やカメラ移動をプロンプトに記述し、旧モデルの multi\_shot スイッチは使わないでください。 E は英語の文字数、N は非英語の文字数です。

> [!NOTE]
>
> 4.0 のテキスト・画像生成に audio や multi\_shot の切り替えはありません。settings.audio と settings.multi\_shot は省略し、旧モデルの audio=off を引き継がないでください。

## テキストから動画を生成

| フィールド | 説明 |
| - | - |
| `prompt` | 必須のトップレベル prompt。テキスト生成のエンドポイントにメディアは渡せません。 |
| `settings.aspect_ratio` | 21:9、16:9、9:16、1:1。プロバイダーの既定値は 16:9。テキスト生成に adaptive を指定しないでください。 |

MIXROUTE\_API\_KEY を設定し、example.com の画像 URL をアクセス可能な素材に置き換えてください。送信は一度だけ行い、タイムアウトをタスク未作成と判断しないでください。

```bash theme={null}
curl --request POST "https://api.mixroute.ai/kling/text-to-video/kling-4.0" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "prompt": "A red ceramic mug slowly rotates on a white tabletop. Static camera, soft studio lighting.",
  "settings": {
    "resolution": "720p",
    "duration": 3,
    "aspect_ratio": "16:9"
  }
}'
```

## 画像から動画を生成

prompt 項目と first\_frame、middle\_frame、last\_frame の画像項目を使います。画像には url を指定し、任意の一意な id を @id で参照できます。画像とプロンプト内の参照は時系列に並べてください。このスキーマに追加の timestamp フィールドはありません。

画像は最大 10 枚。JPG/JPEG/PNG、各 30 MB 以下、両辺 300 px 以上、縦横比 2:5-5:2。公開 URL または Base64 を指定します。画像生成に settings.aspect\_ratio はありません。動画、Element、音声参照は Omni を使います。

```bash theme={null}
curl --request POST "https://api.mixroute.ai/kling/image-to-video/kling-4.0" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "contents": [
    {
      "type": "prompt",
      "text": "The scene moves smoothly from @start through @middle to @end."
    },
    {
      "type": "first_frame",
      "id": "start",
      "url": "https://example.com/first-frame.png"
    },
    {
      "type": "middle_frame",
      "id": "middle",
      "url": "https://example.com/middle-frame.png"
    },
    {
      "type": "last_frame",
      "id": "end",
      "url": "https://example.com/last-frame.png"
    }
  ],
  "settings": {
    "resolution": "720p",
    "duration": 5
  }
}'
```

## Omni 参照と編集

prompt 項目が必須です。first\_frame、middle\_frame、last\_frame、refer\_image、feature\_video、base\_video、element、voice に対応します。画像・動画は url、Element は element\_id、声は voice\_id を使います。一意な id を @id で参照し、素材 ID は上流のルーティング先アカウントからアクセスできる必要があります。

element と voice の項目には、element\_id または voice\_id に加えて id も必要です。

Omni で middle\_frame または refer\_image が複数ある場合、画像 id が必須です。first\_frame、last\_frame、refer\_image を併用するときは、最初の画像を first\_frame、最後の画像を last\_frame にしてください。

| フィールド | 説明 |
| - | - |
| `settings.aspect_ratio` | 21:9、16:9、9:16、1:1、adaptive（プロバイダー既定）。明示比率が優先されます。adaptive はプロンプト、base\_video、キーフレーム、feature\_video の順で決定し、参照動画が複数ある場合や参照元がない場合は 16:9 になります。 |
| `settings.audio` | native（プロバイダー既定）または original。original には base\_video または feature\_video が必要で、voice 参照と併用できません。base\_video の音声を優先し、なければ最初の feature\_video を使います。off と multi\_shot は 4.0 の設定ではありません。 |

### メディアの制限

画像、動画、Element、声の合計は最大 15 件。画像は最大 10 枚。参照動画は動画キャラクター Element と合わせて最大 5 件。Element は最大 7 件、そのうち動画キャラクターは最大 3 件。声は最大 3 件、base\_video は最大 1 件です。

JPG/JPEG/PNG、1 枚あたり最大 30 MB、幅と高さはどちらも 300 px 以上、縦横比は 2:5 から 5:2 です。公開 URL または Base64 を指定します。

MP4/MOV、各 300 MB 以下。各動画と動画の合計時間は 3-30 秒で、動画キャラクター Element も合計に含みます。両辺 700-4553 px、総画素数 8,294,400 以下、縦横比 2:5-5:2。入力 24-60 fps、出力 24 fps。

```bash theme={null}
curl --request POST "https://api.mixroute.ai/kling/omni-video/kling-4.0" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --header "Content-Type: application/json" \
  --data '{
  "contents": [
    {
      "type": "prompt",
      "text": "A slow camera move around the ceramic mug in @mug on a white tabletop."
    },
    {
      "type": "refer_image",
      "id": "mug",
      "url": "https://example.com/mug.png"
    }
  ],
  "settings": {
    "resolution": "720p",
    "duration": 5,
    "aspect_ratio": "adaptive",
    "audio": "native"
  }
}'
```

## タスクの結果

HTTP ステータスと code=0 を確認し、作成時の data.id を保持して、その MixRoute タスク ID を 1 件ずつ照会します。succeeded 後に data\[0].outputs の type=video から URL を取得します。結果 CDN に API キーを送らないでください。

```bash theme={null}
curl --get "https://api.mixroute.ai/kling/tasks" \
  --header "Authorization: Bearer $MIXROUTE_API_KEY" \
  --data-urlencode "task_ids=$KLING_TASK_ID"
```

[タスクの結果](https://mixroute.ai/docs/ja/api-reference/endpoint/kling-tasks.md)

Kling 4.0 の上流課金は input\_duration と output\_duration を区別し、入力には参照動画と動画キャラクター Element が含まれます。ゲートウェイの usage は未返却または空の場合があります。outputs\[].duration だけで MixRoute の最終料金を計算したり、旧モデルの料金を適用したりせず、マーケットプレイスと請求を確認してください。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.