> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.beatapi.io/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.beatapi.io/_mcp/server.

# Kling V4

POST https://api.beatapi.io/v1/videos/tasks
Content-Type: application/json

テキスト、時間順に並べたフレーム、または参照画像・参照動画・参照音声と名前付きのエレメントから、720p または 1080p、3～30 秒の音声付き動画を生成します。料金は秒単位です。- 非同期です。作成の呼び出しはタスク ID を返し、動画はタスクが成功した時点で得られます。
- 入力方法は 4 通りです。テキストのみ、フレーム（時間順に並べた `images`）、参照画像・参照動画・参照音声、そして名前付きの `elements`（最大 7 つ）です。フレームは参照素材やエレメントと組み合わせられません。
- プロンプトでは各入力をメンションで指定します。`@image_1`、`@video_1`、`@voice_1`、`@` とエレメント名、`@first_frame`、`@keyframe_1`、`@last_frame` です。すべての `@` は同じリクエストの入力を指す必要があります。
- 音声は常に生成されます。`keep_original_sound` を使うと、代わりに参照動画そのものの音声を残します。
- `duration` は 3～30 秒（デフォルト 5）、解像度は `720p`（デフォルト）または `1080p` です。料金は選んだ解像度での動画の秒数で決まり、失敗したタスクには課金されません。POST/v1/videos/tasks試してみるこのモデルをテスト画面で開きます。BeatAPI の API キーを入力するとタスクを作成できます。実際に呼び出され、ご自身の残高から課金されます。## モデル IDこのエンドポイントには Kling の生成モデルが 2 つあります。以下の値はゲートウェイの契約から直接取得しています。参照素材、3 枚以上のフレーム、最大 7 つのエレメントを受け付けるのは Kling V4 だけです。| モデル ID         | `duration`（秒） | `resolution`    | フレームの上限 | 参照画像の上限 | エレメントの上限 | 選ぶ場面                                                    |
| -------------- | ------------- | --------------- | ------- | ------- | -------- | ------------------------------------------------------- |
| **`kling-v4`** | 3–30          | `720p`, `1080p` | 10      | 10      | 7        | 最長 30 秒の動画、参照画像・参照動画・参照音声、中間フレーム、または 4 つ以上のエレメントが必要な場合。 |
| `kling-v3`     | 3–15          | `std`, `pro`    | 2       | —       | 3        | マルチショットのストーリーボード、音声なしの動画、またはより低い秒単価が必要な場合。              |## エンドポイントと認証`POST https://api.beatapi.io/v1/videos/tasks`Authorization
string
必須BeatAPI の API キーを `Bearer <BEATAPI_API_KEY>` の形式で送信します。キーは[ダッシュボード](https://beatapi.io/dashboard)で作成できます。キーはサーバー側で保管し、ブラウザーやモバイルアプリに含めないでください。ボディは JSON で送信し、`Content-Type: application/json` を指定します。`Idempotency-Key` は任意です。論理的に 1 件のリクエストごとに一意の値（255 文字以内）を送り、まったく同じボディを再試行するときだけ再利用してください。24 時間以内に同じキーと同じボディで再試行すると、最初のレスポンスが `Idempotent-Replayed: true` 付きで再度返されます。同じキーで異なるボディを送ると `409 idempotency_conflict` が返ります。2xx 以外のレスポンスは保存されないため、400 や 402 の後の再試行は改めて実行されます。## リクエストの流れ下記のパラメーターをエンドポイントに `POST` します。`201` が返れば、タスクが受け付けられ、料金が残高から仮確保されたことを意味します。処理はバックグラウンドで実行されます。`data.id` を保存してください。`GET /v1/tasks/{task_id}` を呼び出し、`status` が `succeeded` または `failed` になるまで、呼び出しの間隔を `data.poll_after_seconds`（画像は 5 秒、動画は 8 秒）だけ空けてください。あるいは `task.succeeded` と `task.failed` の[Webhook](/webhooks)を登録することもできます。処理タイムアウトで停止したタスクはイベントを送信しないため、フォールバックとしてポーリングも続けてください。`succeeded` の場合は、すべての `data.output.media[].url` をダウンロードし、必要なファイルを保存してください。結果 URL がいつまで利用できるかは保証されません。`failed` の場合は、`data.error_code` と `data.error_message` を確認してください。仮確保された金額は残高に戻されます。`data.retryable` は、同じリクエストをもう一度送れば成功する可能性があるかどうかを示します。## 入力モード| モード           | 必須の入力                                                                                          | 備考                                                               |
| ------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
| テキストから動画      | `model`、`prompt`                                                                               | メディアは送りません。`aspect_ratio` を省略すると 16:9 になります。                     |
| 開始フレーム        | `model`、`prompt`、`images`（リンク 1 個）                                                             | 動画はその画像から始まり、画像の形を引き継ぎます。                                        |
| 開始フレームと終了フレーム | `model`、`prompt`、`images`（リンク 2 個）                                                             | `images[0]` が開始フレーム、`images[1]` が終了フレームです。                       |
| 複数フレーム        | `model`、`prompt`、`images`（リンク 3～10 個）                                                          | 開始フレーム、中間フレーム、終了フレームを時間順に並べます。画像は動画の秒数より最大 1 枚多くまでです。            |
| 参照素材とエレメント    | `model`、`prompt`、および `reference_images`、`reference_videos`、`reference_audios`、`elements` のいずれか | 下記の上限内で自由に組み合わせられます。`images` とは組み合わせられません。各入力をプロンプトでメンションしてください。 |## リクエストパラメーターmodel
string
必須実行するモデルです。**値**：`kling-v4`**値が正しくない場合**- 指定がない場合：`"model" is required`
- 画像モデルをこのエンドポイントに送った場合：`"model" nano-banana-2 is served by POST /v1/images/tasks, not this endpoint`prompt
string
必須動画の中で起きること（被写体、動き、カメラワーク、スタイル、音）です。各入力は `@` のメンションで指定します。**長さ**：1–5000 文字- 長さは文字数で数えます（CJK 文字も 1 文字として数えます）。
- メンションの書き方：`reference_images` は `@image_1`、`@image_2` …、`reference_videos` は `@video_1` …、`reference_audios` は `@voice_1` …、エレメントは `@` に続けてその `name` を書きます。フレームは `@first_frame`、`@keyframe_1`、`@keyframe_2` … と `@last_frame` です。
- すべての `@` は同じリクエストの入力を指す必要があります。参照画像が 2 枚なのに `@image_3` と書く、画像が 1 枚なのに `@last_frame` と書くなど、対応する入力がない番号付きメンションやフレームのメンションは、タスク作成時に拒否されます。**値が正しくない場合**- 指定がない場合：`"prompt" is required`
- 空、または上限を超える長さの場合：`"prompt" has an unsupported length`
- リクエストに含まれない入力をメンションした場合：`the prompt names @image_3, which this request does not send`images
string[]
任意時間順に並べたフレームです。リンク 1 個は開始フレーム、2 個は開始フレームと終了フレームで、それ以上はその間に中間フレームを加えます。**要素数**：1–10  \
各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。- リンクが 3 個以上の場合、`images[0]` が開始フレーム、最後のリンクが終了フレームで、その間のリンクが中間フレームです。`images[1]` が `@keyframe_1`、`images[2]` が `@keyframe_2` というように続きます。
- 画像は動画の秒数より最大 1 枚多くまで（`duration` + 1。`duration` を省略した場合は 5 秒として数えます）で、どの場合も 10 枚を超えられません。
- フレームは `reference_images`、`reference_videos`、`reference_audios`、`elements`、`aspect_ratio` と一緒に送れません。動画は開始フレームの形を引き継ぎます。**値が正しくない場合**- リンクが 10 個を超える場合：`"images" accepts at most 10 items`
- リンクが `duration` + 1 個を超える場合（この例は 5 秒の動画に 7 個）：`Kling V4 takes at most 6 images for a 5-second video`
- いずれかの reference\_\* フィールドと組み合わせた場合：`Cannot combine "images" with reference inputs in one task`
- `elements` と組み合わせた場合：`Kling V4 cannot combine elements with images`
- `aspect_ratio` と組み合わせた場合：`Kling V4 takes the first frame's shape; do not send aspect_ratio with images`
- https\:// のリンクではない場合：`"images[0]" must be a public HTTPS URL`reference_images
string[]
任意動画の内容、キャラクター、商品、スタイルを導く画像です。プロンプトではリストの順に `@image_1`、`@image_2` … と書きます。**要素数**：1–10  \
各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。- `images` とは組み合わせられません。
- 参照素材とエレメントの合計 15 個の上限に含まれます。**値が正しくない場合**- 上限を超える場合：`"reference_images" accepts at most 10 items`
- 参照素材とエレメントが合計 15 個を超える場合：`Kling V4 takes at most 15 reference inputs and elements together`reference_videos
string[]
任意動き、カメラワーク、内容を取り入れる動画です。プロンプトではリストの順に `@video_1`、`@video_2` … と書きます。**要素数**：1–5  \
各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。- 各クリップは 2～30 秒、すべてのクリップの合計は 30 秒以内です。ゲートウェイはタスク作成前に各クリップを測定し、上限を外れたクリップはどれかを示したうえで拒否します。
- 参照動画と動画エレメントは合計 5 個までで、参照素材とエレメントの合計 15 個の上限にも含まれます。
- 完成した動画には生成された音声が付きます。`keep_original_sound: true` を送ると、参照動画そのものの音声を残します。**値が正しくない場合**- 上限を超える場合：`"reference_videos" accepts at most 5 items`
- クリップが 2 秒より短い、または 30 秒より長い場合：`reference_videos[0] is 35 seconds long; this model takes reference video of 2 to 30 seconds.`
- クリップの合計が 30 秒を超える場合：`The reference videos run 36 seconds in total; this model takes at most 30.`
- 参照動画と動画エレメントが合計 5 個を超える場合：`Kling V4 takes at most 5 reference videos and video elements together`reference_audios
string[]
任意動画で使う声です。プロンプトではリストの順に `@voice_1`、`@voice_2` … と書きます。**要素数**：1–3  \
各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。- `images` とは組み合わせられません。
- 参照素材とエレメントの合計 15 個の上限に含まれます。**値が正しくない場合**- 上限を超える場合：`"reference_audios" accepts at most 3 items`elements
object[]
任意キャラクター、動物、小道具、衣装、シーン、エフェクトなど、名前を付けた被写体を最大 7 つ定義します。それぞれ一度だけ定義し、プロンプトでは `@` に続けてその `name` を書きます。**要素数**：≤ 7- 最大 7 個のオブジェクトからなる配列です。各オブジェクトは次のキーだけを受け付けます。
- `elements[].name`（文字列、必須）：英字、数字、アンダースコア、漢字の 1～20 文字で、同じリクエスト内で大文字と小文字を区別せずに重複できません。`image_N`、`video_N`、`voice_N`、`keyframe_N`、`object_N`、`audio_N`、`first_frame`、`last_frame` は使えません。
- `elements[].element_input_urls`（文字列の配列）：エレメントを写した画像の公開 HTTPS リンク 2～4 個です。最初の画像がメインビューです。
- `elements[].element_input_video_urls`（文字列の配列）：キャラクターを写した 3～8 秒のワンショット動画の公開 HTTPS リンクをちょうど 1 個です。`element_input_urls` とはどちらか一方だけを送ります。
- `elements[].element_input_audio_urls`（文字列の配列、任意）：キャラクターのエレメントの声となる公開 HTTPS 音声リンクをちょうど 1 個です。
- `elements[].tag`（文字列、任意）：エレメントの種類です。動画エレメント、または声を持つエレメントはキャラクターである必要があります。`tag` を省略するか、`character` を送ってください。
- `elements[].description`（文字列、任意）：エレメントの説明で、最大 100 文字です。
- 動画エレメントは最大 3 個、`reference_videos` との合計は最大 5 個です。すべてのエレメントが参照素材とエレメントの合計 15 個の上限に含まれます。
- エレメントは `images` と一緒に送れません。**値が正しくない場合**- エレメントが 7 個を超える場合：`"elements" accepts at most 7 items`
- エレメントがオブジェクトではない場合：`"elements[0]" must be an object`
- エレメントに `name` がない場合：`"name" is required in "elements[0]"`
- `name` が空、または 20 文字を超える場合：`"elements[0].name" has an unsupported length`
- `name` に他の文字が含まれる、または予約名を使った場合：`elements[0].name "image_1" is not a name Kling V4 accepts`
- 同じ `name` が 2 回出てくる場合（大文字と小文字は区別しません）：`elements[1].name "Hero" is used twice`
- 画像と動画の両方がある、またはどちらもない場合：`elements[0] takes either element_input_urls or element_input_video_urls`
- 画像が 2 枚未満の場合：`"elements[0].element_input_urls" requires at least 2 item`
- 画像が 4 枚を超える場合：`"elements[0].element_input_urls" accepts at most 4 items`
- 動画エレメントの `tag` が `character` ではない場合：`elements[0] is a video element, which is always a character`
- `tag` が `character` ではないエレメントに声がある場合：`elements[0] has a voice, which only a character element takes`
- `tag` が一覧にない値の場合：`"elements[0].tag" must be one of: [character animal prop costume scene effect others]`
- `description` が 100 文字を超える場合：`"elements[0].description" has an unsupported length`
- エレメントが受け付けないキーがある場合：`field "start_time" is not supported in "elements[0]"`
- 動画エレメントが 3 個を超える場合：`Kling V4 takes at most 3 video elements`
- `images` と組み合わせた場合：`Kling V4 cannot combine elements with images`duration
integer
任意デフォルト: 5動画の長さ（秒、整数）です。課金はこの値に基づきます。**デフォルト**：`5`  \
**範囲**：3–30- 省略すると `5` が使われ、その分が課金されます。
- フレームを使う場合は画像の枚数の上限にもなります。最大 `duration` + 1 枚で、10 枚を超えられません。**値が正しくない場合**- 範囲外、整数ではない、または文字列として送った場合：`"duration" is outside its supported range`aspect_ratio
string
任意デフォルト: 16:9動画の形（幅:高さ）です。**指定できる値**：`16:9`, `9:16`, `1:1`, `21:9`  \
**デフォルト**：`16:9`- 省略すると `16:9` になります。
- `images` と一緒に送らないでください。動画は開始フレームの形を引き継ぎます。**値が正しくない場合**- 一覧にない値の場合：`"aspect_ratio" must be one of: [16:9 9:16 1:1 21:9]`
- `images` と一緒に送った場合：`Kling V4 takes the first frame's shape; do not send aspect_ratio with images`resolution
string
任意デフォルト: 720p出力解像度です。`1080p` は `720p` より秒単価が高くなります。**指定できる値**：`720p`, `1080p`  \
**デフォルト**：`720p`- 省略すると `720p` が使われ、その分が課金されます。
- このモデルでは 4K は使えません。**値が正しくない場合**- 一覧にない値の場合（例：`4K` や `pro`）：`"resolution" must be one of: [720p 1080p]`keep_original_sound
boolean
任意生成された音声の代わりに、参照動画そのものの音声を完成した動画に残します。- `reference_videos` と一緒の場合だけ有効です。参照動画なしで送ると、`false` であっても拒否されます。
- 省略すると、動画には生成された音声が付きます。音声をオフにするフィールドはありません。**値が正しくない場合**- true または false ではない場合：`"keep_original_sound" must be a boolean`
- `reference_videos` なしで送った場合：`"keep_original_sound" needs reference_videos`ゲートウェイはタスク作成前に、次の組み合わせも確認します。- `images` と参照メディアのフィールドは同時に使用できません。
- `images` は時間順に並べたフレームです。1 枚は開始フレーム、2 枚は開始フレームと終了フレームで、それ以上はその間に中間フレームを加えます。プロンプトではそれぞれ `@first_frame`、`@keyframe_1`、`@keyframe_2` … と `@last_frame` と書きます。
- 画像は動画の秒数より最大 1 枚多くまでで、どの場合も 10 枚を超えられません。
- プロンプトでは、`reference_images` を `@image_1`、`@image_2` …、`reference_videos` を `@video_1` …、`reference_audios` を `@voice_1` …、エレメントを `@` とその名前で指定します。プロンプト内のすべての `@` は、同じリクエストの入力を指す必要があります。
- 参照動画は各 2～30 秒、合計 30 秒までです。参照動画と動画エレメントは合計 5 個まで、そのうち動画エレメントは 3 個までです。`reference_images`、`reference_videos`、`reference_audios`、`elements` は合計 15 個までです。
- エレメントは、`element_input_urls` の画像 2～4 枚（1 枚目がメインビュー）か、`element_input_video_urls` の 3～8 秒のワンショットのキャラクター動画 1 本で構成します。`element_input_audio_urls` はキャラクターのエレメントに声を与えます。
- エレメント名は英字、数字、アンダースコア、漢字の 1～20 文字で、大文字と小文字を区別せずに重複できません。`image_N`、`video_N`、`voice_N`、`keyframe_N`、`object_N`、`audio_N`、`first_frame`、`last_frame` は使えません。
- `elements` と `aspect_ratio` は `images` と一緒に送れません。出力は開始フレームの形を引き継ぎます。`images` がない場合、`aspect_ratio` の既定値は 16:9 です。
- `keep_original_sound` は参照動画そのものの音声を残し、`reference_videos` が必要です。それ以外の場合、動画には生成された音声が付きます。## 入力メディアの上限ゲートウェイはタスク作成前にすべての入力を読み取り、次の上限を超えるものは、その入力を示す `400 bad_request` で拒否します。課金はされません。| メディア | タスク作成前に確認される上限                            |
| ---- | ----------------------------------------- |
| 画像   | 幅・高さとも 300～65536 px；アスペクト比（幅 ÷ 高さ）0.4～2.5 |
| 動画   | 1 本あたり 2～30 秒；合計 30 秒以内                   |- ゲートウェイはタスク作成前に `images`、`reference_images`、`reference_videos` を測定し、上限を外れた入力を、リストと位置を示すメッセージで拒否します。例：`reference_videos[0] is 35 seconds long; this model takes reference video of 2 to 30 seconds.` 課金はされません。
- エレメントのリンクと `reference_audios` については、タスク作成前には公開 HTTPS リンクかどうかだけを確認します。エレメントの動画は 3～8 秒である必要があります。
- ローカルのファイルを使う場合は、`POST /v1/files` でアップロードし、返された `data.url` を渡してください。## プロンプトのメンション入力の種類ごとにメンションがあり、リストの順に 1 から番号を付けます。| メンション                         | 指す入力                  | 使える条件                   |
| ----------------------------- | --------------------- | ----------------------- |
| `@image_1`、`@image_2` …       | `reference_images`    | その番号以上の枚数の参照画像を送っている    |
| `@video_1`、`@video_2` …       | `reference_videos`    | その番号以上の本数の参照動画を送っている    |
| `@voice_1`、`@voice_2` …       | `reference_audios`    | その番号以上の数の参照音声を送っている     |
| `@` + エレメント名                  | 同じ `name` のエレメント      | そのエレメントが `elements` にある |
| `@first_frame`                | `images[0]`           | 画像を 1 枚以上送っている          |
| `@keyframe_1`、`@keyframe_2` … | `images[1]` 以降の中間フレーム | 画像を 3 枚以上送っている          |
| `@last_frame`                 | `images` の最後のリンク      | 画像を 2 枚以上送っている          |- 対応する入力がない番号付きメンションやフレームのメンションは、タスク作成時に拒否されます。例：`the prompt names @last_frame, which this request does not send`## 組み合わせのルール以下はタスク作成時に確認されます。いずれかに違反したリクエストは `400 bad_request` で拒否され、課金されません。| ルール                                          | メッセージ                                                                          |
| -------------------------------------------- | ------------------------------------------------------------------------------ |
| `images` といずれかの `reference_*` フィールド          | `Cannot combine "images" with reference inputs in one task`                    |
| `images` と `elements`                        | `Kling V4 cannot combine elements with images`                                 |
| `images` と `aspect_ratio`                    | `Kling V4 takes the first frame's shape; do not send aspect_ratio with images` |
| 画像が `duration` + 1 枚を超える（この例は 5 秒の動画）        | `Kling V4 takes at most 6 images for a 5-second video`                         |
| `reference_videos` なしの `keep_original_sound` | `"keep_original_sound" needs reference_videos`                                 |
| 動画エレメントが 3 個を超える                             | `Kling V4 takes at most 3 video elements`                                      |
| 参照動画と動画エレメントが合計 5 個を超える                      | `Kling V4 takes at most 5 reference videos and video elements together`        |
| 参照画像、参照動画、参照音声、エレメントが合計 15 個を超える             | `Kling V4 takes at most 15 reference inputs and elements together`             |## このモデルが受け付けないフィールド次のフィールドを送ると、無視されるのではなく、課金前に拒否されます。- `sound`、`generate_audio`、`seed`、`multi_shots`、`multi_prompt`、`quality`、`watermark`、`task_type`、`output_format` → `field "sound" is not supported by model kling-v4`（送ったフィールド名が入ります）。
- その他の不明なフィールド → `unknown field: <name>`。## リクエスト例```bash title="cURL"
curl --request POST \
  --url https://api.beatapi.io/v1/videos/tasks \
  --header "Authorization: Bearer $BEATAPI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "kling-v4",
  "prompt": "A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone",
  "duration": 5,
  "aspect_ratio": "16:9",
  "resolution": "720p"
}'
``````python title="Python"
import os
import requests

