# カスタムテンプレート API

> よく使う編集設定をテンプレートとして保存し、1 つの ID で AI クリッピングとクリップ書き出しに適用します。

## カスタムテンプレート API

編集設定をテンプレートとして保存し、[AI クリッピング](https://wayin.ai/ja/api-docs/ai-clipping/) または [クリップ書き出し](https://wayin.ai/ja/api-docs/clips-export/) に `custom_template_id` を渡すと、設定一式を一度に適用できます。

テンプレートには、画角とレイアウト、字幕スタイル、絵文字、B-roll、AI Hook、音声強調、フィラー語の除去、無音の除去、イントロ、アウトロ、ロゴを含められます。

テンプレートは、ウェブサイトの **My Template** と同じデータです。ウェブサイトで作ったテンプレートはここで一覧でき、ここで作ったテンプレートはウェブサイトにも表示されます。

## プランの上限

| プラン | 保存できるテンプレート数 |
|--------|--------------------------|
| Free | 利用不可 |
| Starter | 1 |
| Pro | 3 |
| Scale | 10。2 件以上購入すると上限は 20 になります。 |

ロゴ、イントロ、アウトロのアップロードにも有料プランが必要で、ストレージ容量を使います。[サブスクリプションプラン](https://wayin.ai/wayinvideo/settings/plan)を参照してください。

## 手順

1. テンプレートにロゴ、イントロ、アウトロが必要なときだけ**素材をアップロード**します。字幕、画角、その他の設定にはアップロードは不要です。
2. テンプレートを**作成**します。ロゴ、イントロ、アウトロの位置は、指定した配置からプラットフォームが決めます。座標は送らないでください。
3. 現在の設定が必要なときは、テンプレートを**一覧または取得**します。
4. `POST /api/v2/clips` または `POST /api/v2/clips/export` に `custom_template_id` を渡して**適用**します。
5. **更新**はテンプレート全体を置き換えます。リクエストにない機能は削除されます。先に現在のテンプレートを読み、編集した全体を送信してください。
6. 不要になったテンプレートを**削除**します。

## エンドポイント

| メソッド | パス | 説明 |
|----------|------|------|
| `POST` | `/api/v2/upload/single-file` | ロゴ、イントロ、アウトロのアップロード URL を取得 |
| `POST` | `/api/v2/upload/status` | ファイルが使えるまでポーリング |
| `POST` | `/api/v2/custom-templates` | テンプレートを作成 |
| `GET` | `/api/v2/custom-templates` | テンプレート一覧 |
| `GET` | `/api/v2/custom-templates/{id}` | テンプレートを 1 件取得 |
| `PUT` | `/api/v2/custom-templates/{id}` | テンプレートを置き換え |
| `DELETE` | `/api/v2/custom-templates/{id}` | テンプレートを削除 |

すべてのリクエストに次のヘッダーが必要です。

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

`GET` と `DELETE` に `Content-Type` は不要です。

---

## ロゴ、イントロ、アウトロをアップロード

署名付き URL を取得し、その URL にファイルを `PUT` してから、`status` が `DONE` になるまでポーリングします。返却された `identity` をテンプレートの `resource.identify` に入れます。

ロゴ、イントロ、アウトロを使わないテンプレートでは、この手順を省略します。通常の動画アップロードは [アップロード API](https://wayin.ai/ja/api-docs/upload/) を参照してください。

```http
POST https://wayinvideo-api.wayin.ai/api/v2/upload/single-file
```

### リクエストボディ

| パラメータ | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `name` | string | はい | 拡張子付きのファイル名。拡張子で形式を確認します。 |
| `size` | integer | いいえ | ファイルサイズ（バイト）。サイズ上限とストレージ枠の確認に使います。 |
| `resource_type` | string | テンプレート素材では必須 | ファイルの用途。下表を参照。省略すると通常の動画として扱われ、テンプレートでは使えません。 |

| `resource_type` | 用途 | 形式 | サイズ上限 | 長さの上限 |
|-----------------|------|------|------------|------------|
| `BRAND_KIT_LOGO` | `logo` | `.jpg`、`.jpeg`、`.png`、`.webp` | 10 MB | — |
| `BRAND_KIT_VIDEO` | `intro`、`outro` | `.mp4`、`.mov`、`.webm`、`.avi` | 5 GB | 60 分 |

### リクエスト例

```bash
curl -X POST https://wayinvideo-api.wayin.ai/api/v2/upload/single-file \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2" \
  -d '{
    "name": "brand-logo.png",
    "size": 204800,
    "resource_type": "BRAND_KIT_LOGO"
  }'
```

### レスポンス

```json
{
  "data": {
    "upload_url": "https://storage.example.com/upload/presigned-url...",
    "identity": "EF_up_06wguq1afbwg1"
  }
}
```

| フィールド | 型 | 説明 |
|------------|-----|------|
| `upload_url` | string | 署名付きアップロード URL。期限があるため、取得後すぐにアップロードしてください。 |
| `identity` | string | ファイル ID。テンプレートの作成または更新時に `resource.identify` へ入れます。 |

### ファイルをアップロード

```bash
curl -X PUT "https://storage.example.com/upload/presigned-url..." \
  --upload-file ./brand-logo.png
```

HTTP `200` はファイルを受け取ったことを示します。その後プラットフォームが処理します。処理が終わるまでステータスをポーリングしてください。

### アップロード状態を確認

3〜5 秒ごとにポーリングし、`status` が `DONE` または `ERROR` になるまで待ちます。テンプレートに使えるのは `status` が `DONE` のファイルだけです。

```http
POST https://wayinvideo-api.wayin.ai/api/v2/upload/status
```

| パラメータ | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `identify` | string | はい | アップロード URL のリクエストが返した `identity`。 |

```bash
curl -X POST https://wayinvideo-api.wayin.ai/api/v2/upload/status \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2" \
  -d '{
    "identify": "EF_up_06wguq1afbwg1"
  }'
```

```json
{
  "data": {
    "status": "DONE",
    "file_name": "brand-logo.png",
    "url": "https://cdn.example.com/user/brand-logo.png"
  }
}
```

| フィールド | 型 | 説明 |
|------------|-----|------|
| `status` | string | `START`：ファイルが届いていません。`PUT` が成功したか確認してください。`UPLOADED`：ファイルは届き、処理中です。`DONE`：使用できます。`ERROR`：処理に失敗しました。再アップロードしてください。 |
| `file_name` | string | ファイル名。 |
| `url` | string | ファイル URL。 |

---

<a id="create-a-template"></a>

## テンプレートを作成

```http
POST https://wayinvideo-api.wayin.ai/api/v2/custom-templates
```

### リクエストボディ

| パラメータ | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `name` | string | はい | テンプレート名。空にはできません。 |
| `config` | object | はい | 保存する機能。各キーが 1 つの機能です。[設定フィールド](#config-fields)を参照。`{}` は可、`null` は不可。他の機能を送る場合は `reframe` が必須です。 |

`config` にある機能は、適用時に [AI クリッピング](https://wayin.ai/ja/api-docs/ai-clipping/) の対応するパラメータを上書きします。`config` にない機能は、そのクリッピングまたは書き出しリクエストの値を使います。

### リクエスト例

```bash
curl -X POST https://wayinvideo-api.wayin.ai/api/v2/custom-templates \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2" \
  -d '{
    "name": "Brand A - Shorts",
    "config": {
      "reframe": {
        "ratio": "RATIO_9_16",
        "layout_type": "Fit",
        "auto_reframe": true
      },
      "caption_style": {
        "mode": "on",
        "template_id": "word-focus"
      },
      "emoji": { "operation": "add" },
      "broll": {
        "operation": "add",
        "resource_type": "RESOURCE_VIDEO_STOCK_BROLL"
      },
      "ai_hook": {
        "operation": "add",
        "template_id": "preset-1",
        "script_style": "casual",
        "position": "beginning"
      },
      "speech_enhance": { "operation": "clean" },
      "remove_filter": { "operation": "remove" },
      "remove_silence": {
        "operation": "remove",
        "silence_duration_ms": 500
      },
      "intro": {
        "operation": "add",
        "resource": { "identify": "EF_up_06wgintro0001" }
      },
      "outro": {
        "operation": "add",
        "resource": { "identify": "EF_up_06wgoutro0001" }
      },
      "logo": {
        "operation": "add",
        "items": [
          {
            "resource": { "identify": "EF_up_06wguq1afbwg1" },
            "position": "top_right"
          }
        ]
      }
    }
  }'
```

### レスポンス

保存されたテンプレートです。形は [テンプレートを取得](#get-a-template) と同じです。

```json
{
  "data": {
    "id": "uctmpl06yf2m0m1b0pv",
    "name": "Brand A - Shorts",
    "config": {
      "reframe": {
        "ratio": "RATIO_9_16",
        "layout_type": "Fit",
        "auto_reframe": true
      }
    },
    "created": 1764057600000,
    "last_modified": 1764057600000
  }
}
```

---

## テンプレート一覧

現在のアカウントまたはワークスペースのテンプレートを、新しい順に返します。テンプレートがないとき `data` は `[]` です。

```http
GET https://wayinvideo-api.wayin.ai/api/v2/custom-templates
```

### リクエスト例

```bash
curl -X GET https://wayinvideo-api.wayin.ai/api/v2/custom-templates \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2"
```

### レスポンス例

```json
{
  "data": [
    {
      "id": "uctmpl06yf2m0m1b0pv",
      "name": "Brand A - Shorts",
      "config": {
        "reframe": {
          "ratio": "RATIO_9_16",
          "layout_type": "Fit",
          "auto_reframe": true
        }
      },
      "created": 1764057600000,
      "last_modified": 1764144000000
    }
  ]
}
```

| フィールド | 型 | 説明 |
|------------|-----|------|
| `id` | string | テンプレート ID。`uctmpl` で始まります。 |
| `name` | string | テンプレート名。 |
| `config` | object | 保存された設定。[テンプレートを取得](#get-a-template)を参照。 |
| `created` | integer | 作成時刻。ミリ秒の Unix タイムスタンプ。 |
| `last_modified` | integer | 最終更新時刻。ミリ秒の Unix タイムスタンプ。 |

---

<a id="get-a-template"></a>

## テンプレートを取得

```http
GET https://wayinvideo-api.wayin.ai/api/v2/custom-templates/{id}
```

### パスパラメータ

| パラメータ | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `id` | string | はい | 作成または一覧で返ったテンプレート ID。 |

### リクエスト例

```bash
curl -X GET https://wayinvideo-api.wayin.ai/api/v2/custom-templates/uctmpl06yf2m0m1b0pv \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2"
```

### レスポンス例

```json
{
  "data": {
    "id": "uctmpl06yf2m0m1b0pv",
    "name": "Brand A - Shorts",
    "config": {
      "reframe": {
        "ratio": "RATIO_9_16",
        "layout_type": "Fit",
        "auto_reframe": true
      },
      "caption_style": {
        "mode": "on",
        "template_id": "word-focus"
      },
      "intro": {
        "operation": "add",
        "resource": {
          "identify": "EF_up_06wgintro0001",
          "url": "https://cdn.example.com/user/intro.mp4",
          "name": "intro"
        }
      },
      "logo": {
        "operation": "add",
        "items": [
          {
            "resource": {
              "identify": "EF_up_06wguq1afbwg1",
              "url": "https://cdn.example.com/user/brand-logo.png",
              "name": "brand-logo"
            },
            "position": "top_right"
          }
        ]
      }
    },
    "created": 1764057600000,
    "last_modified": 1764144000000
  }
}
```

| フィールド | 型 | 説明 |
|------------|-----|------|
| `id` | string | テンプレート ID。 |
| `name` | string | テンプレート名。 |
| `config` | object | テンプレート設定。このページのフィールド以外に、`transform`、`operation`、`extra` などの内部フィールドが含まれることがあります。更新時はそのまま戻せます。戻した `transform` はそのまま再利用されます。ロゴ項目に `position` もある場合、その項目の `transform` は捨てられ、`position` から配置が作り直されます。素材オブジェクトには `url` と `name` が付くことがあります。プラットフォームが読むのは `identify` だけです。 |
| `created` | integer | 作成時刻。ミリ秒の Unix タイムスタンプ。 |
| `last_modified` | integer | 最終更新時刻。ミリ秒の Unix タイムスタンプ。 |

ウェブサイトでドラッグして置いたロゴには `position` がありません。その項目にあるのは `transform` だけです。そのまま戻すと配置は維持されます。`position` を足すと、新しい位置に置き直されます。

---

## テンプレートを更新

テンプレート全体の `name` と `config` を置き換えます。`config` にない機能は削除されます。部分更新ではありません。ロゴ、イントロ、アウトロの配置は新しい設定から再計算されます。

[テンプレートを取得](#get-a-template) で現在のオブジェクトを読み、編集してから完全なボディを送信してください。

```http
PUT https://wayinvideo-api.wayin.ai/api/v2/custom-templates/{id}
```

ボディは [テンプレートを作成](#create-a-template) と同じです。`name` と `config` はどちらも必須です。

### リクエスト例

この例は画角、字幕、ロゴを残し、ロゴを右下へ移します。以前保存されていたイントロはこのボディにないため削除されます。

```bash
curl -X PUT https://wayinvideo-api.wayin.ai/api/v2/custom-templates/uctmpl06yf2m0m1b0pv \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2" \
  -d '{
    "name": "Brand A - Shorts v2",
    "config": {
      "reframe": {
        "ratio": "RATIO_9_16",
        "layout_type": "Fit",
        "auto_reframe": true
      },
      "caption_style": {
        "mode": "on",
        "template_id": "word-focus"
      },
      "logo": {
        "operation": "add",
        "items": [
          {
            "resource": { "identify": "EF_up_06wguq1afbwg1" },
            "position": "bottom_right"
          }
        ]
      }
    }
  }'
```

### レスポンス

更新後のテンプレートです。形は [テンプレートを取得](#get-a-template) と同じです。

---

## テンプレートを削除

```http
DELETE https://wayinvideo-api.wayin.ai/api/v2/custom-templates/{id}
```

削除は取り消せません。この ID で後から取得または適用すると、テンプレートが存在しないため失敗します。すでにこのテンプレートで生成または書き出したクリップは変わりません。テンプレートが参照するファイルは削除されません。

### リクエスト例

```bash
curl -X DELETE https://wayinvideo-api.wayin.ai/api/v2/custom-templates/uctmpl06yf2m0m1b0pv \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "x-wayinvideo-api-version: v2"
```

### レスポンス

```json
{
  "data": null
}
```

---

## テンプレートを適用

JSON ボディに `custom_template_id` を追加します。

[AI クリッピング](https://wayin.ai/ja/api-docs/ai-clipping/) では、`enable_export` が `true` のときだけ `custom_template_id` が使われます。[クリップ書き出し](https://wayin.ai/ja/api-docs/clips-export/) では、書き出しリクエスト自体がレンダリングなので、ID を送れば適用されます。

```json
{
  "video_url": "https://www.youtube.com/watch?v=example",
  "target_lang": "en",
  "enable_export": true,
  "custom_template_id": "uctmpl06yf2m0m1b0pv"
}
```

| 場合 | 結果 |
|------|------|
| テンプレートとリクエストが同じ機能を設定している | テンプレートが優先されます。たとえばテンプレートの `caption_style` は、リクエストの `cc_style_tpl` を上書きします。 |
| リクエストが、テンプレートにない機能を設定している | リクエストの値が使われます。 |
| テンプレートが、リクエストにない機能を設定している | テンプレートの値が使われます。 |

テンプレートはタスク送信時に読み取られます。その後の編集や削除は、すでに送信されたタスクには影響しません。

---

<a id="config-fields"></a>

## 設定フィールド

各キーは 1 つの機能です。保存しない機能は書かないでください。`reframe` は必須です。

### `reframe`

| フィールド | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `ratio` | string | はい | `RATIO_16_9`、`RATIO_1_1`、`RATIO_4_5`、`RATIO_9_16`。 |
| `layout_type` | string | はい | レイアウト。許可される値は `ratio` によって変わります。空白を含めて名前を正確に送ってください。 |
| `auto_reframe` | boolean | いいえ | AI による被写体追従を有効にします。 |

| `ratio` | 許可される `layout_type` |
|---------|--------------------------|
| `RATIO_16_9` | `Auto`、`Full`、`Fit`、`Grid 4`、`Split 2`、`Trio`、`PiP`、`OTS`、`Screen First` |
| `RATIO_9_16` | `Auto`、`Full`、`Fit`、`Grid 4`、`Split 2`、`Trio`、`PiP`、`Screen First`、`Gameplay A`、`Gameplay B` |
| `RATIO_4_5` | `Auto`、`Full`、`Fit`、`Grid 4`、`Split 2`、`Trio`、`PiP`、`Screen First`、`Gameplay A`、`Gameplay B` |
| `RATIO_1_1` | `Auto`、`Full`、`Fit`、`Grid 4`、`Trio` |

### `caption_style`

| フィールド | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `mode` | string | はい | `on` は字幕を表示します。`off` は字幕を隠し、`inherit` は字幕をクリッピングまたは書き出しリクエストに任せます。 |
| `template_id` | string | `mode` が `on` のとき必須 | システムテンプレート ID。[字幕スタイル](https://wayin.ai/ja/api-docs/subtitles-style/)を参照。 |

### `emoji`

| フィールド | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `operation` | string | はい | `add` は絵文字を自動で入れます。`remove` は絵文字を入れません。 |

### `broll`

| フィールド | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `operation` | string | はい | `add` は B-roll を入れます。`remove` は B-roll を入れず、書き出し時に既存の B-roll も外します。 |
| `resource_type` | string | いいえ | `RESOURCE_VIDEO_AI_BROLL` は AI 生成です。`RESOURCE_VIDEO_STOCK_BROLL` はストック素材です。 |

### `ai_hook`

| フィールド | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `operation` | string | はい | `add` は AI Hook を入れます。`remove` は入れず、書き出し時に既存の Hook も外します。`remove` のときは他のフィールドは不要です。 |
| `template_id` | string | `operation` が `add` のとき必須 | システムテンプレート ID。[フックテキストスタイル](https://wayin.ai/ja/api-docs/hook-text-styles/)を参照。 |
| `script_style` | string | いいえ | 文案のスタイル。既定値は `serious`。指定できる値：`serious`、`casual`、`informative`、`conversational`、`humorous`、`parody`、`inspirational`、`dramatic`、`empathetic`、`persuasive`、`neutral`、`excited`、`calm`。 |
| `position` | string | いいえ | `beginning` または `end`。既定値は `beginning`。 |
| `keywords` | string | いいえ | Hook が沿うキーワード。 |
| `text_duration` | integer | いいえ | Hook の文字を画面に出す時間（ミリ秒）。 |

### `speech_enhance`

| フィールド | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `operation` | string | はい | `clean` は音声強調とノイズ低減を有効にします。`restore` は元の音声を残します。 |

### `remove_filter`

| フィールド | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `operation` | string | はい | `remove` は "um" や "uh" などのフィラーを切ります。`restore` は残します。 |

### `remove_silence`

| フィールド | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `operation` | string | はい | `remove` は無音区間を切ります。`restore` は残します。 |
| `silence_duration_ms` | integer | いいえ | 切る無音の最短時間（ミリ秒）。既定値は `500`。 |

### `intro` と `outro`

両方のオブジェクトは同じフィールドです。イントロは各クリップの先頭、アウトロは末尾に付き、テンプレートの画角に合わせて配置されます。

| フィールド | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `operation` | string | はい | `add` は素材を入れます。`remove` は適用時に既存のイントロまたはアウトロを外します。`remove` のときは他のフィールドは不要です。 |
| `resource.identify` | string | `operation` が `add` のとき必須 | アップロードで返った `identity`。アップロード時の `resource_type` は `BRAND_KIT_VIDEO` である必要があります。 |

### `logo`

| フィールド | 型 | 必須 | 説明 |
|------------|-----|------|------|
| `operation` | string | はい | `add` はロゴを入れます。`remove` は適用時に既存のロゴを外します。`remove` のとき `items` は不要です。 |
| `items` | array | `operation` が `add` のとき必須 | ロゴの一覧。1 件以上。 |
| `items[].resource.identify` | string | `operation` が `add` のとき必須 | アップロードで返った `identity`。アップロード時の `resource_type` は `BRAND_KIT_LOGO` である必要があります。 |
| `items[].position` | string | はい | `top_left`、`top_right`、`center`、`bottom_left`、`bottom_right`。更新時に詳細の `transform` を戻す場合、`position` は省略でき、以前の配置が維持されます。`position` を送るとロゴは置き直されます。 |

ロゴのサイズと余白はプラットフォームの既定値です。
