> ## 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/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/api-reference/webhooks.md) 了解传送要求和重试行为。

## 计费

新提交的非 LLM 请求按 **1 积分 = `$0.001`** 计费。先按用量和附加项目计算总额，再应用账号折扣，最后将请求总额向上取整到整数积分。如果约定了固定单价，则按该单价的原始精度计算，不再使用标准价或另行打折；最终积分仍向上取整。详见[积分换算与取整](https://apixo.ai/docs/zh/pricing.md#credit-conversion-and-rounding)。

LTX 2 19B 按秒计费。后端通过 `resolution` 和基本 vs LoRA 模式选择单价，然后将该单价乘以提交的 `duration`。

| 分辨率 | 基本模式价格 | LoRA 模式价格 | 最低 5s 成本 |
| - | - | - | - |
| `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/api-reference/system.md)。

## 错误与排查

### HTTP 错误

| 代码 | 含义 | 处理方式 |
| - | - | - |
| `400` | 请求体无效、缺少 `input`、缺少 `mode`、缺少 `prompt`、无效 `resolution`、无效 `duration`、无效 `seed`、无效 `image_urls` 或无效 `loras` | 在重试前修复请求 |
| `401` | 缺少 API 密钥，或密钥无效 | 检查 `Authorization` 请求头 |
| `402` | 余额或配额不足 | 充值或更换账号或API密钥 |
| `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，且该 URL 返回 `200` 或 `206` 状态码 |
| `RateLimited` | 请求频率达到上限 | 按指数退避策略重试 |
| `Timeout` | 任务超时 | 重试、简化请求或者使用回调方式 |
| `Unknown error` | 任务因未知原因失败 | 逐步延长间隔后重试，或联系支持团队并提供 `taskId` |

完整列表见[错误码](https://apixo.ai/docs/zh/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/models.md)
* [视频模型](https://apixo.ai/docs/zh/models/video)
* [提交生成任务](https://apixo.ai/docs/zh/api-reference/generate-task.md)
* [查询任务状态](https://apixo.ai/docs/zh/api-reference/status-task.md)
* [Webhook](https://apixo.ai/docs/zh/api-reference/webhooks.md)
* [错误码](https://apixo.ai/docs/zh/api-reference/errors.md)
* [参数规范](https://apixo.ai/docs/zh/api-reference/parameters.md)
* [路由策略](https://apixo.ai/docs/zh/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.