response = requests.post(
    "https://api.beatapi.io/v1/videos/tasks",
    headers={"Authorization": f"Bearer {os.environ['BEATAPI_API_KEY']}"},
    json={
      "model": "kling-v4",
      "prompt": "A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone",
      "duration": 5,
      "aspect_ratio": "16:9",
      "resolution": "720p"
    },
    timeout=60,
)
body = response.json()
if not response.ok:
    raise RuntimeError(f"{response.status_code} {body['error']['code']}: {body['error']['message']}")
task = body["data"]
print(task["id"], task["status"])
``````javascript title="JavaScript"
const response = await fetch('https://api.beatapi.io/v1/videos/tasks', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.BEATAPI_API_KEY}`,
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    "model": "kling-v4",
    "prompt": "A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone",
    "duration": 5,
    "aspect_ratio": "16:9",
    "resolution": "720p"
  }),
});
const body = await response.json();
if (!response.ok) throw new Error(`${response.status} ${body.error.code}: ${body.error.message}`);
console.log(body.data.id, body.data.status);
```### テキストから動画生成音声付きの 5 秒、16:9、720p のクリップです。```bash
curl --request POST \
  --url https://api.beatapi.io/v1/videos/tasks \
  --header "Authorization: Bearer $BEATAPI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "kling-v4",
  "prompt": "A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone",
  "duration": 5,
  "aspect_ratio": "16:9",
  "resolution": "720p"
}'
```### 開始フレームと終了フレーム1080p で 1 枚目の画像から 2 枚目の画像へ移り、開始フレームの形を引き継ぎます。```bash
curl --request POST \
  --url https://api.beatapi.io/v1/videos/tasks \
  --header "Authorization: Bearer $BEATAPI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "kling-v4",
  "prompt": "The camera moves from the bottle in @first_frame to the singer on a neon stage in @last_frame in one continuous shot",
  "images": [
    "https://media.beatapi.io/samples/smart-bottle.png",
    "https://media.beatapi.io/samples/neon-singer.png"
  ],
  "duration": 5,
  "resolution": "1080p"
}'
```### 参照画像と声参照画像 2 枚と声 1 つを使い、それぞれをプロンプトでメンションします。```bash
curl --request POST \
  --url https://api.beatapi.io/v1/videos/tasks \
  --header "Authorization: Bearer $BEATAPI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "kling-v4",
  "prompt": "The singer from @image_1 lifts the bottle from @image_2 toward the camera and says a short line in the voice of @voice_1",
  "reference_images": [
    "https://media.beatapi.io/samples/neon-singer.png",
    "https://media.beatapi.io/samples/smart-bottle.png"
  ],
  "reference_audios": [
    "https://media.beatapi.io/samples/neon-singer-preview.mp3"
  ],
  "duration": 8,
  "aspect_ratio": "9:16",
  "resolution": "720p"
}'
```### 元の音声を残す参照動画プレースホルダーを 2～30 秒の自分のクリップに置き換えてください。`keep_original_sound` で、生成音声の代わりにその音声を残します。```bash
curl --request POST \
  --url https://api.beatapi.io/v1/videos/tasks \
  --header "Authorization: Bearer $BEATAPI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "kling-v4",
  "prompt": "Restyle @video_1 as a neon-lit night scene and keep its camera movement",
  "reference_videos": [
    "https://your-cdn.example.com/clips/source.mp4"
  ],
  "keep_original_sound": true,
  "duration": 10,
  "resolution": "720p"
}'
```### 名前付きのエレメントキャラクターと小道具を、それぞれ 2 枚の画像（1 枚目がメインビュー）で定義します。プレースホルダーのリンクは自分の画像に置き換えてください。```bash
curl --request POST \
  --url https://api.beatapi.io/v1/videos/tasks \
  --header "Authorization: Bearer $BEATAPI_API_KEY" \
  --header 'Content-Type: application/json' \
  --data '{
  "model": "kling-v4",
  "prompt": "@singer walks across a neon stage holding @bottle and smiles at the camera",
  "duration": 6,
  "aspect_ratio": "16:9",
  "resolution": "720p",
  "elements": [
    {
      "name": "singer",
      "tag": "character",
      "description": "A performer in a silver jacket",
      "element_input_urls": [
        "https://your-cdn.example.com/elements/singer-front.png",
        "https://your-cdn.example.com/elements/singer-side.png"
      ]
    },
    {
      "name": "bottle",
      "tag": "prop",
      "element_input_urls": [
        "https://your-cdn.example.com/elements/bottle-front.png",
        "https://your-cdn.example.com/elements/bottle-back.png"
      ]
    }
  ]
}'
```## レスポンス### タスクの作成（201）タスクオブジェクトです。タスクが成功するまで `output` は `null` です。「実行中」と記載されたフィールドは、タスクの完了後に表示されなくなります。```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "video",
    "capability_id": "kling-v4",
    "capability_version": 1,
    "media_type": "video",
    "model": "kling-v4",
    "status": "queued",
    "stage": "queued",
    "created_at": 1791993600,
    "updated_at": 1791993600,
    "completed_at": null,
    "poll_after_seconds": 8,
    "output": null,
    "usage": {
      "credits_reserved": 1,
      "credits_settled": 0,
      "credits_refunded": 0,
      "credits_charged": 1,
      "billable_duration_seconds": 5
    },
    "request_id": "req_5f0c2a9e4b7d4e31",
    "error_code": null,
    "error_message": null
  }
}
```| フィールド                                  | 型                 | 説明                                                                                            |
| -------------------------------------- | ----------------- | --------------------------------------------------------------------------------------------- |
| `data.id`                              | `string`          | タスク ID です。`task_` の後に英数字 32 文字が続きます。ポーリングや Webhook イベントとの照合に使います。                             |
| `data.object`                          | `string`          | 常に `task` です。                                                                                 |
| `data.task_kind`                       | `string`          | `image` または `video` です。                                                                       |
| `data.capability_id`                   | `string`          | 送信したモデル ID です。                                                                                |
| `data.capability_version`              | `integer`         | モデルの仕様バージョンです。現在は `1` です。                                                                     |
| `data.media_type`                      | `string`          | `image` または `video` です。                                                                       |
| `data.model`                           | `string`          | 送信したモデル ID です（`capability_id` と同じ）。                                                           |
| `data.status`                          | `string`          | `queued`、`processing`、`succeeded`、`failed` のいずれかです。最終状態は後ろの 2 つだけです。                          |
| `data.stage`                           | `string`          | `status` と同じ値です。古いクライアント向けに残されています。                                                           |
| `data.created_at`                      | `integer`         | タスクの作成日時（Unix 秒）です。                                                                           |
| `data.updated_at`                      | `integer`         | 最終更新日時（Unix 秒）です。                                                                             |
| `data.completed_at`                    | `integer \| null` | タスクの完了日時（Unix 秒）です。実行中は `null` です。                                                            |
| `data.poll_after_seconds`              | `integer`         | 実行中のみ。次のポーリングまでに待つ秒数です（画像は 5、動画は 8）。                                                          |
| `data.typical_seconds`                 | `object`          | 実行中のみ、直近のタスクが十分にある場合に含まれます。直近 `window` の `samples` 件のタスクについて、完了までの時間（秒）の `p50` と `p90` を示します。 |
| `data.output`                          | `object \| null`  | 結果です。`status` が `succeeded` になるまでは `null` です。下の出力フィールドを参照してください。                              |
| `data.usage.credits_reserved`          | `number`          | タスク作成時に残高から仮確保された金額（USD）です。                                                                   |
| `data.usage.credits_charged`           | `number`          | このタスクの料金（USD）です。失敗したタスクでは `0` です。                                                             |
| `data.usage.credits_settled`           | `number`          | 最終的に差し引かれた金額（USD）です。タスクが成功した時点で設定され、それ以外では `0` です。                                            |
| `data.usage.credits_refunded`          | `number`          | 残高に戻された金額（USD）です。失敗したタスクでは、返金が記録された時点で仮確保した金額と一致します。                                          |
| `data.usage.billable_duration_seconds` | `integer`         | 動画のみ。料金の算定に使われた秒数です。モデルが長さを報告しない場合は含まれません。                                                    |
| `data.request_id`                      | `string`          | リクエスト ID です。サポートに問い合わせる際に添えてください。                                                             |
| `data.error_code`                      | `string \| null`  | 失敗コードです。タスクが失敗した場合以外は `null` です。                                                              |
| `data.error_message`                   | `string \| null`  | 何が問題で、何を変更すればよいかを示します。タスクが失敗した場合以外は `null` です。                                                |### 完了したタスク`GET /v1/tasks/{task_id}` は HTTP 200 と `status: "succeeded"` を返し、結果は `data.output` に入ります。```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "video",
    "capability_id": "kling-v4",
    "capability_version": 1,
    "media_type": "video",
    "model": "kling-v4",
    "status": "succeeded",
    "stage": "succeeded",
    "created_at": 1791993600,
    "updated_at": 1791993690,
    "completed_at": 1791993690,
    "output": {
      "media": [
        {
          "type": "video",
          "url": "https://media.beatapi.io/outputs/task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ/0.mp4",
          "mime_type": "video/mp4"
        }
      ],
      "r2_url": "https://media.beatapi.io/outputs/task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ/0.mp4"
    },
    "usage": {
      "credits_reserved": 1,
      "credits_settled": 1,
      "credits_refunded": 0,
      "credits_charged": 1,
      "billable_duration_seconds": 5
    },
    "request_id": "req_5f0c2a9e4b7d4e31",
    "error_code": null,
    "error_message": null
  }
}
```#### 出力フィールド| フィールド                      | 型          | 説明                                                   |
| -------------------------- | ---------- | ---------------------------------------------------- |
| `output.media`             | `object[]` | 生成されたファイルです。このモデルでは動画が 1 本です。                        |
| `output.media[].type`      | `string`   | 常に `video` です。                                       |
| `output.media[].url`       | `string`   | 保存された動画への HTTPS リンクです。ダウンロードして保管してください。保持期間は保証されません。 |
| `output.media[].mime_type` | `string`   | ファイルのメディアタイプです。通常は `video/mp4` です。                   |
| `output.r2_url`            | `string`   | 古いクライアント向けに、動画の URL を再掲したものです。代わりに `media` を読んでください。 |### 失敗したタスク失敗したタスクも、`GET /v1/tasks/{task_id}` では HTTP 200 になります。失敗はボディに示されます。仮確保された金額は全額戻されるため、課金されません。```json
{
  "data": {
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "object": "task",
    "task_kind": "video",
    "capability_id": "kling-v4",
    "capability_version": 1,
    "media_type": "video",
    "model": "kling-v4",
    "status": "failed",
    "stage": "failed",
    "created_at": 1791993600,
    "updated_at": 1791993690,
    "completed_at": 1791993690,
    "output": null,
    "usage": {
      "credits_reserved": 1,
      "credits_settled": 0,
      "credits_refunded": 1,
      "credits_charged": 0,
      "billable_duration_seconds": 5
    },
    "retryable": true,
    "request_id": "req_5f0c2a9e4b7d4e31",
    "error_code": "processing_failed",
    "error_message": "The task failed during processing on our side. Retry; a failed task is refunded."
  }
}
```| フィールド                | 型         | 説明                                                                                                                                                                                                         |
| -------------------- | --------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `data.error_code`    | `string`  | `bad_request` と `content_policy_violation`（リクエストを修正してください）、または `processing_unavailable`、`processing_timeout`、`processing_failed`、`result_transfer_failed`（時間をおいて再試行してください）のいずれかです。[エラー](/errors)を参照してください。 |
| `data.error_message` | `string`  | 問題と対処方法を示す文です。                                                                                                                                                                                             |
| `data.retryable`     | `boolean` | 失敗したタスクにのみ含まれます。同じリクエストをもう一度送れば成功する可能性がある場合は `true` です。                                                                                                                                                    |
| `data.usage`         | `object`  | 返金が記録された時点（通常はタスクが失敗した瞬間）で、`credits_charged` と `credits_settled` は `0` になり、`credits_refunded` は `credits_reserved` と一致します。                                                                                 |## 完全なコード例タスクを作成し、サーバーが示すポーリング間隔で完了を待ち、結果の URL を出力します。環境変数に `BEATAPI_API_KEY` を設定し、`requests` をインストールしてください。```python
import os
import time
import uuid

