# POST /api/v1/jobs/confirm

> Answer to the «trim or not» question for HeyGen Lipsync: 1 — trim and start, 0 — do not start.

## When the question comes

Only for [HeyGen Lipsync Speed](https://docs.mixmedia.tech/en/models/heygen-lipsync-speed) and [HeyGen Lipsync Precision](https://docs.mixmedia.tech/en/models/heygen-lipsync-precision). HeyGen accepts audio and video only if their lengths differ by at most 15% (with `enable_dynamic_duration` = `true`, the default). We check this ourselves, before the start and before any charge.

- **Lengths are close** (up to 15%) — no question, the task runs as usual.
- **Lengths differ too much** — the task is created in state `confirm`, **nothing is charged**. We ask whether to trim the longer file (from the start) to the length of the shorter one.
- **The video has no sound** — no question: createTask answers `422` right away, no task is created, nothing is charged. HeyGen needs the original speech inside the video to find who speaks; pass the new speech in `audio_urls`.

Sync Lipsync 2 does not ask: it handles different lengths itself (`sync_mode`).

## What the question looks like

The createTask response (the same `confirm` field comes in the `task.confirm_required` callback and in recordInfo):

```json
{
  "code": 200,
  "msg": "confirm_required",
  "data": {
    "taskId": "task_heygen-lipsync-speed_1796400682122ec5137",
    "status": "awaiting_confirmation",
    "state": "confirm",
    "confirm": {
      "type": "trim_to_match",
      "question": "Audio is 2.96 s, video is 5.04 s. HeyGen Lipsync accepts at most a 15% difference. Trim the video to 2.96 s and continue? Answer 1 = yes, 0 = no.",
      "question_ru": "Звук 2.96 с, видео 5.04 с. HeyGen Lipsync допускает разницу не больше 15%. Обрезать видео до 2.96 с и продолжить?",
      "video_seconds": 5.04,
      "audio_seconds": 2.96,
      "max_difference_percent": 15,
      "trim": "video",
      "trim_to_seconds": 2.96,
      "price_if_yes_usd": "0.0550",
      "answers": {
        "0": "do not trim, the task fails, nothing is charged",
        "1": "trim the video and start (charged on start)"
      },
      "answer_url": "https://mixmedia.tech/api/v1/jobs/confirm",
      "expires_at": 1796486400000
    }
  }
}
```

| Field | Meaning |
|---|---|
| `trim` | What we trim: `video` or `audio` — always the longer file |
| `trim_to_seconds` | Target length (the shorter file) |
| `price_if_yes_usd` | Price if you answer 1. Trimming the audio lowers it: the price follows audio seconds |
| `expires_at` | Answer deadline (unix ms), 24 hours |

Without a `callBackUrl` the question is in [recordInfo](https://docs.mixmedia.tech/en/endpoints/record-info): `state` = `confirm`, `status` = `awaiting_confirmation`. All of them: `GET /api/v1/jobs/list?state=confirm`.

## Request

```http
POST https://mixmedia.tech/api/v1/jobs/confirm
Authorization: Bearer <API_KEY>
Content-Type: application/json

{"taskId": "task_heygen-lipsync-speed_1796400682122ec5137", "answer": 1}
```

| Field | Required | Description |
|---|---|---|
| `taskId` | yes | ID of a task in state `confirm` |
| `answer` | yes | `1` — yes, trim and start; `0` — no |

## What happens

| answer | Result |
|---|---|
| `1` | We trim the longer file, charge the price and start the task. Then as usual: recordInfo or a result callback. Not enough balance — `402`, the task keeps waiting; top up and send `1` again |
| `0` | Nothing is trimmed or started. The task becomes `fail` with code `422`, nothing is charged. Your callBackUrl gets `task.fail` |
| no answer in 24 hours | Same as `0`: `fail`, `422`, nothing charged |

```json
{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_heygen-lipsync-speed_1796400682122ec5137",
    "status": "submitted",
    "answer": 1,
    "trimmed": {
      "what": "video",
      "to_seconds": 2.96
    }
  }
}
```

## Errors

| code | error | When |
|---|---|---|
| 401 | `authentication_error` | Missing or invalid key |
| 400 | `invalid_request_error` | `taskId` missing or `answer` is not 1 or 0 |
| 404 | `task_not_found` | No such task in your account |
| 409 | `not_awaiting_confirmation` | The task no longer waits for an answer (already started or closed) |
| 402 | `payment_required` | Not enough balance for answer 1, the task keeps waiting |
