# Video Enhancer API

> Enhance a platform video file or an uploaded file to 1080p, 2K, or 4K, with optional text sharpening and a clip of up to 10 minutes.

## Video Enhancer API

Submit a video that is already stored on the platform, or a file you uploaded, and receive an enhanced version at 1080p, 2K, or 4K. You can turn text sharpening on or off, and you can enhance the whole video or a clip of up to 10 minutes.

## Supported Video Sources

Pass a platform file URL, or the `identity` returned by the [Upload API](https://wayin.ai/api-docs/upload/). Local upload requires a **Starter** plan or above.

### Workflow

1. **Submit** an enhancement task with the source video and a target resolution
2. **Poll** the results until `status` is `DONE` or `ERROR`
3. When `status` is `DONE`, read `output_url`

---

## Endpoints

| Method | Path                                  | Description                  |
| ------ | ------------------------------------- | ---------------------------- |
| `POST` | `/api/v2/video-enhancer`              | Submit an enhancement task   |
| `GET`  | `/api/v2/video-enhancer/results/{id}` | Retrieve the task result     |

All requests require:

```http
Authorization: Bearer YOUR_API_KEY
Content-Type: application/json
x-wayinvideo-api-version: v2
```

---

## Submit Enhancement Task

```http
POST https://wayinvideo-api.wayin.ai/api/v2/video-enhancer
```

### Request Body

| Parameter        | Type    | Required | Default | Description                                                                                                                                                                                                 |
| ---------------- | ------- | -------- | ------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `video_url`      | string  | Yes      | —       | Platform file URL, or the `identity` returned by the [Upload API](https://wayin.ai/api-docs/upload/).                                                                                                                       |
| `target_res`     | string  | Yes      | —       | Output resolution. Allowed values: `1080p`, `2k`, `4k`.                                                                                                                                                     |
| `enable_text_hd` | boolean | No       | `true`  | Sharpen on-screen text. When this field is omitted, the default is `true`.                                                                                                                                 |
| `start_ms`       | integer | No       | —       | Clip start, in milliseconds. Omit both `start_ms` and `end_ms` to process the whole video, still subject to the 10-minute maximum. Sending only one of the two fields is rejected.                        |
| `end_ms`         | integer | No       | —       | Clip end, in milliseconds. Must be greater than `start_ms` and must not exceed the source duration.                                                                                                        |

The processed range cannot be longer than 10 minutes. Billing uses that range, rounded up to the next whole second. Rates are on the [Billing](https://wayin.ai/api-docs/pricing/) page.

### Example Request

```bash
curl -X POST https://wayinvideo-api.wayin.ai/api/v2/video-enhancer \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2" \
  -d '{
    "video_url": "EF_up_06wguq1afbwg1",
    "target_res": "1080p",
    "enable_text_hd": true,
    "start_ms": 0,
    "end_ms": 8000
  }'
```

```python
import requests

requests.post(
    "https://wayinvideo-api.wayin.ai/api/v2/video-enhancer",
    headers={
        "Authorization": "Bearer YOUR_API_KEY",
        "x-wayinvideo-api-version": "v2",
    },
    json={
        "video_url": "EF_up_06wguq1afbwg1",
        "target_res": "1080p",
        "enable_text_hd": True,
        "start_ms": 0,
        "end_ms": 8000,
    },
)
```

```javascript
await fetch('https://wayinvideo-api.wayin.ai/api/v2/video-enhancer', {
  method: 'POST',
  headers: {
    Authorization: 'Bearer YOUR_API_KEY',
    'x-wayinvideo-api-version': 'v2',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    video_url: 'EF_up_06wguq1afbwg1',
    target_res: '1080p',
    enable_text_hd: true,
    start_ms: 0,
    end_ms: 8000,
  }),
});
```

### Response

A newly submitted task is usually `PENDING` (still queued) or `IN_PROGRESS` (already running).

```json
{
  "data": {
    "id": "proj_01HQ2X8J3K4L5M6N7O8P9Q0R",
    "status": "IN_PROGRESS"
  }
}
```

| Field        | Type   | Description                                                                                          |
| ------------ | ------ | ---------------------------------------------------------------------------------------------------- |
| `id`         | string | Project id. Pass it in the results path.                                                            |
| `status`     | string | `PENDING` (queued), `IN_PROGRESS` (running), `DONE` (finished), or `ERROR` (failed).                 |
| `output_url` | string | URL of the enhanced video. Present only when `status` is `DONE`.                                    |

---

## Retrieve Enhancement Result

Poll with the `id` from the submit response until `status` is `DONE` or `ERROR`. When `status` is `DONE`, read `output_url`.

```http
GET https://wayinvideo-api.wayin.ai/api/v2/video-enhancer/results/{id}
```

### Example Request

```bash
curl -X GET https://wayinvideo-api.wayin.ai/api/v2/video-enhancer/results/proj_01HQ2X8J3K4L5M6N7O8P9Q0R \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2"
```

### Response

```json
{
  "data": {
    "id": "proj_01HQ2X8J3K4L5M6N7O8P9Q0R",
    "status": "DONE",
    "output_url": "https://cdn.viralhub.ai/user/video_0_8000_1080p.mp4"
  }
}
```

The fields match the submit response. `output_url` is included when the task is finished.

---

## Billing

Video Enhancer consumes **API Units** for the processed range, rounded up to the next whole second. A range shorter than 1 second is billed as 1 second.

| Target resolution | API Units        |
| ----------------- | ---------------- |
| 1080p             | 1 per second     |
| 2K (`2k`)         | 2 per second     |
| 4K (`4k`)         | 4 per second     |

If the account does not have enough API Units, the task is not created and no units are deducted. See [Billing](https://wayin.ai/api-docs/pricing/) and [Status Codes](https://wayin.ai/api-docs/status-codes/).

---

## Errors

Failed requests use the standard status codes and response formats. See [Status Codes](https://wayin.ai/api-docs/status-codes/).