import requests

API = "https://api.beatapi.io"
HEADERS = {"Authorization": f"Bearer {os.environ['BEATAPI_API_KEY']}"}


def create_task(body: dict) -> dict:
    # One Idempotency-Key per logical request: a retry with the same key cannot create a second task.
    headers = {**HEADERS, "Idempotency-Key": str(uuid.uuid4())}
    for attempt in range(3):
        response = requests.post(f"{API}/v1/videos/tasks", headers=headers, json=body, timeout=60)
        if response.status_code in (429, 503) and attempt < 2:
            time.sleep(int(response.headers.get("Retry-After", 10)))
            continue
        break
    try:
        payload = response.json()
    except ValueError:  # an edge error page is not JSON
        response.raise_for_status()
        raise
    if not response.ok:
        error = payload["error"]
        raise RuntimeError(f"{response.status_code} {error['code']}: {error['message']} (request_id={error.get('request_id')})")
    return payload["data"]


def wait_for_task(task_id: str, timeout_seconds: int = 1800) -> dict:
    deadline = time.monotonic() + timeout_seconds
    while time.monotonic() < deadline:
        response = requests.get(f"{API}/v1/tasks/{task_id}", headers=HEADERS, timeout=30)
        if response.status_code == 429 or response.status_code >= 500:
            time.sleep(int(response.headers.get("Retry-After", 10)))
            continue
        response.raise_for_status()
        task = response.json()["data"]
        if task["status"] in ("succeeded", "failed"):
            return task
        time.sleep(task.get("poll_after_seconds", 5))
    raise TimeoutError(f"task {task_id} is still running; keep polling later")


