完成一次视频生成
创建异步任务,可靠轮询终态并取得视频结果。文生视频完整流程
创建请求返回任务对象。客户端应使用任务 ID 轮询,采用有上限的退避间隔,并设置总等待时间。
curl
Python
Node.js
curl
#!/usr/bin/env bash
set -euo pipefail
task=$(curl -fsS https://api.noxgate.net/v1/videos/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{"model":"YOUR_MODEL_ID","prompt":"Ocean waves at sunrise","duration":5,"ratio":"16:9"}')
task_id=$(printf '%s' "$task" | jq -r '.id')
for delay in 2 3 5 8 10 10 10 10 10 10; do
sleep "$delay"
task=$(curl -fsS "https://api.noxgate.net/v1/videos/generations/$task_id" \
-H "Authorization: Bearer sk-your-api-key")
status=$(printf '%s' "$task" | jq -r '.status')
case "$status" in succeeded) printf '%s
' "$task" | jq .; exit 0 ;; failed|canceled|cancelled) printf '%s
' "$task" >&2; exit 1 ;; esac
done
echo "Video generation timed out" >&2
exit 1图生视频完整流程
模型支持时增加 image_url、image_urls 或 media。参考资源必须为上游可访问 URL;比例、时长、分辨率和音频生成能力依模型而定。
curl
Python
Node.js
curl
#!/usr/bin/env bash
set -euo pipefail
task=$(curl -fsS https://api.noxgate.net/v1/videos/generations \
-H "Authorization: Bearer sk-your-api-key" \
-H "Content-Type: application/json" \
-d '{"model":"YOUR_MODEL_ID","image_url":"https://example.com/start.png","prompt":"A gentle camera move across the scene","duration":5}')
task_id=$(printf '%s' "$task" | jq -r '.id')
status=$(printf '%s' "$task" | jq -r '.status')
deadline=$((SECONDS + 600))
delay=2
while [[ "$status" != "succeeded" ]]; do
case "$status" in failed|canceled|cancelled) printf '%s\n' "$task" >&2; exit 1 ;; esac
[[ $SECONDS -ge $deadline ]] && { echo "Video generation timed out" >&2; exit 1; }
sleep "$delay"
task=$(curl -fsS "https://api.noxgate.net/v1/videos/generations/$task_id" \
-H "Authorization: Bearer sk-your-api-key")
status=$(printf '%s' "$task" | jq -r '.status')
(( delay < 10 )) && delay=$((delay + 2))
done
printf '%s\n' "$task" | jq .终态、取消与下载
- succeeded:读取 result.url,并尽快下载。
- failed:记录 error 和响应中的 request ID 后停止轮询。
- canceled 或 cancelled:按用户取消处理。
- 不再需要任务时可调用 DELETE /v1/videos/generations/:task_id。
curl
Python
Node.js
curl
curl -fsS -X DELETE "https://api.noxgate.net/v1/videos/generations/video_task_example" \
-H "Authorization: Bearer sk-your-api-key"
echo "Cancellation accepted"curl
Python
Node.js
curl
#!/usr/bin/env bash
set -euo pipefail
task=$(curl -fsS "https://api.noxgate.net/v1/videos/generations/video_task_example" \
-H "Authorization: Bearer sk-your-api-key")
status=$(printf '%s' "$task" | jq -r '.status')
[[ "$status" == "succeeded" ]] || { printf '%s\n' "$task" >&2; exit 1; }
result_url=$(printf '%s' "$task" | jq -r '.result.url // empty')
[[ -n "$result_url" ]] || { echo "Successful task has no result URL" >&2; exit 1; }
if [[ "$result_url" == /* ]]; then result_url="https://api.noxgate.net$result_url"; fi
curl -fL "$result_url" -o generated-video.mp4