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

# LTX-2 19B API：Lightricks 文字生成影片與圖片生成影片模型

> Lightricks 影片產生 API，用於文字轉影片、圖生影片和 LoRA 工作流程

## 概覽

LTX 2 19B 是用於文字到影片和影像到影片工作流程的 Lightricks 影片生成模型。當您需要自訂樣式、字元或結構指導時，它還支援 LoRA 條件變體。

在 APIXO Playground 試用後，可依本頁範例呼叫 API。

| 功能 | 值 |
| - | - |
| 模型 ID | `ltx-2-19b` |
| 模式 | `text-to-video`, `image-to-video`, `text-to-video-LoRA`, `image-to-video-LoRA` |
| 提示詞長度 | 1 至 5000 個字元 |
| 參考圖片 | 確切地 1 個 URL 對應於 `image-to-video` 和 `image-to-video-LoRA`。 |
| 縱橫比 | `16:9`、`9:16` 用於文字轉影片模式。 |
| 解析度級距 | `480p`, `720p`, `1080p` |
| 長度 | 5-20 秒 |
| LoRA 控制 | 最多 3 個 LoRA 項目，每個項目皆包含 `path` 與 `scale`。 |
| 種子 | `-1` 或 `1` 至 `2147483647` |

## 端點與身分驗證

API 基底網址：

```text theme={null}
https://api.apixo.ai/api/v1
```

| 方法 | 端點 | 用途 |
| - | - | - |
| `POST` | `/generateTask/ltx-2-19b` | 送出生成任務 |
| `GET` | `/statusTask/ltx-2-19b?taskId={taskId}` | 查詢任務狀態並取得結果 |

每個請求都必須附上 APIXO API 金鑰：

```http theme={null}
Authorization: Bearer YOUR_API_KEY
```

送出任務時，還需設定以下請求標頭：

```http theme={null}
Content-Type: application/json
```

## 非同步請求範例

以下範例提交一個最簡單的文字生成影片任務，回應中會傳回 `taskId`。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/ltx-2-19b" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "async",
    "input": {
      "mode": "text-to-video",
      "prompt": "a cinematic shot of a small robot walking through a rainy neon street",
      "resolution": "720p",
      "duration": 10,
      "aspect_ratio": "16:9"
    }
  }'
```

成功回應：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678"
  }
}
```

請保留 `taskId`，後續輪詢結果時會用到。

## 輪詢結果

```bash theme={null}
curl -X GET "https://api.apixo.ai/api/v1/statusTask/ltx-2-19b?taskId=task_12345678" \
  -H "Authorization: Bearer YOUR_API_KEY"
```

任務處理中的回應範例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "processing",
    "createTime": 1767965610929
  }
}
```

成功回應：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://file.apixo.ai/video.mp4\"]}",
    "createTime": 1767965610929,
    "completeTime": 1767965652317,
    "costTime": 41388
  }
}
```

任務失敗時的回應範例：

```json theme={null}
{
  "code": 200,
  "message": "success",
  "data": {
    "taskId": "task_12345678",
    "state": "failed",
    "failCode": "SensitiveContent",
    "failMsg": "Content was rejected by safety checks, please adjust the prompt",
    "createTime": 1767965610929,
    "completeTime": 1767965620132
  }
}
```

等 `state` 變為 `success` 後，再解析 `resultJson`：

```javascript theme={null}
const payload = JSON.parse(data.resultJson);
const videoUrls = payload.resultUrls;
```

## 請求體

### 文生影片

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "text-to-video",
    "prompt": "a futuristic city with flying cars at sunset",
    "resolution": "1080p",
    "duration": 10,
    "aspect_ratio": "16:9",
    "seed": 54248617
  }
}
```

### 圖生影片

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-video",
    "prompt": "make the scene cinematic with a slow camera push and soft motion",
    "image_urls": [
      "https://example.com/source.jpg"
    ],
    "resolution": "720p",
    "duration": 8
  }
}
```