task = create_task({
  "model": "kling-v4",
  "prompt": "A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone",
  "duration": 5,
  "aspect_ratio": "16:9",
  "resolution": "720p"
})
print("created", task["id"])
task = wait_for_task(task["id"])
if task["status"] == "failed":
    raise SystemExit(f"{task['error_code']}: {task['error_message']}")
for item in task["output"]["media"]:
    print(item["url"])
```## 課金- 料金は、選んだ解像度での動画の秒数で決まります。`720p` は 1 秒あたり $0.20、`1080p` は 1 秒あたり $0.30 です。下の一覧は 8 秒のクリップの料金です。
- 秒数は `duration` で、省略すると 5 です。タスクの `usage.billable_duration_seconds` に表示されます。
- どの動画にも音声（生成された音声、または残した参照動画の音声）が付き、追加料金はかかりません。
- 料金はタスクの作成時に予約され、動画の完成時に確定します。失敗したタスク（送信後にモデレーションで拒否されたものを含む）は全額返金されます。現在の定価です。[料金](https://beatapi.io/pricing)ページと同じ金額です。割引を個別に契約しているアカウントでは、より低い金額になります。実際に課金された金額は、タスクの `data.usage` で確認できます。| オプション       | 定価（USD） |
| ----------- | ------- |
| 8 秒 · 720p  | \$1.6   |
| 8 秒 · 1080p | \$2.4   |## よくあるエラー| エラーまたは症状                                                                                           | 原因                                                                                   | 対処                                                                     |
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------- |
| 400 `the prompt names @image_3, which this request does not send`                                  | 参照画像が 2 枚なのに 3 枚目を指すなど、リクエストに含まれない入力をメンションしています。                                     | すべての `@` を同じリクエストの入力に対応させてください。番号はリストの順に 1 から数えます。                     |
| 400 `Cannot combine "images" with reference inputs in one task`                                    | `images` のフレームを、`reference_images`、`reference_videos`、`reference_audios` と一緒に送っています。 | フレームか参照素材のどちらか一方を使ってください。フレームとしてではなく動画を導く画像は `reference_images` に入れます。 |
| 400 `Kling V4 cannot combine elements with images`                                                 | `elements` をフレームと一緒に送っています。                                                          | `images` か `elements` のどちらかを削除してください。                                  |
| 400 `Kling V4 takes the first frame's shape; do not send aspect_ratio with images`                 | `aspect_ratio` をフレームと一緒に送っています。                                                      | `aspect_ratio` を削除し、開始フレームを希望の形に切り抜いてください。                             |
| 400 `Kling V4 takes at most 6 images for a 5-second video`                                         | フレームが `duration` + 1 枚を超えています。                                                       | フレームを減らすか、`duration` を長くしてください。どの場合も 10 枚が上限です。                        |
| 400 `elements[0] takes either element_input_urls or element_input_video_urls`                      | エレメントに画像と動画の両方がある、またはどちらもありません。                                                      | 各エレメントには、画像 2～4 枚か、キャラクター動画 1 本を指定してください。                              |
| 400 `"elements[0].element_input_urls" requires at least 2 item`                                    | エレメントの画像が 1 枚しかありません。                                                                | エレメントの画像を 2～4 枚送り、メインビューを 1 枚目にしてください。                                 |
| 400 `elements[0].name "image_1" is not a name Kling V4 accepts`                                    | 名前に英字、数字、アンダースコア、漢字以外の文字が含まれている、または `image_1` や `first_frame` のような予約名です。             | `singer` や `hero_bottle` のような名前に変え、その名前でメンションしてください。                   |
| 400 `"keep_original_sound" needs reference_videos`                                                 | `reference_videos` なしで `keep_original_sound` を送っています。                                | このフィールドを削除するか、音声を残したい参照動画を追加してください。                                    |
| 400 `reference_videos[0] is 35 seconds long; this model takes reference video of 2 to 30 seconds.` | 参照クリップが 2 秒より短い、または 30 秒より長いです。すべてのクリップの合計は 30 秒までです。                                | クリップを必要な部分だけに切り詰めてください。                                                |
| 400 `field "sound" is not supported by model kling-v4`                                             | 音声は常に生成され、音声のオン・オフを切り替える設定はありません（`generate_audio`、`seed`、`multi_shots` も拒否されます）。     | そのフィールドを削除してください。参照動画の音声を残すには `keep_original_sound: true` を送ります。       |
| 400 `"resolution" must be one of: [720p 1080p]`                                                    | `4K`、または `pro` のような区分名を送っています。                                                       | `720p` または `1080p` を送ってください。                                           |
| 400 `"duration" is outside its supported range`                                                    | 3～30 の整数ではない、または文字列として送っています。                                                        | `5` のような整数を送ってください。                                                    |
| タスクが `failed` になり、`content_policy_violation` が返る                                                   | プロンプト、入力、または生成結果がモデレーションで拒否されました。                                                    | プロンプトまたは入力を変更してください。そのまま再試行しても再び失敗します。課金はされません。                        |
| 402 `insufficient_credits`                                                                         | 残高が、この長さと解像度の予約額を下回っています。                                                            | チャージするか、`duration` を短くするか、`720p` を使ってください。                             |## HTTP エラー早見表タスクが作られる前のエラーは、2xx 以外のレスポンスで返されます。課金はされません。`error.code` または `error.retryable` で処理を分岐してください。`message` には問題の内容が示されます。全一覧と再試行のルールは[エラー](/errors)にあります。```json
{
  "error": {
    "code": "bad_request",
    "message": "\"prompt\" is required",
    "retryable": false,
    "request_id": "req_5f0c2a9e4b7d4e31"
  }
}
```| HTTP ステータス | `error.code`                                                                                  | 対処方法                                                                             |
| ---------- | --------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| 400        | `bad_request`, `content_policy_violation`                                                     | リクエストを修正してください。メッセージにフィールド名が示されます。そのまま再試行しないでください。                               |
| 401        | `missing_api_key`, `invalid_api_key`（古いクライアントでは `unauthorized` が返ることがあります）                    | 有効なキーを `Authorization: Bearer <key>` で送信してください。                                  |
| 402        | `insufficient_credits`                                                                        | 残高をチャージするか、キーのクォータを引き上げてから、再度送信してください。                                           |
| 403        | `forbidden`                                                                                   | このキーまたはアカウントでは、このモデルを利用できない可能性があります（たとえば、無料クレジットは一部のモデルにのみ使えます）。そのまま再試行しないでください。 |
| 404        | `not_found`                                                                                   | `GET /v1/tasks/{task_id}` の場合：このキーのアカウントに該当するタスクが存在しません。ID を確認してください。            |
| 409        | `idempotency_conflict`                                                                        | 新しい `Idempotency-Key` を使うか、同じキーの最初のリクエストが完了するまで待ってください。                          |
| 429        | `rate_limit_exceeded`                                                                         | `Retry-After` の秒数（`error.retry_after_seconds` にも含まれます）だけ待ってから再試行してください。          |
| 500        | `internal_error`                                                                              | バックオフを入れて再試行してください。解消しない場合は、`request_id` を添えてサポートにお問い合わせください。                    |
| 503        | `processing_unavailable`, `processing_timeout`, `processing_failed`, `result_transfer_failed` | 課金はされていません。指数バックオフで再試行してください。                                                    |

Reference: https://docs.beatapi.io/api-reference/video-api/kling-v4

## Authentication

- `Authorization` header (bearer token, required) — Send your API key as `Authorization: Bearer <BEATAPI_API_KEY>`.

## Servers

- `https://api.beatapi.io` (Direct, default)
- `https://api.beatapi.io` (API)

