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

# Генерация видео Kling v2.6 с управлением движением

>  - Модель Kling с управлением движением (референсное изображение + референсное видео)
- Вызов через единый эндпоинт `/v1/videos/generations`
- Поддерживает ориентацию персонажа по изображению / видео, максимальная длительность 10 с / 30 с соответственно
- Асинхронная задача — при отправке возвращается task_id 

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url https://api.apimart.ai/v1/videos/generations \
    --header 'Authorization: Bearer <token>' \
    --header 'Content-Type: application/json' \
    --data '{
      "model": "kling-v2-6-motion-control",
      "prompt": "Keep the character consistent, perform a turn and wave following the reference video, cinematic lighting",
      "image_url": "https://example.com/ref-image.png",
      "video_url": "https://example.com/ref-video-8s.mp4",
      "keep_original_sound": "yes",
      "character_orientation": "image",
      "mode": "std",
      "watermark_info": {"enabled": false}
    }'
  ```

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

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

  payload = {
      "model": "kling-v2-6-motion-control",
      "prompt": "Keep the character consistent, perform a turn and wave following the reference video, cinematic lighting",
      "image_url": "https://example.com/ref-image.png",
      "video_url": "https://example.com/ref-video-8s.mp4",
      "keep_original_sound": "yes",
      "character_orientation": "image",
      "mode": "std",
      "watermark_info": {"enabled": False}
  }

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

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

  print(response.json())
  ```

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

  const payload = {
    model: "kling-v2-6-motion-control",
    prompt: "Keep the character consistent, perform a turn and wave following the reference video, cinematic lighting",
    image_url: "https://example.com/ref-image.png",
    video_url: "https://example.com/ref-video-8s.mp4",
    keep_original_sound: "yes",
    character_orientation: "image",
    mode: "std",
    watermark_info: { enabled: false }
  };

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

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

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

  ```json 400 theme={null}
  {
    "error": {
      "code": 400,
      "message": "Invalid request parameters",
      "type": "invalid_request_error"
    }
  }
  ```

  ```json 401 theme={null}
  {
    "error": {
      "code": 401,
      "message": "Authentication failed. Please check your API key.",
      "type": "authentication_error"
    }
  }
  ```

  ```json 402 theme={null}
  {
    "error": {
      "code": 402,
      "message": "Insufficient account balance. Please top up and try again.",
      "type": "payment_required"
    }
  }
  ```

  ```json 429 theme={null}
  {
    "error": {
      "code": 429,
      "message": "Too many requests. Please try again later.",
      "type": "rate_limit_error"
    }
  }
  ```

  ```json 500 theme={null}
  {
    "error": {
      "code": 500,
      "message": "Internal server error. Please try again later.",
      "type": "server_error"
    }
  }
  ```
</ResponseExample>

## Аутентификация

<ParamField header="Authorization" type="string" required>
  Все запросы требуют аутентификации по Bearer Token

  Получение API-ключа:

  Перейдите на [страницу управления API-ключами](https://apimart.ai/keys), чтобы получить свой API-ключ

  Добавьте следующий заголовок в каждый запрос:

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

## Параметры запроса

<ParamField body="model" type="string" required>
  Название модели: `kling-v3-motion-control` или `kling-v2-6-motion-control`
</ParamField>

<ParamField body="prompt" type="string">
  Текстовое описание желаемого движения, перемещения камеры и стиля

  Необязательный, но рекомендуемый параметр — более конкретные описания дают более стабильные результаты

  Пример: `"The character dances following the reference video, smooth motion, realistic style"`
</ParamField>

<ParamField body="image_url" type="string" required>
  URL референсного изображения

  Должен быть публично доступной ссылкой
</ParamField>

<ParamField body="video_url" type="string" required>
  URL референсного видео

  Должен быть публично доступной прямой ссылкой; рекомендуется mp4/mov, размер до 100 МБ

  <Warning>
    Сервер определяет фактическую длительность по `video_url`. Минимум — 3 секунды; максимум зависит от значения `character_orientation`.
  </Warning>
</ParamField>

<ParamField body="keep_original_sound" type="string" default="yes">
  Сохранять ли оригинальную аудиодорожку из референсного видео

  Варианты:

  * `yes`: сохранять оригинальное аудио (по умолчанию)
  * `no`: не сохранять оригинальное аудио
</ParamField>

<ParamField body="character_orientation" type="string" required>
  Управление ориентацией персонажа

  Варианты:

  * `image`: использовать ориентацию персонажа из референсного изображения (длительность референсного видео: `3~10s`)
  * `video`: использовать ориентацию персонажа из референсного видео (длительность референсного видео: `3~30s`)
</ParamField>

<ParamField body="mode" type="string" required>
  Режим генерации

  Варианты:

  * `std`: стандартный режим (баланс скорости и качества)
  * `pro`: режим высокого качества (более высокая задержка)
</ParamField>

<ParamField body="watermark_info" type="object">
  Объект управления водяным знаком (необязательно)

  <Expandable title="Поля watermark_info">
    <ParamField body="enabled" type="boolean" default="false">
      Добавлять ли водяной знак

      * `true`: добавлять водяной знак
      * `false`: без водяного знака (по умолчанию)
    </ParamField>
  </Expandable>
</ParamField>

## Правила длительности

| Условие                         | Допустимая длительность референсного видео |
| ------------------------------- | ------------------------------------------ |
| `character_orientation = image` | `3s ~ 10s`                                 |
| `character_orientation = video` | `3s ~ 30s`                                 |

<Note>
  Длительность для тарификации определяется фактической длительностью, считываемой сервером из `video_url`, а не клиентской оценкой.
</Note>

## Ответ

<ResponseField name="code" type="integer">
  Код состояния ответа, 200 при успехе
</ResponseField>

<ResponseField name="data" type="array">
  Массив данных ответа

  <Expandable title="Элементы массива">
    <ResponseField name="status" type="string">
      Статус задачи, `submitted` при первоначальной отправке
    </ResponseField>

    <ResponseField name="task_id" type="string">
      Уникальный идентификатор задачи для запроса её статуса и результатов
    </ResponseField>
  </Expandable>
</ResponseField>

## Примеры

### Пример 1: ориентация по изображению (в пределах 10 с)

```json theme={null}
{
  "model": "kling-v2-6-motion-control",
  "prompt": "Keep character orientation consistent with the reference image, perform a turn and wave",
  "image_url": "https://example.com/ref-image.png",
  "video_url": "https://example.com/ref-video-8s.mp4",
  "character_orientation": "image",
  "mode": "std",
  "keep_original_sound": "yes",
  "watermark_info": {"enabled": false}
}
```

### Пример 2: ориентация по видео (в пределах 30 с)

```json theme={null}
{
  "model": "kling-v2-6-motion-control",
  "prompt": "Follow the character orientation and rhythm of the reference video, maintain fluid motion",
  "image_url": "https://example.com/ref-image.png",
  "video_url": "https://example.com/ref-video-12s.mp4",
  "character_orientation": "video",
  "mode": "pro",
  "keep_original_sound": "no",
  "watermark_info": {"enabled": false}
}
```