### 使用 LoRA 進行圖生影片

```json theme={null}
{
  "request_type": "async",
  "input": {
    "mode": "image-to-video-LoRA",
    "prompt": "animate this character in a stylized studio lighting setup",
    "image_urls": [
      "https://example.com/source.jpg"
    ],
    "resolution": "720p",
    "duration": 8,
    "loras": [
      {
        "path": "https://huggingface.co/username/model.safetensors?download=true",
        "scale": 1.2
      }
    ]
  }
}
```

## 參數

**request\_type** `string` *required* (default: async)

取得結果的方式。選擇 `async` 時，透過 `statusTask` 輪詢結果；選擇 `callback` 時，透過 Webhook 接收結果。

**callback\_url** `string`

當 `request_type` 為 `callback` 時必須提供。必須為公開的 HTTPS 端點，且能接收最終任務的負載。請參閱 [Webhooks](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)。

**input** `object` *required*

LTX 2 19B 的輸入參數。

**屬性**

**mode** `string` *required*

生成模式。可用值為 `text-to-video`、`image-to-video`、`text-to-video-LoRA`、`image-to-video-LoRA`。

**prompt** `string` *required*

描述所需影片的文字提示。必須非空且長度不能超過 5000 個字元。

**resolution** `string` *required*

輸出解析度級距。可用值為 `480p`、`720p`、`1080p`。

**duration** `integer` *required*

影片時長（以秒為單位）。必須是一個 JSON 整數，範圍從 `5` 到 `20`。

**image\_urls** `string[]`

對於 `image-to-video` 和 `image-to-video-LoRA` 是必需的。準確提供 1 公共、可直接存取的 JPG 或 PNG 影像 URL。

**aspect\_ratio** `string` (default: 16:9)

僅適用於文字轉影片模式。支援的值：`16:9`、`9:16`。若在文字轉影片中省略，後端將使用 `16:9`。

**seed** `integer`

可選種子。使用 `-1` 作為隨機選擇的種子，或發送從 `1` 到 `2147483647` 的整數。

**loras** `array`

選填的 LoRA 陣列，用於 LoRA 模式。最多支援 3 個項目。

**物品屬性**

**path** `string` *required*

可公開下載的 LoRA 模型 URL。該值必須是非空字串。

**scale** `number` *required*

LoRA 強度。必須是 `0.0` 到 `4.0` 之間的數字。

## 回應格式

### 送出任務時的回應

任務受理後，`POST /generateTask/ltx-2-19b` 會傳回任務 ID：

**code** `integer`

API 狀態碼。`200` 表示任務已受理。

**message** `string`

狀態說明。

**data.taskId** `string`

任務的唯一 ID，用於查詢任務狀態。

### 狀態回應欄位

**taskId** `string`

任務的唯一識別碼。

**state** `string`

目前的任務狀態，可能的值為 `pending`、`processing`、`success`、`failed`。

**resultJson** `string`

JSON 字串，包含 `resultUrls` 中產生的影片 URL。當 `state` 為 `success` 時存在。

**failCode** `string`

供程式判讀的錯誤碼，僅在 `state` 為 `failed` 時傳回。

**failMsg** `string`

失敗原因說明，僅在 `state` 為 `failed` 時傳回。

**createTime** `integer`

任務建立時的 Unix 時間戳記，單位為毫秒。

**completeTime** `integer`

任務完成時的 Unix 時間戳記，單位為毫秒。任務完成後才會傳回。

**costTime** `integer`

處理持續時間（如果可用）以毫秒為單位。完成後呈現。

## Webhook 回呼模式

若希望後端自動收到最終結果，可使用回呼模式，無須輪詢。

```bash theme={null}
curl -X POST "https://api.apixo.ai/api/v1/generateTask/ltx-2-19b" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "request_type": "callback",
    "callback_url": "https://your-server.com/webhooks/apixo",
    "input": {
      "mode": "text-to-video",
      "prompt": "a clean product reveal video with a slow camera push-in",
      "resolution": "720p",
      "duration": 10,
      "aspect_ratio": "16:9"
    }
  }'
```