## Request

### Headers

- `Idempotency-Key` (string, optional) — ボディは JSON で送信し、`Content-Type: application/json` を指定します。`Idempotency-Key` は任意です。論理的に 1 件のリクエストごとに一意の値（255 文字以内）を送り、まったく同じボディを再試行するときだけ再利用してください。24 時間以内に同じキーと同じボディで再試行すると、最初のレスポンスが `Idempotent-Replayed: true` 付きで再度返されます。同じキーで異なるボディを送ると `409 idempotency_conflict` が返ります。2xx 以外のレスポンスは保存されないため、400 や 402 の後の再試行は改めて実行されます。

### Body (application/json)

This endpoint expects a KlingV4VideoRequest.

- `model` (enum, required) — 実行するモデルです。 **値**：`kling-v4` **値が正しくない場合** - 指定がない場合：`"model" is required` - 画像モデルをこのエンドポイントに送った場合：`"model" nano-banana-2 is served by POST /v1/images/tasks, not this endpoint`
  - Allowed values: `kling-v4`
- `prompt` (string, required) — 動画の中で起きること（被写体、動き、カメラワーク、スタイル、音）です。各入力は `@` のメンションで指定します。 **長さ**：1–5000 文字 - 長さは文字数で数えます（CJK 文字も 1 文字として数えます）。 - メンションの書き方：`reference_images` は `@image_1`、`@image_2` …、`reference_videos` は `@video_1` …、`reference_audios` は `@voice_1` …、エレメントは `@` に続けてその `name` を書きます。フレームは `@first_frame`、`@keyframe_1`、`@keyframe_2` … と `@last_frame` です。 - すべての `@` は同じリクエストの入力を指す必要があります。参照画像が 2 枚なのに `@image_3` と書く、画像が 1 枚なのに `@last_frame` と書くなど、対応する入力がない番号付きメンションやフレームのメンションは、タスク作成時に拒否されます。 **値が正しくない場合** - 指定がない場合：`"prompt" is required` - 空、または上限を超える長さの場合：`"prompt" has an unsupported length` - リクエストに含まれない入力をメンションした場合：`the prompt names @image_3, which this request does not send`
- `aspect_ratio` (enum, optional, default: 16:9) — 動画の形（幅:高さ）です。 **指定できる値**：`16:9`, `9:16`, `1:1`, `21:9` **デフォルト**：`16:9` - 省略すると `16:9` になります。 - `images` と一緒に送らないでください。動画は開始フレームの形を引き継ぎます。 **値が正しくない場合** - 一覧にない値の場合：`"aspect_ratio" must be one of: [16:9 9:16 1:1 21:9]` - `images` と一緒に送った場合：`Kling V4 takes the first frame's shape; do not send aspect_ratio with images`
  - Allowed values: `16:9`, `9:16`, `1:1`, `21:9`
- `duration` (integer, optional, default: 5) — 動画の長さ（秒、整数）です。課金はこの値に基づきます。 **デフォルト**：`5` **範囲**：3–30 - 省略すると `5` が使われ、その分が課金されます。 - フレームを使う場合は画像の枚数の上限にもなります。最大 `duration` + 1 枚で、10 枚を超えられません。 **値が正しくない場合** - 範囲外、整数ではない、または文字列として送った場合：`"duration" is outside its supported range`
- `elements` (list of KlingV4VideoRequestElementsItems, optional) — キャラクター、動物、小道具、衣装、シーン、エフェクトなど、名前を付けた被写体を最大 7 つ定義します。それぞれ一度だけ定義し、プロンプトでは `@` に続けてその `name` を書きます。 **要素数**：≤ 7 - 最大 7 個のオブジェクトからなる配列です。各オブジェクトは次のキーだけを受け付けます。 - `elements[].name`（文字列、必須）：英字、数字、アンダースコア、漢字の 1～20 文字で、同じリクエスト内で大文字と小文字を区別せずに重複できません。`image_N`、`video_N`、`voice_N`、`keyframe_N`、`object_N`、`audio_N`、`first_frame`、`last_frame` は使えません。 - `elements[].element_input_urls`（文字列の配列）：エレメントを写した画像の公開 HTTPS リンク 2～4 個です。最初の画像がメインビューです。 - `elements[].element_input_video_urls`（文字列の配列）：キャラクターを写した 3～8 秒のワンショット動画の公開 HTTPS リンクをちょうど 1 個です。`element_input_urls` とはどちらか一方だけを送ります。 - `elements[].element_input_audio_urls`（文字列の配列、任意）：キャラクターのエレメントの声となる公開 HTTPS 音声リンクをちょうど 1 個です。 - `elements[].tag`（文字列、任意）：エレメントの種類です。動画エレメント、または声を持つエレメントはキャラクターである必要があります。`tag` を省略するか、`character` を送ってください。 - `elements[].description`（文字列、任意）：エレメントの説明で、最大 100 文字です。 - 動画エレメントは最大 3 個、`reference_videos` との合計は最大 5 個です。すべてのエレメントが参照素材とエレメントの合計 15 個の上限に含まれます。 - エレメントは `images` と一緒に送れません。 **値が正しくない場合** - エレメントが 7 個を超える場合：`"elements" accepts at most 7 items` - エレメントがオブジェクトではない場合：`"elements[0]" must be an object` - エレメントに `name` がない場合：`"name" is required in "elements[0]"` - `name` が空、または 20 文字を超える場合：`"elements[0].name" has an unsupported length` - `name` に他の文字が含まれる、または予約名を使った場合：`elements[0].name "image_1" is not a name Kling V4 accepts` - 同じ `name` が 2 回出てくる場合（大文字と小文字は区別しません）：`elements[1].name "Hero" is used twice` - 画像と動画の両方がある、またはどちらもない場合：`elements[0] takes either element_input_urls or element_input_video_urls` - 画像が 2 枚未満の場合：`"elements[0].element_input_urls" requires at least 2 item` - 画像が 4 枚を超える場合：`"elements[0].element_input_urls" accepts at most 4 items` - 動画エレメントの `tag` が `character` ではない場合：`elements[0] is a video element, which is always a character` - `tag` が `character` ではないエレメントに声がある場合：`elements[0] has a voice, which only a character element takes` - `tag` が一覧にない値の場合：`"elements[0].tag" must be one of: [character animal prop costume scene effect others]` - `description` が 100 文字を超える場合：`"elements[0].description" has an unsupported length` - エレメントが受け付けないキーがある場合：`field "start_time" is not supported in "elements[0]"` - 動画エレメントが 3 個を超える場合：`Kling V4 takes at most 3 video elements` - `images` と組み合わせた場合：`Kling V4 cannot combine elements with images`
- `images` (list of string, optional) — 時間順に並べたフレームです。リンク 1 個は開始フレーム、2 個は開始フレームと終了フレームで、それ以上はその間に中間フレームを加えます。 **要素数**：1–10 各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。 - リンクが 3 個以上の場合、`images[0]` が開始フレーム、最後のリンクが終了フレームで、その間のリンクが中間フレームです。`images[1]` が `@keyframe_1`、`images[2]` が `@keyframe_2` というように続きます。 - 画像は動画の秒数より最大 1 枚多くまで（`duration` + 1。`duration` を省略した場合は 5 秒として数えます）で、どの場合も 10 枚を超えられません。 - フレームは `reference_images`、`reference_videos`、`reference_audios`、`elements`、`aspect_ratio` と一緒に送れません。動画は開始フレームの形を引き継ぎます。 **値が正しくない場合** - リンクが 10 個を超える場合：`"images" accepts at most 10 items` - リンクが `duration` + 1 個を超える場合（この例は 5 秒の動画に 7 個）：`Kling V4 takes at most 6 images for a 5-second video` - いずれかの reference_* フィールドと組み合わせた場合：`Cannot combine "images" with reference inputs in one task` - `elements` と組み合わせた場合：`Kling V4 cannot combine elements with images` - `aspect_ratio` と組み合わせた場合：`Kling V4 takes the first frame's shape; do not send aspect_ratio with images` - https:// のリンクではない場合：`"images[0]" must be a public HTTPS URL`
- `keep_original_sound` (boolean, optional) — 生成された音声の代わりに、参照動画そのものの音声を完成した動画に残します。 - `reference_videos` と一緒の場合だけ有効です。参照動画なしで送ると、`false` であっても拒否されます。 - 省略すると、動画には生成された音声が付きます。音声をオフにするフィールドはありません。 **値が正しくない場合** - true または false ではない場合：`"keep_original_sound" must be a boolean` - `reference_videos` なしで送った場合：`"keep_original_sound" needs reference_videos`
- `reference_audios` (list of string, optional) — 動画で使う声です。プロンプトではリストの順に `@voice_1`、`@voice_2` … と書きます。 **要素数**：1–3 各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。 - `images` とは組み合わせられません。 - 参照素材とエレメントの合計 15 個の上限に含まれます。 **値が正しくない場合** - 上限を超える場合：`"reference_audios" accepts at most 3 items`
- `reference_images` (list of string, optional) — 動画の内容、キャラクター、商品、スタイルを導く画像です。プロンプトではリストの順に `@image_1`、`@image_2` … と書きます。 **要素数**：1–10 各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。 - `images` とは組み合わせられません。 - 参照素材とエレメントの合計 15 個の上限に含まれます。 **値が正しくない場合** - 上限を超える場合：`"reference_images" accepts at most 10 items` - 参照素材とエレメントが合計 15 個を超える場合：`Kling V4 takes at most 15 reference inputs and elements together`
- `reference_videos` (list of string, optional) — 動き、カメラワーク、内容を取り入れる動画です。プロンプトではリストの順に `@video_1`、`@video_2` … と書きます。 **要素数**：1–5 各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。 - 各クリップは 2～30 秒、すべてのクリップの合計は 30 秒以内です。ゲートウェイはタスク作成前に各クリップを測定し、上限を外れたクリップはどれかを示したうえで拒否します。 - 参照動画と動画エレメントは合計 5 個までで、参照素材とエレメントの合計 15 個の上限にも含まれます。 - 完成した動画には生成された音声が付きます。`keep_original_sound: true` を送ると、参照動画そのものの音声を残します。 **値が正しくない場合** - 上限を超える場合：`"reference_videos" accepts at most 5 items` - クリップが 2 秒より短い、または 30 秒より長い場合：`reference_videos[0] is 35 seconds long; this model takes reference video of 2 to 30 seconds.` - クリップの合計が 30 秒を超える場合：`The reference videos run 36 seconds in total; this model takes at most 30.` - 参照動画と動画エレメントが合計 5 個を超える場合：`Kling V4 takes at most 5 reference videos and video elements together`
- `resolution` (enum, optional, default: 720p) — 出力解像度です。`1080p` は `720p` より秒単価が高くなります。 **指定できる値**：`720p`, `1080p` **デフォルト**：`720p` - 省略すると `720p` が使われ、その分が課金されます。 - このモデルでは 4K は使えません。 **値が正しくない場合** - 一覧にない値の場合（例：`4K` や `pro`）：`"resolution" must be one of: [720p 1080p]`
  - Allowed values: `720p`, `1080p`

