AI 视频
文生视频生成,支持状态轮询与取消。
概览
基础路径:
/v1/videoPython 命名空间:
ai.videotext
# Python
from infrai import ai
# TypeScript
import { InfraiClient } from "@infrai/sdk";
const client = new InfraiClient({ apiKey: process.env.INFRAI_API_KEY! });
// → client.video方法
video.generate
POST /v1/video/generate
启动一个文生视频任务。
Python
python
ai.video.generate(prompt, *, reference_image_url=None, duration_seconds=None, aspect=None, resolution="720p", prefer="balanced", model=None, vendor=None, idempotency_key=None)TypeScript
typescript
client.video.generate(opts: VideoGenerateOptions): Promise<VideoJob>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
prompt | string | 必填 | 目标视频的文本描述。 |
reference_image_url | string | 可选 | 可选参考图像 URL。 |
duration_seconds | number | 可选 | 片段时长(秒)。 |
aspect | "16:9" | "9:16" | "1:1" | 可选 | 宽高比。 |
resolution | "720p" | "1080p" | "4k" | 可选 | 输出分辨率(720p/1080p/4k);按供应商能力门控。 |
prefer | "balanced" | "cheapest" | "smartest" | 可选 | 优化轴:balanced(最佳性价比)| cheapest | smartest。 |
idempotency_key | string | 可选 | 可选去重 key;相同重试将返回同一结果。 |
返回
VideoJob { job_id, state, video_url?, thumbnail_url?, error? }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import ai
job = ai.video.generate("a timelapse of a city skyline at dusk",
resolution="1080p", prefer="balanced")
print("job:", job.get("job_id"), "| state:", job.get("state"))video.status
GET /v1/video/jobs/{id}
轮询视频任务的状态。
Python
python
ai.video.status(id=job_id)TypeScript
typescript
client.video.status(jobId: string): Promise<VideoJob>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 必填 | 任务标识。 |
返回
VideoJob示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import ai
job = ai.video.status(id="vid_...")
print("state:", job.get("state"), "| url:", job.get("video_url"))video.cancel
POST /v1/video/jobs/{id}/cancel
取消正在运行的视频任务。
Python
python
ai.video.cancel(id=job_id)TypeScript
typescript
client.video.cancel(jobId: string): Promise<{ ok }>参数
| 名称 | 类型 | 必填 | 说明 |
|---|---|---|---|
id | string | 必填 | 任务标识。 |
返回
{ ok: boolean }示例
一次性前置(每个范例都假定已完成):
bash
pip install infrai
# one-time auth (no secret needed): anonymous account + trial, writes ~/.infrai/credentials
python -c "from infrai import infra; infra.activate()"
# returning user instead: export INFRAI_API_KEY=ifr_pk_proj_...python
from infrai import ai
print("cancelled:", ai.video.cancel(id="vid_...").get("ok"))