回呼 `data` 物件使用與狀態回應相同的終端欄位。請參閱 [Webhooks](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md) 以了解傳送要求和重試行為。

## 計費

新提交的非 LLM 請求按 **1 點 = `$0.001`** 計費。先依用量和加購項目計算總額，再套用帳戶折扣，最後將請求總額無條件進位至整數點數。若已約定固定單價，則保留該單價的精度，不再使用標準價或另行打折；最終點數仍須進位。詳見[積分換算與進位](https://apixo.ai/docs/zh-hant/pricing.md#credit-conversion-and-rounding)。

LTX 2 19B 按秒計費。後端透過 `resolution` 和基本 vs LoRA 模式選擇單價，然後將該單價乘以提交的 `duration`。

| 解析度 | 基本模式價格 | LoRA 模式價格 | 最低 5 秒成本 |
| - | - | - | - |
| `480p` | `$0.012 / second` | `$0.015 / second` | 基數 `$0.06`；LoRA `$0.075` |
| `720p` | `$0.016 / second` | `$0.02 / second` | 基數 `$0.08`；LoRA `$0.10` |
| `1080p` | `$0.024 / second` | `$0.03 / second` | 基數 `$0.12`；LoRA `$0.15` |

公式：

```text theme={null}
total cost = duration * selected per-second unit price
```

最新的美元費率請見 [API 價目表](https://apixo.ai/pricing/api)。

## 耗時與輪詢

實際延遲可能因提示複雜性、持續時間、解析度、LoRA 載入、佇列負載和儲存傳輸時間而異

| 工作量 | 一般生成時間 | 建議首次查詢時間 | 輪詢間隔 |
| - | - | - | - |
| `480p` | 40s-60s | 任務建立 40 秒後 | 5s |
| `720p` | 60s-90s | 任務建立 60 秒後 | 5s |
| `1080p` | 90s-120s | 任務建立 90 秒後 | 5s |
| LoRA 模式 | 額外增加約 10 秒至 20 秒 | 在基礎首次輪詢中增加約 10 秒 | 5s |

> [!TIP]
>
> 對於生產影片工作負載，請使用回呼模式以避免在生成仍在運行時頻繁輪詢。

結果 URL 通常會儲存 15 天。請及時下載並儲存重要輸出。

對於影像到影片模式，請僅提供一張來源影像。公用影像 URL 應可透過 APIXO 直接存取；JPG、PNG 或 WebP 檔案是最安全的選擇。

對於 LoRA 工作流程，請使用公用可下載模型 URL，例如 Hugging Face 或 Civitai 下載連結。每個 LoRA 項目必須同時包含 `path` 和 `scale`，即使您想要像 `1.0` 這樣的中性比例。

請求頻率與並行數上限會依帳戶、API 金鑰和路由而異。收到 `429` 時，請降低請求頻率，並逐步拉長重試間隔。帳戶層級的限制請見[系統 API](https://apixo.ai/docs/zh-hant/api-reference/system.md)。

## 錯誤與排查

### HTTP 錯誤

| 代碼 | 含義 | 處理方式 |
| - | - | - |
| `400` | 請求主體無效、缺少 `input`、缺少 `mode`、缺少 `prompt`、無效 `resolution`、無效 `duration`、無效 `seed`、無效 `image_urls` 或無效 `loras` | 修正請求後再試 |
| `401` | 缺少 API 金鑰，或金鑰無效 | 檢查 `Authorization` 請求標頭 |
| `402` | 餘額或配額不足 | 充值或更換帳號或金鑰 |
| `403` | 金鑰或路由無權訪問該模型 | 檢查權限和路由策略 |
| `404` | 輪詢時未找到任務 | 檢視 `taskId` 和模型端點 |
| `429` | 已達到速率或並行限制 | 以指數退避方式重試 |
| `500` | 伺服器錯誤或未知任務失敗 | 逐步拉長間隔後重試 |
| `502` | 服務或網路錯誤 | 逐步拉長間隔後重試 |
| `503` | 服務暫時無法使用或非同步佇列已滿 | 稍後重試 |
| `504` | 服務超時 | 重新嘗試；耗時較長的任務可改用回呼模式 |

### 驗證說明

| 參數 | 後端行為 |
| - | - |
| `input.mode` | 路由所需。必須是 `text-to-video`、`image-to-video`、`text-to-video-LoRA`、`image-to-video-LoRA` 之一。 |
| `input.prompt` | 必需的字串。不能為空且不能超過 5000 個字元。 |
| `input.resolution` | 必填，型別為字串。必須使用下列其中一個值：`480p`、`720p`、`1080p`。 |
| `input.duration` | 必需的 JSON 整數。必須從 `5` 到 `20`；引號的字串無效。 |
| `input.image_urls` | 影像到影片模式所需。必須是恰好包含 1 個字串 URL 的陣列。 |
| `input.aspect_ratio` | 文字轉影片模式可選。必須是`16:9`或`9:16`；省略時預設為 `16:9`。 |
| `input.seed` | 選填的 JSON 整數。必須是 `-1`，或從 `1` 到 `2147483647`。 |
| `input.loras` | 選填陣列，最多包含 3 項。 |
| `input.loras[].path` | 每個 LoRA 項目都是必需的。必須是非空字串。 |
| `input.loras[].scale` | 每個 LoRA 項目都是必需的。必須是數值且在 `0.0` 到 `4.0` 之間。 |

### 任務失敗代碼

| 錯誤碼 | 含義 | 處理方式 |
| - | - | - |
| `SensitiveContent` / `InputOutputSensitiveContentDetected` | 提示、輸入影像或輸出未通過安全檢查 | 更改提示或輸入影像 |
| `PromptInvalid` | 提示被拒絕或格式錯誤 | 調整提示並重試 |
| `ImageFormatIncorrect` / `InvalidImageSize` | 輸入影像影像驗證失敗 | 使用公共直接的 JPG、PNG 或 WebP URL |
| `ImageNotAccess` | APIXO 無法取得輸入 URL。 | 使用公開 HTTP 或 HTTPS URL，且必須傳回 `200` 或 `206`。 |
| `RateLimited` | 請求頻率已達上限 | 以指數退避方式重試 |
| `Timeout` | 任務逾時 | 重試、簡化請求或使用回呼方式 |
| `Unknown error` | 任務因不明原因失敗 | 逐步拉長間隔後重試，或聯絡支援團隊並提供 `taskId` |

完整列表見[錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)。

## MCP 整合

[完整模型 Schema](https://apixo.ai/docs/models/schemas/video/ltx-2-19b.json) 中的 `mcp.result` 指定結果的解析方式，`mcp.attachments` 列出可繫結檔案的欄位。這些中繼資料供用戶端整合使用，無須當作生成參數提交。附件欄位為 `image_urls`。請保留使用者指定的檔案順序。模型參數由 API 驗證。

## 相關連結

* [生成 API 總覽](https://apixo.ai/docs/zh-hant/models.md)
* [影片模型](https://apixo.ai/docs/zh-hant/models/video)
* [送出生成任務](https://apixo.ai/docs/zh-hant/api-reference/generate-task.md)
* [查詢任務狀態](https://apixo.ai/docs/zh-hant/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh-hant/api-reference/webhooks.md)
* [錯誤碼](https://apixo.ai/docs/zh-hant/api-reference/errors.md)
* [參數規範](https://apixo.ai/docs/zh-hant/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh-hant/concepts/routing-strategies.md)
* [在 APIXO Playground 試用 LTX 2 19B](https://apixo.ai/models/ltx-2-19b)
* [API定價](https://apixo.ai/pricing/api)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.