## Response

### 201

タスクオブジェクトです。タスクが成功するまで `output` は `null` です。「実行中」と記載されたフィールドは、タスクの完了後に表示されなくなります。

- `map from string to any`

## Errors

### 400 Bad Request Error

`bad_request`, `content_policy_violation` リクエストを修正してください。メッセージにフィールド名が示されます。そのまま再試行しないでください。

- `map from string to any`

### 401 Unauthorized Error

`missing_api_key`, `invalid_api_key`（古いクライアントでは `unauthorized` が返ることがあります） 有効なキーを `Authorization: Bearer <key>` で送信してください。

- `map from string to any`

### 402 Payment Required Error

`insufficient_credits` 残高をチャージするか、キーのクォータを引き上げてから、再度送信してください。

- `map from string to any`

### 403 Forbidden Error

`forbidden` このキーまたはアカウントでは、このモデルを利用できない可能性があります（たとえば、無料クレジットは一部のモデルにのみ使えます）。そのまま再試行しないでください。

- `map from string to any`

### 409 Conflict Error

`idempotency_conflict` 新しい `Idempotency-Key` を使うか、同じキーの最初のリクエストが完了するまで待ってください。

- `map from string to any`

### 429 Too Many Requests Error

`rate_limit_exceeded` `Retry-After` の秒数（`error.retry_after_seconds` にも含まれます）だけ待ってから再試行してください。

- `map from string to any`

### 500 Internal Server Error

`internal_error` バックオフを入れて再試行してください。解消しない場合は、`request_id` を添えてサポートにお問い合わせください。

- `map from string to any`

### 503 Service Unavailable Error

`processing_unavailable`, `processing_timeout`, `processing_failed`, `result_transfer_failed` 課金はされていません。指数バックオフで再試行してください。

- `map from string to any`

## Types

### KlingV4VideoRequestElementsItems

- `name` (string, required) — `elements[].name`（文字列、必須）：英字、数字、アンダースコア、漢字の 1～20 文字で、同じリクエスト内で大文字と小文字を区別せずに重複できません。`image_N`、`video_N`、`voice_N`、`keyframe_N`、`object_N`、`audio_N`、`first_frame`、`last_frame` は使えません。 **長さ**：1–20 文字
- `description` (string, optional) — `elements[].description`（文字列、任意）：エレメントの説明で、最大 100 文字です。 **長さ**：≤ 100 文字
- `element_input_audio_urls` (list of string, optional) — `elements[].element_input_audio_urls`（文字列の配列、任意）：キャラクターのエレメントの声となる公開 HTTPS 音声リンクをちょうど 1 個です。 **要素数**：1–1 各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。
- `element_input_urls` (list of string, optional) — `elements[].element_input_urls`（文字列の配列）：エレメントを写した画像の公開 HTTPS リンク 2～4 個です。最初の画像がメインビューです。 **要素数**：2–4 各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。
- `element_input_video_urls` (list of string, optional) — `elements[].element_input_video_urls`（文字列の配列）：キャラクターを写した 3～8 秒のワンショット動画の公開 HTTPS リンクをちょうど 1 個です。`element_input_urls` とはどちらか一方だけを送ります。 **要素数**：1–1 各要素は公開されている `https://` の URL です。ローカルファイルは先に [アップロード](/quick-guide#upload-an-input-file)（`POST /v1/files`）し、返された `data.url` を渡してください。
- `tag` (enum, optional) — `elements[].tag`（文字列、任意）：エレメントの種類です。動画エレメント、または声を持つエレメントはキャラクターである必要があります。`tag` を省略するか、`character` を送ってください。 **指定できる値**：`character`, `animal`, `prop`, `costume`, `scene`, `effect`, `others`
  - Allowed values: `character`, `animal`, `prop`, `costume`, `scene`, `effect`, `others`

## Examples

### テキストから動画

**Request**

```json
{
  "model": "kling-v4",
  "prompt": "A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone",
  "aspect_ratio": "16:9",
  "duration": 5,
  "resolution": "720p"
}
```

**Response**

```json
{
  "data": {
    "capability_id": "kling-v4",
    "capability_version": 1,
    "completed_at": null,
    "created_at": 1791993600,
    "error_code": null,
    "error_message": null,
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "media_type": "video",
    "model": "kling-v4",
    "object": "task",
    "output": null,
    "poll_after_seconds": 8,
    "request_id": "req_5f0c2a9e4b7d4e31",
    "stage": "queued",
    "status": "queued",
    "task_kind": "video",
    "updated_at": 1791993600,
    "usage": {
      "billable_duration_seconds": 5,
      "credits_charged": 1,
      "credits_refunded": 0,
      "credits_reserved": 1,
      "credits_settled": 0
    }
  }
}
```

**SDK Code**

```python テキストから動画
import requests

url = "https://api.beatapi.io/v1/videos/tasks"

payload = {
    "model": "kling-v4",
    "prompt": "A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone",
    "aspect_ratio": "16:9",
    "duration": 5,
    "resolution": "720p"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript テキストから動画
const url = 'https://api.beatapi.io/v1/videos/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"kling-v4","prompt":"A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone","aspect_ratio":"16:9","duration":5,"resolution":"720p"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go テキストから動画
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/videos/tasks"

	payload := strings.NewReader("{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone\",\n  \"aspect_ratio\": \"16:9\",\n  \"duration\": 5,\n  \"resolution\": \"720p\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby テキストから動画
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/videos/tasks")

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 = "{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone\",\n  \"aspect_ratio\": \"16:9\",\n  \"duration\": 5,\n  \"resolution\": \"720p\"\n}"

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

```java テキストから動画
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/videos/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone\",\n  \"aspect_ratio\": \"16:9\",\n  \"duration\": 5,\n  \"resolution\": \"720p\"\n}")
  .asString();
```

```php テキストから動画
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/videos/tasks', [
  'body' => '{
  "model": "kling-v4",
  "prompt": "A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone",
  "aspect_ratio": "16:9",
  "duration": 5,
  "resolution": "720p"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp テキストから動画
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/videos/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone\",\n  \"aspect_ratio\": \"16:9\",\n  \"duration\": 5,\n  \"resolution\": \"720p\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift テキストから動画
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "kling-v4",
  "prompt": "A dramatic product reveal of a glass water bottle, slow orbiting camera, soft studio reflections, a low ambient synth tone",
  "aspect_ratio": "16:9",
  "duration": 5,
  "resolution": "720p"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/videos/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 開始フレームと終了フレーム

**Request**

```json
{
  "model": "kling-v4",
  "prompt": "The camera moves from the bottle in @first_frame to the singer on a neon stage in @last_frame in one continuous shot",
  "duration": 5,
  "images": [
    "https://media.beatapi.io/samples/smart-bottle.png",
    "https://media.beatapi.io/samples/neon-singer.png"
  ],
  "resolution": "1080p"
}
```

**Response**

```json
{
  "data": {
    "capability_id": "kling-v4",
    "capability_version": 1,
    "completed_at": null,
    "created_at": 1791993600,
    "error_code": null,
    "error_message": null,
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "media_type": "video",
    "model": "kling-v4",
    "object": "task",
    "output": null,
    "poll_after_seconds": 8,
    "request_id": "req_5f0c2a9e4b7d4e31",
    "stage": "queued",
    "status": "queued",
    "task_kind": "video",
    "updated_at": 1791993600
  }
}
```

**SDK Code**

