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

# Utwórz zadanie Kling Motion Control

> Utwórz zadanie Kling Motion Control na podstawie obrazu postaci i referencyjnego filmu ruchu, korzystając ze zgodnej trasy CometAPI.

Użyj tego endpointu, aby utworzyć zadanie Motion Control na podstawie obrazu postaci i
filmu referencyjnego.

<Warning>
  Na tej stronie opisano zgodną trasę Motion Control. Kling Video 3.0
  Motion Control korzysta z odrębnego kontraktu API.
</Warning>

## Wymagane multimedia

`image_url` akceptuje publiczny adres URL lub nieprzetworzony ciąg Base64.

* Użyj obrazu JPG, JPEG lub PNG o rozmiarze nie większym niż 10 MB.
* Każdy wymiar obrazu musi mieścić się w zakresie od 300 do 65 536 pikseli.
* Użyj proporcji obrazu w zakresie od 1:2,5 do 2,5:1.
* Przesyłaj Base64 jako nieprzetworzony zakodowany ciąg bez
  `data:image/...;base64,` prefiksu.
* Przedstaw jedną niezasłoniętą postać z kadrowaniem sylwetki zgodnym z ruchem
  referencyjnym.

`video_url` akceptuje publiczny adres URL pliku MP4 lub MOV.

* Użyj filmu o rozmiarze nie większym niż 100 MB.
* Ustaw krótszy bok na co najmniej 340 pikseli.
* Ustaw dłuższy bok na nie więcej niż 3850 pikseli.
* Użyj ciągłego ujęcia z jedną widoczną postacią.
* Unikaj cięć, zmian kamery i nadmiernie szybkiego ruchu.

<Note>
  Przestrzegaj limitów czasu trwania i sprawdzaj zagnieżdżone pole terminalne `task_status`. Zewnętrzny
  kod HTTP 200 lub odpowiedź `code: 0` potwierdzają odpowiedź na zapytanie, a nie
  pomyślny wynik generowania.
</Note>

## Ustaw wartość orientacji

`character_orientation` jest wymagana i akceptuje `image` lub `video`.

| Wartość | Czas trwania filmu referencyjnego |
| ------- | --------------------------------- |
| `image` | 3–10 sekund                       |
| `video` | 3–30 sekund                       |

Jeśli używasz `element_list`, ustaw `character_orientation` na `video`.

## Wybierz model i tryb

Zgodna trasa akceptuje `kling-v2-6` i `kling-v3`. Obie wartości modelu
akceptują obie wartości trybu:

| Model        | `std`       | `pro`       |
| ------------ | ----------- | ----------- |
| `kling-v2-6` | Akceptowane | Akceptowane |
| `kling-v3`   | Akceptowane | Akceptowane |

Jeśli pominiesz `model_name`, żądanie użyje `kling-v2-6`. Jeśli pominiesz `mode`,
żądanie użyje `std`. Wartość `kling-v3` zachowuje zgodną strukturę żądania
opisaną na tej stronie; nie wybiera odrębnego kontraktu Kling 3.0 opartego na wersji ścieżki
API.

Zgodny kontrakt nie gwarantuje stałej rozdzielczości wyjściowej. Sprawdź
każdy zwrócony film, jeśli aplikacja wymaga określonych wymiarów.

`keep_original_sound` akceptuje `yes` lub `no`. Jeśli pominiesz to pole,
żądanie użyje `yes`.

## Przepływ zadania

<Steps>
  <Step title="Wyślij żądanie Motion Control">
    Wyślij obraz źródłowy, film referencyjny i wartość orientacji. Wybierz
    model, tryb i wartość dźwięku lub użyj ich udokumentowanych wartości domyślnych. Zapisz
    zwrócony `task_id`.
  </Step>

  <Step title="Odpytuj zadanie">
    Użyj [Pobierz zadanie Kling](./individual-queries) ze zwróconym `task_id`.
    Kontynuuj, aż status będzie miał wartość `succeed` lub `failed`.
  </Step>

  <Step title="Zapisz wynik">
    Niezwłocznie pobierz i zapisz wynik. Dokumentacja zgodnego API Kling
    podaje, że wygenerowane filmy są usuwane po 30 dniach. Nie
    zakładaj, że zwrócony adres URL pozostanie dostępny przez pełne 30 dni.
  </Step>
