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

# 文生视频

> 仅凭文字提示词生成 5–15 秒、带原生音频的 Viggle H3 视频，无需输入文件。

文生视频把一段文字描述变成带原生音频的 MP4。你发送提示词，Viggle H3 规划并渲染镜头，然后你下载结果。它不需要任何图片或视频，因此是试用 API 最快的方式。

当你能用文字描述镜头、且不需要匹配现有图片时使用它。要从一张静态图开始，请使用[首帧生视频](https://docs.viggle.ai/zh/v1/video/first-frame-to-video.md)。要从你自己的素材中带入主体或风格，请使用[参考生视频](https://docs.viggle.ai/zh/v1/video/reference-to-video.md)。

## 请求内容

以 `multipart/form-data` 调用 `POST /v1/videos`。只发送提示词（不带帧画面、参考或 Remake 字段）即选择文生视频。

| 参数 | 必填 | 说明 |
| - | - | - |
| `prompt` | 是 | 镜头内容：主体、动作、场景、运镜。不能为空 |
| `quality` | 是 | `low`（更快）或 `high`（保真度更高），价格相同。也可以用 [`ultrafast`](https://docs.viggle.ai/zh/v1/video/generate-video#ultrafast)，最快的档位，单独定价 |
| `duration_s` | 否 | 5–15 秒，默认 `5` |
| `resolution` | 否 | `480p`、`768p`（默认）、`1080p`、`2k`、`4k` |
| `aspect_ratio` | 否 | `16:9`（默认）、`9:16`、`1:1`、`4:3`、`3:4`、`21:9` |
| `enhance` | 否 | 默认 `true`。生成前先经过一轮规划，改写提示词 |

其余选项（`seed`、`watermark`）见[通用参数](https://docs.viggle.ai/zh/v1/video/generate-video#common-parameters)和 [API 参考](https://docs.viggle.ai/zh/v1/api-reference/videos/create-a-video.md)。

## 价格

按视频秒数和 `resolution` 计费，开启 `enhance` 时每秒另加 $0.01。下面的示例（5 秒，768p，开启 enhance）消耗 5 × (1 + 1) = 10 积分（$0.10）。全部单价见[概览](https://docs.viggle.ai/zh/v1/video/generate-video#price)。

## 生成视频

将密钥导出为 `VIGGLE_API_KEY`，然后直接运行以下任一脚本。每个脚本都会提交任务、每 5 秒轮询一次，并打印视频 URL。cURL 版本需要 `jq`。

```bash cURL theme={null}
#!/usr/bin/env bash
set -euo pipefail
API="https://apis.viggle.ai/v1"

video_id=$(curl -sS --fail-with-body "$API/videos" \
  -H "Authorization: Bearer $VIGGLE_API_KEY" \
  -F prompt="a paper airplane gliding through a sunlit office" \
  -F quality=low \
  -F duration_s=5 | jq -er '.id')
echo "Submitted $video_id"

for _ in $(seq 1 1440); do
  video=$(curl -sS --fail-with-body "$API/videos/$video_id" \
    -H "Authorization: Bearer $VIGGLE_API_KEY")
  case $(echo "$video" | jq -r '.status') in
    ready) echo "$video" | jq -r '.video_url'; exit 0 ;;
    failed|cancelled) echo "$video" | jq -c '.error' >&2; exit 1 ;;
  esac
  sleep 5
done
echo "Timed out waiting for $video_id" >&2; exit 1
```

```javascript Node.js theme={null}
// Node.js 20+。保存为 text-to-video.mjs，然后运行：node text-to-video.mjs
const API = "https://apis.viggle.ai/v1";
const headers = { Authorization: `Bearer ${process.env.VIGGLE_API_KEY}` };

async function call(path, init = {}) {
  const res = await fetch(`${API}${path}`, { ...init, headers });
  const body = await res.json();
  if (!res.ok) throw new Error(`HTTP ${res.status}: ${JSON.stringify(body.error)}`);
  return body;
}

const form = new FormData();
form.append("prompt", "a paper airplane gliding through a sunlit office");
form.append("quality", "low");
form.append("duration_s", "5");
const { id } = await call("/videos", { method: "POST", body: form });
console.log(`Submitted ${id}`);

for (let i = 0; i < 1440; i++) {
  const video = await call(`/videos/${id}`);
  if (video.status === "ready") {
    console.log(video.video_url);
    process.exit(0);
  }
  if (video.status === "failed" || video.status === "cancelled") {
    throw new Error(`${video.status}: ${JSON.stringify(video.error)}`);
  }
  await new Promise((resolve) => setTimeout(resolve, 5000));
}
throw new Error(`Timed out waiting for ${id}`);
```

```python Python theme={null}
import os
import time

import requests

API = "https://apis.viggle.ai/v1"
HEADERS = {"Authorization": f"Bearer {os.environ['VIGGLE_API_KEY']}"}


def check(resp):
    if not resp.ok:
        raise RuntimeError(f"HTTP {resp.status_code}: {resp.text}")
    return resp.json()


# 通过 files= 传字段，requests 会以 multipart/form-data 发送，
# 这是该接口要求的格式。只用 data= 会发送 urlencoded 请求体。
video = check(requests.post(f"{API}/videos", headers=HEADERS, files={
    "prompt": (None, "a paper airplane gliding through a sunlit office"),
    "quality": (None, "low"),
    "duration_s": (None, "5"),
}))
print("Submitted", video["id"])

for _ in range(1440):
    video = check(requests.get(f"{API}/videos/{video['id']}", headers=HEADERS))
    if video["status"] == "ready":
        print(video["video_url"])
        break
    if video["status"] in ("failed", "cancelled"):
        raise RuntimeError(f"{video['status']}: {video['error']}")
    time.sleep(5)
else:
    raise TimeoutError(f"Timed out waiting for {video['id']}")
```

创建请求会立即返回任务 ID：

```json theme={null}
{ "id": "vid_7d3f0b8e-2c41-4f6a-9b1e-5a2c8d4e6f10", "status": "queued", "progress": null, "created_at": "2026-11-20T09:12:03Z" }
```

> [!WARNING]
>
> 如果余额不足以支付该任务，请求仍会被接受，随后任务以 `failed` 结束，`error.code: "INSUFFICIENT_CREDITS"`。大批量提交前请先调用 `GET /v1/credits` 查看余额。

## 获取结果

任务运行期间，`GET /v1/videos/{video_id}` 会返回 `status`（先是 `queued`，然后是 `processing`），排队时还会返回 `queue_position` 和 `estimated_wait_seconds`。`status` 为 `ready` 时，下载 `video_url`。

* 链接有效期为一小时。每次读取都会返回新链接，因此请重新读取任务，而不是保存链接。
* 视频在任务结束 24 小时后删除，请复制到你自己的存储中。
* 响应中包含实际使用的 `seed`。发送相同的 `seed` 和提示词，可以再次得到相近的结果。
* 只有创建该任务的 API 密钥才能读取它。

状态和失败处理见[任务生命周期](https://docs.viggle.ai/zh/v1/concepts/task-lifecycle.md)，错误码见[错误](https://docs.viggle.ai/zh/v1/production/errors.md)。

## 写出更好的提示词

* 描述一个镜头：画面里有谁或什么、发生了什么、在哪里、镜头如何运动。
* 探索阶段保持 `enhance` 开启，它会在生成前扩写简短的提示词。希望按原样使用你的提示词时再关闭（`enhance=false`，768p 下价格减半）。
* 先用 `quality=low` 迭代，最终成片再切换到 `high`。两者价格相同。

## 后续步骤

> [card] [首帧生视频](https://docs.viggle.ai/zh/v1/video/first-frame-to-video.md)
>
> 让静态图动起来，并保留其构图。

> [card] [参考生视频](https://docs.viggle.ai/zh/v1/video/reference-to-video.md)
>
> 从你自己的图片或视频中带入主体或风格。

> [card] [视频超分](https://docs.viggle.ai/zh/v1/video/upscale.md)
>
> 用 FlashVSR 将成片的分辨率提升一倍。

> [card] [创建视频（API 参考）](https://docs.viggle.ai/zh/v1/api-reference/videos/create-a-video.md)
>
> `POST /v1/videos` 的全部字段、限制和错误。


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