```python 開始フレームと終了フレーム
import requests

url = "https://api.beatapi.io/v1/videos/tasks"

payload = {
    "model": "kling-v4",
    "prompt": "The camera moves from the bottle in @first_frame to the singer on a neon stage in @last_frame in one continuous shot",
    "duration": 5,
    "images": ["https://media.beatapi.io/samples/smart-bottle.png", "https://media.beatapi.io/samples/neon-singer.png"],
    "resolution": "1080p"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript 開始フレームと終了フレーム
const url = 'https://api.beatapi.io/v1/videos/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"kling-v4","prompt":"The camera moves from the bottle in @first_frame to the singer on a neon stage in @last_frame in one continuous shot","duration":5,"images":["https://media.beatapi.io/samples/smart-bottle.png","https://media.beatapi.io/samples/neon-singer.png"],"resolution":"1080p"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 開始フレームと終了フレーム
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/videos/tasks"

	payload := strings.NewReader("{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"The camera moves from the bottle in @first_frame to the singer on a neon stage in @last_frame in one continuous shot\",\n  \"duration\": 5,\n  \"images\": [\n    \"https://media.beatapi.io/samples/smart-bottle.png\",\n    \"https://media.beatapi.io/samples/neon-singer.png\"\n  ],\n  \"resolution\": \"1080p\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 開始フレームと終了フレーム
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/videos/tasks")

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 = "{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"The camera moves from the bottle in @first_frame to the singer on a neon stage in @last_frame in one continuous shot\",\n  \"duration\": 5,\n  \"images\": [\n    \"https://media.beatapi.io/samples/smart-bottle.png\",\n    \"https://media.beatapi.io/samples/neon-singer.png\"\n  ],\n  \"resolution\": \"1080p\"\n}"

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

```java 開始フレームと終了フレーム
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/videos/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"The camera moves from the bottle in @first_frame to the singer on a neon stage in @last_frame in one continuous shot\",\n  \"duration\": 5,\n  \"images\": [\n    \"https://media.beatapi.io/samples/smart-bottle.png\",\n    \"https://media.beatapi.io/samples/neon-singer.png\"\n  ],\n  \"resolution\": \"1080p\"\n}")
  .asString();
```

```php 開始フレームと終了フレーム
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/videos/tasks', [
  'body' => '{
  "model": "kling-v4",
  "prompt": "The camera moves from the bottle in @first_frame to the singer on a neon stage in @last_frame in one continuous shot",
  "duration": 5,
  "images": [
    "https://media.beatapi.io/samples/smart-bottle.png",
    "https://media.beatapi.io/samples/neon-singer.png"
  ],
  "resolution": "1080p"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 開始フレームと終了フレーム
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/videos/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"The camera moves from the bottle in @first_frame to the singer on a neon stage in @last_frame in one continuous shot\",\n  \"duration\": 5,\n  \"images\": [\n    \"https://media.beatapi.io/samples/smart-bottle.png\",\n    \"https://media.beatapi.io/samples/neon-singer.png\"\n  ],\n  \"resolution\": \"1080p\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 開始フレームと終了フレーム
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "kling-v4",
  "prompt": "The camera moves from the bottle in @first_frame to the singer on a neon stage in @last_frame in one continuous shot",
  "duration": 5,
  "images": ["https://media.beatapi.io/samples/smart-bottle.png", "https://media.beatapi.io/samples/neon-singer.png"],
  "resolution": "1080p"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/videos/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 参照画像と声

**Request**

```json
{
  "model": "kling-v4",
  "prompt": "The singer from @image_1 lifts the bottle from @image_2 toward the camera and says a short line in the voice of @voice_1",
  "aspect_ratio": "9:16",
  "duration": 8,
  "reference_audios": [
    "https://media.beatapi.io/samples/neon-singer-preview.mp3"
  ],
  "reference_images": [
    "https://media.beatapi.io/samples/neon-singer.png",
    "https://media.beatapi.io/samples/smart-bottle.png"
  ],
  "resolution": "720p"
}
```

**Response**

```json
{
  "data": {
    "capability_id": "kling-v4",
    "capability_version": 1,
    "completed_at": null,
    "created_at": 1791993600,
    "error_code": null,
    "error_message": null,
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "media_type": "video",
    "model": "kling-v4",
    "object": "task",
    "output": null,
    "poll_after_seconds": 8,
    "request_id": "req_5f0c2a9e4b7d4e31",
    "stage": "queued",
    "status": "queued",
    "task_kind": "video",
    "updated_at": 1791993600
  }
}
```

**SDK Code**

```python 参照画像と声
import requests

url = "https://api.beatapi.io/v1/videos/tasks"

payload = {
    "model": "kling-v4",
    "prompt": "The singer from @image_1 lifts the bottle from @image_2 toward the camera and says a short line in the voice of @voice_1",
    "aspect_ratio": "9:16",
    "duration": 8,
    "reference_audios": ["https://media.beatapi.io/samples/neon-singer-preview.mp3"],
    "reference_images": ["https://media.beatapi.io/samples/neon-singer.png", "https://media.beatapi.io/samples/smart-bottle.png"],
    "resolution": "720p"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript 参照画像と声
const url = 'https://api.beatapi.io/v1/videos/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"kling-v4","prompt":"The singer from @image_1 lifts the bottle from @image_2 toward the camera and says a short line in the voice of @voice_1","aspect_ratio":"9:16","duration":8,"reference_audios":["https://media.beatapi.io/samples/neon-singer-preview.mp3"],"reference_images":["https://media.beatapi.io/samples/neon-singer.png","https://media.beatapi.io/samples/smart-bottle.png"],"resolution":"720p"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 参照画像と声
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/videos/tasks"

	payload := strings.NewReader("{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"The singer from @image_1 lifts the bottle from @image_2 toward the camera and says a short line in the voice of @voice_1\",\n  \"aspect_ratio\": \"9:16\",\n  \"duration\": 8,\n  \"reference_audios\": [\n    \"https://media.beatapi.io/samples/neon-singer-preview.mp3\"\n  ],\n  \"reference_images\": [\n    \"https://media.beatapi.io/samples/neon-singer.png\",\n    \"https://media.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"resolution\": \"720p\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 参照画像と声
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/videos/tasks")

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 = "{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"The singer from @image_1 lifts the bottle from @image_2 toward the camera and says a short line in the voice of @voice_1\",\n  \"aspect_ratio\": \"9:16\",\n  \"duration\": 8,\n  \"reference_audios\": [\n    \"https://media.beatapi.io/samples/neon-singer-preview.mp3\"\n  ],\n  \"reference_images\": [\n    \"https://media.beatapi.io/samples/neon-singer.png\",\n    \"https://media.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"resolution\": \"720p\"\n}"

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

```java 参照画像と声
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/videos/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"The singer from @image_1 lifts the bottle from @image_2 toward the camera and says a short line in the voice of @voice_1\",\n  \"aspect_ratio\": \"9:16\",\n  \"duration\": 8,\n  \"reference_audios\": [\n    \"https://media.beatapi.io/samples/neon-singer-preview.mp3\"\n  ],\n  \"reference_images\": [\n    \"https://media.beatapi.io/samples/neon-singer.png\",\n    \"https://media.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"resolution\": \"720p\"\n}")
  .asString();
```

```php 参照画像と声
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/videos/tasks', [
  'body' => '{
  "model": "kling-v4",
  "prompt": "The singer from @image_1 lifts the bottle from @image_2 toward the camera and says a short line in the voice of @voice_1",
  "aspect_ratio": "9:16",
  "duration": 8,
  "reference_audios": [
    "https://media.beatapi.io/samples/neon-singer-preview.mp3"
  ],
  "reference_images": [
    "https://media.beatapi.io/samples/neon-singer.png",
    "https://media.beatapi.io/samples/smart-bottle.png"
  ],
  "resolution": "720p"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 参照画像と声
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/videos/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"The singer from @image_1 lifts the bottle from @image_2 toward the camera and says a short line in the voice of @voice_1\",\n  \"aspect_ratio\": \"9:16\",\n  \"duration\": 8,\n  \"reference_audios\": [\n    \"https://media.beatapi.io/samples/neon-singer-preview.mp3\"\n  ],\n  \"reference_images\": [\n    \"https://media.beatapi.io/samples/neon-singer.png\",\n    \"https://media.beatapi.io/samples/smart-bottle.png\"\n  ],\n  \"resolution\": \"720p\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 参照画像と声
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "kling-v4",
  "prompt": "The singer from @image_1 lifts the bottle from @image_2 toward the camera and says a short line in the voice of @voice_1",
  "aspect_ratio": "9:16",
  "duration": 8,
  "reference_audios": ["https://media.beatapi.io/samples/neon-singer-preview.mp3"],
  "reference_images": ["https://media.beatapi.io/samples/neon-singer.png", "https://media.beatapi.io/samples/smart-bottle.png"],
  "resolution": "720p"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/videos/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 元の音声を残す参照動画

**Request**

```json
{
  "model": "kling-v4",
  "prompt": "Restyle @video_1 as a neon-lit night scene and keep its camera movement",
  "duration": 10,
  "keep_original_sound": true,
  "reference_videos": [
    "https://your-cdn.example.com/clips/source.mp4"
  ],
  "resolution": "720p"
}
```

**Response**

```json
{
  "data": {
    "capability_id": "kling-v4",
    "capability_version": 1,
    "completed_at": null,
    "created_at": 1791993600,
    "error_code": null,
    "error_message": null,
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "media_type": "video",
    "model": "kling-v4",
    "object": "task",
    "output": null,
    "poll_after_seconds": 8,
    "request_id": "req_5f0c2a9e4b7d4e31",
    "stage": "queued",
    "status": "queued",
    "task_kind": "video",
    "updated_at": 1791993600
  }
}
```

**SDK Code**

```python 元の音声を残す参照動画
import requests

url = "https://api.beatapi.io/v1/videos/tasks"

payload = {
    "model": "kling-v4",
    "prompt": "Restyle @video_1 as a neon-lit night scene and keep its camera movement",
    "duration": 10,
    "keep_original_sound": True,
    "reference_videos": ["https://your-cdn.example.com/clips/source.mp4"],
    "resolution": "720p"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript 元の音声を残す参照動画
const url = 'https://api.beatapi.io/v1/videos/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"kling-v4","prompt":"Restyle @video_1 as a neon-lit night scene and keep its camera movement","duration":10,"keep_original_sound":true,"reference_videos":["https://your-cdn.example.com/clips/source.mp4"],"resolution":"720p"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 元の音声を残す参照動画
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/videos/tasks"

	payload := strings.NewReader("{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"Restyle @video_1 as a neon-lit night scene and keep its camera movement\",\n  \"duration\": 10,\n  \"keep_original_sound\": true,\n  \"reference_videos\": [\n    \"https://your-cdn.example.com/clips/source.mp4\"\n  ],\n  \"resolution\": \"720p\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 元の音声を残す参照動画
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/videos/tasks")

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 = "{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"Restyle @video_1 as a neon-lit night scene and keep its camera movement\",\n  \"duration\": 10,\n  \"keep_original_sound\": true,\n  \"reference_videos\": [\n    \"https://your-cdn.example.com/clips/source.mp4\"\n  ],\n  \"resolution\": \"720p\"\n}"

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

```java 元の音声を残す参照動画
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/videos/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"Restyle @video_1 as a neon-lit night scene and keep its camera movement\",\n  \"duration\": 10,\n  \"keep_original_sound\": true,\n  \"reference_videos\": [\n    \"https://your-cdn.example.com/clips/source.mp4\"\n  ],\n  \"resolution\": \"720p\"\n}")
  .asString();