</Steps>

## Pola opcjonalne

| Pole               | Struktura                                                       | Ograniczenie                                                                          |
| ------------------ | --------------------------------------------------------------- | ------------------------------------------------------------------------------------- |
| `prompt`           | Ciąg znaków, maksymalnie 2500 znaków                            | Opcjonalne pole tekstowe w zgodnej strukturze żądania.                                |
| `callback_url`     | Ciąg URI lub pusty ciąg                                         | Pomiń pole albo użyj pustego ciągu, gdy nie skonfigurowano URI wywołania zwrotnego.   |
| `external_task_id` | Ciąg znaków unikatowy dla Twojego konta                         | Łączy zadanie z aplikacją. Nie zastępuje zwróconego `task_id` w zapytaniach CometAPI. |
| `element_list`     | Tablica zawierająca najwyżej jeden obiekt `{"element_id": 123}` | Łącz to pole tylko z `character_orientation: "video"`.                                |
| `watermark_info`   | `{"enabled": boolean}`                                          | Zgodna struktura znaku wodnego zawiera wyłącznie wartość `enabled` typu Boolean.      |

## Struktura callbacka

Schemat callbacka Legacy ma następującą strukturę:

```json theme={null}
{
  "task_id": "<task_id>",
  "task_status": "succeed",
  "task_status_msg": "",
  "created_at": 1785398400000,
  "updated_at": 1785398460000,
  "final_unit_deduction": "<value>",
  "final_balance_deduction": {
    "quota": "<value>",
    "list_price": "<value>"
  },
  "task_info": {
    "external_task_id": "<your_unique_id>"
  },
  "task_result": {
    "videos": [
      {
        "id": "<video_id>",
        "url": "https://media.example.com/<file_id>.mp4",
        "duration": "6.4"
      }
    ]
  }
}
```

Status callbacka może mieć wartość `submitted`, `processing`, `succeed` lub `failed`.
Pola wyniku końcowego są obecne tylko wtedy, gdy są zwracane dla stanu końcowego.

## Pola wyniku

| Pole                                 | Typ                                       | Opis                                                                       |
| ------------------------------------ | ----------------------------------------- | -------------------------------------------------------------------------- |
| `task_result.videos[].id`            | Ciąg znaków                               | Identyfikator wygenerowanego filmu.                                        |
| `task_result.videos[].url`           | Ciąg URI                                  | Adres URL dostarczania wygenerowanego filmu.                               |
| `task_result.videos[].watermark_url` | Ciąg URI                                  | Adres URL dostarczania filmu ze znakiem wodnym, jeśli zadanie taki zwróci. |
| `task_result.videos[].duration`      | Ciąg znaków                               | Czas trwania wygenerowanego filmu w sekundach.                             |
| `final_unit_deduction`               | Ciąg znaków                               | Końcowa wartość potrącenia jednostek zwrócona wraz z zadaniem.             |
| `final_balance_deduction`            | `{"quota": string, "list_price": string}` | Końcowe wartości potrąceń z salda zwrócone wraz z zadaniem.                |

Status zadania może mieć wartość `submitted`, `processing`, `succeed` lub `failed`.

<Tip>
  Zobacz [dokumentację referencyjną API Kling Motion Control](https://kling.ai/document-api/api/video/motion-control/legacy)
  oraz [protokół callback Kling](https://kling.ai/document-api/api/get-started/callbacks)
  aby uzyskać szczegóły API.
</Tip>


## OpenAPI

````yaml api/openapi/video/kling/post-motion-control.openapi.json POST /kling/v1/videos/motion-control
openapi: 3.1.0
info:
  title: Kling Motion Control API
  version: 1.0.0
  description: >-
    Create a Kling Motion Control task from a character image and a reference
    motion video.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /kling/v1/videos/motion-control:
    post:
      summary: Create a Kling Motion Control task
      description: >-
        Submit a character image and a reference motion video. The response
        contains a task ID that you can use for status queries.
      operationId: create_kling_motion_control
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - image_url
                - video_url
                - character_orientation
              properties:
                model_name:
                  type: string
                  description: >-
                    Model ID for this compatible Motion Control request. Omit
                    this field to use `kling-v2-6`. The `kling-v3` value keeps
                    this compatible request shape; it does not select the
                    separate Kling 3.0 path-version contract.
                  enum:
                    - kling-v2-6
                    - kling-v3
                  default: kling-v2-6
                image_url:
                  type: string
                  description: >-
                    Character image as a public URL or a raw Base64 string. Send
                    raw Base64 without a `data:image/...;base64,` prefix;
                    data-URI input is outside the compatible contract. Supported
                    formats are JPG, JPEG, and PNG. The image must be 10 MB or
                    smaller. Its width and height must each be from 300 through
                    65,536 pixels, and its aspect ratio must be between 1:2.5
                    and 2.5:1.
                video_url:
                  type: string
                  format: uri
                  description: >-
                    Public reference motion video URL. Use an MP4 or MOV file
                    that is 100 MB or smaller. The short edge must be at least
                    340 pixels, and the long edge must not exceed 3850 pixels.
                    The video must be at least 3 seconds long. The maximum
                    duration depends on `character_orientation`.
                prompt:
                  type: string
                  maxLength: 2500
                  description: >-
                    Optional text field in the compatible request structure.
                    Maximum 2500 characters.
                keep_original_sound:
                  type: string
                  description: >-
                    Compatible string enum. Accepted values are `yes` and `no`.
                    Omitted requests use `yes`.
                  enum:
                    - 'yes'
                    - 'no'
                  default: 'yes'
                character_orientation:
                  type: string
                  description: >-
                    Required compatible string enum. With `image`, the reference
                    video can be 3 to 10 seconds long. With `video`, the
                    reference video can be 3 to 30 seconds long.
                  enum:
                    - image
                    - video
                mode:
                  type: string
                  description: >-
                    Both compatible models accept `std` and `pro`. Omitted
                    requests use `std`.
                  enum:
                    - std
                    - pro
                  default: std
                callback_url:
                  description: >-
                    Optional callback field in the compatible structure. Provide
                    a URI, or omit the field or send an empty string when no
                    callback URI is configured.
                  oneOf:
                    - type: string
                      format: uri
                    - type: string
                      const: ''
                external_task_id:
                  type: string
                  description: >-
                    Optional ID for correlation in your application. The value
                    must be unique for your account. Store the returned
                    `task_id` for CometAPI status queries.
                element_list:
                  type: array
                  maxItems: 1
                  description: >-
                    Optional compatible Element structure. Provide at most one
                    object, and combine this field only with
                    `character_orientation: video`.
                  items:
                    type: object
                    required:
                      - element_id
                    properties:
                      element_id:
                        type: integer
                        format: int64
                        description: Kling Element ID in the compatible structure.
                    additionalProperties: false
                watermark_info:
                  type: object
                  description: Optional compatible watermark structure.
                  required:
                    - enabled
                  properties:
                    enabled:
                      type: boolean
                      description: Boolean flag in the compatible watermark structure.
                  additionalProperties: false
              example:
                model_name: kling-v3
                image_url: https://your-image-host.example.com/character.png
                video_url: https://your-video-host.example.com/reference-motion.mp4
                prompt: Studio scene.
                keep_original_sound: 'no'
                character_orientation: video
                mode: std
            examples:
              Image URL:
                summary: Use a public character image URL
                value:
                  model_name: kling-v3
                  image_url: https://your-image-host.example.com/character.png
                  video_url: https://your-video-host.example.com/reference-motion.mp4
                  prompt: Studio scene.
                  keep_original_sound: 'no'
                  character_orientation: video
                  mode: std
              Image base64:
                summary: Use a raw Base64 character image
                value:
                  model_name: kling-v3
                  image_url: <your-image-base64>
                  video_url: https://your-video-host.example.com/reference-motion.mp4
                  prompt: Studio scene.
                  keep_original_sound: 'no'
                  character_orientation: video
                  mode: pro
      responses:
        '200':
          description: Task accepted.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - message
                  - data
                properties:
                  code:
                    type: integer
                    description: >-
                      Response code. A value of 0 indicates that the request was
                      accepted.
                  message:
                    type: string
                    description: Response message.
                  data:
                    type: object
                    required:
                      - task_id
                      - task_status
                      - task_info
                      - created_at
                      - updated_at
                    properties:
                      task_id:
                        type: string
                        description: System-generated task ID for status queries.
                      task_status:
                        type: string
                        description: Task state after submission.
                        const: submitted
                      task_status_msg:
                        type: string
                        description: Status detail when returned.
                      task_info:
                        type: object
                        description: Additional task metadata. The object can be empty.
                        additionalProperties: true
                      created_at:
                        type: integer
                        format: int64
                        description: Task creation timestamp in milliseconds.
                      updated_at:
                        type: integer
                        format: int64
                        description: Last task update timestamp in milliseconds.
                example:
                  code: 0
                  message: SUCCEED
                  data:
                    task_id: <task_id>
                    task_status: submitted
                    task_info: {}
                    created_at: 1785398400000
                    updated_at: 1785398400000
      x-codeSamples:
        - lang: Shell
          label: Image URL
          source: |
            curl https://api.cometapi.com/kling/v1/videos/motion-control \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "model_name": "kling-v3",
                "image_url": "https://your-image-host.example.com/character.png",
                "video_url": "https://your-video-host.example.com/reference-motion.mp4",
                "prompt": "Studio scene.",
                "keep_original_sound": "no",
                "character_orientation": "video",
                "mode": "std"
              }'
        - lang: Python
          label: Image URL
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/kling/v1/videos/motion-control",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                    "model_name": "kling-v3",
                    "image_url": "https://your-image-host.example.com/character.png",
                    "video_url": "https://your-video-host.example.com/reference-motion.mp4",
                    "prompt": "Studio scene.",
                    "keep_original_sound": "no",
                    "character_orientation": "video",
                    "mode": "std",
                },
            )

            result = response.json()
            print(result.get("code"), result.get("data", {}).get("task_id"))
        - lang: JavaScript
          label: Image URL
          source: |
            const response = await fetch(
              "https://api.cometapi.com/kling/v1/videos/motion-control",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify({
                  model_name: "kling-v3",
                  image_url: "https://your-image-host.example.com/character.png",
                  video_url: "https://your-video-host.example.com/reference-motion.mp4",
                  prompt: "Studio scene.",
                  keep_original_sound: "no",
                  character_orientation: "video",
                  mode: "std",
                }),
              },
            );

            const result = await response.json();
            console.log(result.code, result.data?.task_id);
        - lang: Shell
          label: Image base64
          source: |
            curl https://api.cometapi.com/kling/v1/videos/motion-control \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              --data-binary @- <<'JSON'
            {
              "model_name": "kling-v3",
              "image_url": "<base64-encoded-png>",
              "video_url": "https://your-video-host.example.com/reference-motion.mp4",
              "prompt": "Studio scene.",
              "keep_original_sound": "no",
              "character_orientation": "video",
              "mode": "pro"
            }
            JSON
        - lang: Python
          label: Image base64
          source: |
            import base64
            import os
            import requests

            with open("character.png", "rb") as image_file:
                image_base64 = base64.b64encode(image_file.read()).decode("ascii")

            response = requests.post(
                "https://api.cometapi.com/kling/v1/videos/motion-control",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                    "model_name": "kling-v3",
                    "image_url": image_base64,
                    "video_url": "https://your-video-host.example.com/reference-motion.mp4",
                    "prompt": "Studio scene.",
                    "keep_original_sound": "no",
                    "character_orientation": "video",
                    "mode": "pro",
                },
            )

            result = response.json()
            print(result.get("code"), result.get("data", {}).get("task_id"))
        - lang: JavaScript
          label: Image base64
          source: >
            import { readFile } from "node:fs/promises";


            const imageBase64 = (await
            readFile("character.png")).toString("base64");

            const response = await fetch(
              "https://api.cometapi.com/kling/v1/videos/motion-control",
              {
                method: "POST",
                headers: {
                  Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                  "Content-Type": "application/json",
                },
                body: JSON.stringify({
                  model_name: "kling-v3",
                  image_url: imageBase64,
                  video_url: "https://your-video-host.example.com/reference-motion.mp4",
                  prompt: "Studio scene.",
                  keep_original_sound: "no",
                  character_orientation: "video",
                  mode: "pro",
                }),
              },
            );


            const result = response.json();

            console.log(result.code, result.data?.task_id);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer authentication. Use your CometAPI API key.

````