```

```php 元の音声を残す参照動画
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/videos/tasks', [
  'body' => '{
  "model": "kling-v4",
  "prompt": "Restyle @video_1 as a neon-lit night scene and keep its camera movement",
  "duration": 10,
  "keep_original_sound": true,
  "reference_videos": [
    "https://your-cdn.example.com/clips/source.mp4"
  ],
  "resolution": "720p"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 元の音声を残す参照動画
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/videos/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"Restyle @video_1 as a neon-lit night scene and keep its camera movement\",\n  \"duration\": 10,\n  \"keep_original_sound\": true,\n  \"reference_videos\": [\n    \"https://your-cdn.example.com/clips/source.mp4\"\n  ],\n  \"resolution\": \"720p\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 元の音声を残す参照動画
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "kling-v4",
  "prompt": "Restyle @video_1 as a neon-lit night scene and keep its camera movement",
  "duration": 10,
  "keep_original_sound": true,
  "reference_videos": ["https://your-cdn.example.com/clips/source.mp4"],
  "resolution": "720p"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/videos/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```

### 名前付きのエレメント

**Request**

```json
{
  "model": "kling-v4",
  "prompt": "@singer walks across a neon stage holding @bottle and smiles at the camera",
  "aspect_ratio": "16:9",
  "duration": 6,
  "elements": [
    {
      "name": "singer",
      "description": "A performer in a silver jacket",
      "element_input_urls": [
        "https://your-cdn.example.com/elements/singer-front.png",
        "https://your-cdn.example.com/elements/singer-side.png"
      ],
      "tag": "character"
    },
    {
      "name": "bottle",
      "element_input_urls": [
        "https://your-cdn.example.com/elements/bottle-front.png",
        "https://your-cdn.example.com/elements/bottle-back.png"
      ],
      "tag": "prop"
    }
  ],
  "resolution": "720p"
}
```

**Response**

```json
{
  "data": {
    "capability_id": "kling-v4",
    "capability_version": 1,
    "completed_at": null,
    "created_at": 1791993600,
    "error_code": null,
    "error_message": null,
    "id": "task_7Qm2Xc9LpR4vT8sKa1Nf6YbH3eWdJ0uZ",
    "media_type": "video",
    "model": "kling-v4",
    "object": "task",
    "output": null,
    "poll_after_seconds": 8,
    "request_id": "req_5f0c2a9e4b7d4e31",
    "stage": "queued",
    "status": "queued",
    "task_kind": "video",
    "updated_at": 1791993600
  }
}
```

**SDK Code**

```python 名前付きのエレメント
import requests

url = "https://api.beatapi.io/v1/videos/tasks"

payload = {
    "model": "kling-v4",
    "prompt": "@singer walks across a neon stage holding @bottle and smiles at the camera",
    "aspect_ratio": "16:9",
    "duration": 6,
    "elements": [
        {
            "name": "singer",
            "description": "A performer in a silver jacket",
            "element_input_urls": ["https://your-cdn.example.com/elements/singer-front.png", "https://your-cdn.example.com/elements/singer-side.png"],
            "tag": "character"
        },
        {
            "name": "bottle",
            "element_input_urls": ["https://your-cdn.example.com/elements/bottle-front.png", "https://your-cdn.example.com/elements/bottle-back.png"],
            "tag": "prop"
        }
    ],
    "resolution": "720p"
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript 名前付きのエレメント
const url = 'https://api.beatapi.io/v1/videos/tasks';
const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: '{"model":"kling-v4","prompt":"@singer walks across a neon stage holding @bottle and smiles at the camera","aspect_ratio":"16:9","duration":6,"elements":[{"name":"singer","description":"A performer in a silver jacket","element_input_urls":["https://your-cdn.example.com/elements/singer-front.png","https://your-cdn.example.com/elements/singer-side.png"],"tag":"character"},{"name":"bottle","element_input_urls":["https://your-cdn.example.com/elements/bottle-front.png","https://your-cdn.example.com/elements/bottle-back.png"],"tag":"prop"}],"resolution":"720p"}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go 名前付きのエレメント
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.beatapi.io/v1/videos/tasks"

	payload := strings.NewReader("{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"@singer walks across a neon stage holding @bottle and smiles at the camera\",\n  \"aspect_ratio\": \"16:9\",\n  \"duration\": 6,\n  \"elements\": [\n    {\n      \"name\": \"singer\",\n      \"description\": \"A performer in a silver jacket\",\n      \"element_input_urls\": [\n        \"https://your-cdn.example.com/elements/singer-front.png\",\n        \"https://your-cdn.example.com/elements/singer-side.png\"\n      ],\n      \"tag\": \"character\"\n    },\n    {\n      \"name\": \"bottle\",\n      \"element_input_urls\": [\n        \"https://your-cdn.example.com/elements/bottle-front.png\",\n        \"https://your-cdn.example.com/elements/bottle-back.png\"\n      ],\n      \"tag\": \"prop\"\n    }\n  ],\n  \"resolution\": \"720p\"\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Authorization", "Bearer <token>")
	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby 名前付きのエレメント
require 'uri'
require 'net/http'

url = URI("https://api.beatapi.io/v1/videos/tasks")

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 = "{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"@singer walks across a neon stage holding @bottle and smiles at the camera\",\n  \"aspect_ratio\": \"16:9\",\n  \"duration\": 6,\n  \"elements\": [\n    {\n      \"name\": \"singer\",\n      \"description\": \"A performer in a silver jacket\",\n      \"element_input_urls\": [\n        \"https://your-cdn.example.com/elements/singer-front.png\",\n        \"https://your-cdn.example.com/elements/singer-side.png\"\n      ],\n      \"tag\": \"character\"\n    },\n    {\n      \"name\": \"bottle\",\n      \"element_input_urls\": [\n        \"https://your-cdn.example.com/elements/bottle-front.png\",\n        \"https://your-cdn.example.com/elements/bottle-back.png\"\n      ],\n      \"tag\": \"prop\"\n    }\n  ],\n  \"resolution\": \"720p\"\n}"

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

```java 名前付きのエレメント
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.beatapi.io/v1/videos/tasks")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"@singer walks across a neon stage holding @bottle and smiles at the camera\",\n  \"aspect_ratio\": \"16:9\",\n  \"duration\": 6,\n  \"elements\": [\n    {\n      \"name\": \"singer\",\n      \"description\": \"A performer in a silver jacket\",\n      \"element_input_urls\": [\n        \"https://your-cdn.example.com/elements/singer-front.png\",\n        \"https://your-cdn.example.com/elements/singer-side.png\"\n      ],\n      \"tag\": \"character\"\n    },\n    {\n      \"name\": \"bottle\",\n      \"element_input_urls\": [\n        \"https://your-cdn.example.com/elements/bottle-front.png\",\n        \"https://your-cdn.example.com/elements/bottle-back.png\"\n      ],\n      \"tag\": \"prop\"\n    }\n  ],\n  \"resolution\": \"720p\"\n}")
  .asString();
```

```php 名前付きのエレメント
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.beatapi.io/v1/videos/tasks', [
  'body' => '{
  "model": "kling-v4",
  "prompt": "@singer walks across a neon stage holding @bottle and smiles at the camera",
  "aspect_ratio": "16:9",
  "duration": 6,
  "elements": [
    {
      "name": "singer",
      "description": "A performer in a silver jacket",
      "element_input_urls": [
        "https://your-cdn.example.com/elements/singer-front.png",
        "https://your-cdn.example.com/elements/singer-side.png"
      ],
      "tag": "character"
    },
    {
      "name": "bottle",
      "element_input_urls": [
        "https://your-cdn.example.com/elements/bottle-front.png",
        "https://your-cdn.example.com/elements/bottle-back.png"
      ],
      "tag": "prop"
    }
  ],
  "resolution": "720p"
}',
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp 名前付きのエレメント
using RestSharp;

var client = new RestClient("https://api.beatapi.io/v1/videos/tasks");
var request = new RestRequest(Method.POST);
request.AddHeader("Authorization", "Bearer <token>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"model\": \"kling-v4\",\n  \"prompt\": \"@singer walks across a neon stage holding @bottle and smiles at the camera\",\n  \"aspect_ratio\": \"16:9\",\n  \"duration\": 6,\n  \"elements\": [\n    {\n      \"name\": \"singer\",\n      \"description\": \"A performer in a silver jacket\",\n      \"element_input_urls\": [\n        \"https://your-cdn.example.com/elements/singer-front.png\",\n        \"https://your-cdn.example.com/elements/singer-side.png\"\n      ],\n      \"tag\": \"character\"\n    },\n    {\n      \"name\": \"bottle\",\n      \"element_input_urls\": [\n        \"https://your-cdn.example.com/elements/bottle-front.png\",\n        \"https://your-cdn.example.com/elements/bottle-back.png\"\n      ],\n      \"tag\": \"prop\"\n    }\n  ],\n  \"resolution\": \"720p\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift 名前付きのエレメント
import Foundation

let headers = [
  "Authorization": "Bearer <token>",
  "Content-Type": "application/json"
]
let parameters = [
  "model": "kling-v4",
  "prompt": "@singer walks across a neon stage holding @bottle and smiles at the camera",
  "aspect_ratio": "16:9",
  "duration": 6,
  "elements": [
    [
      "name": "singer",
      "description": "A performer in a silver jacket",
      "element_input_urls": ["https://your-cdn.example.com/elements/singer-front.png", "https://your-cdn.example.com/elements/singer-side.png"],
      "tag": "character"
    ],
    [
      "name": "bottle",
      "element_input_urls": ["https://your-cdn.example.com/elements/bottle-front.png", "https://your-cdn.example.com/elements/bottle-back.png"],
      "tag": "prop"
    ]
  ],
  "resolution": "720p"
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.beatapi.io/v1/videos/tasks")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```