Skip to content

视频生成 API 使用指南

Grok Imagine 文生视频。Base:https://api.ashpetals.com。令牌分组:Grok-Main

最后更新:2026-09-08(文生 4 秒已实测;图生视频仍不可用)

1. 三步

text
① POST /v1/videos     提交 model + prompt + seconds
② GET  /v1/videos/{id} 等到 completed 或 done
③ GET  /v1/videos/{id}/content  立刻保存 mp4(约 25 分钟失效)

HTTP 200 ≠ 成片。不要重复提交同一 prompt(会重复扣费)。

2. 准备

  1. 控制台 → API 密钥 → 新建,分组选 Grok-Main(不是 grok-main、不是 default)。
  2. 确认能看到视频模型:
bash
curl https://api.ashpetals.com/v1/models \
  -H "Authorization: Bearer ***"

data 里应有 grok-imagine-videogrok-imagine-video-1.5

路径三选一,host 都是本站:

text
POST /v1/videos
POST /v1/videos/generations
POST /xai/v1/videos/generations

3. 填参

参数必填说明
modelgrok-imagine-video / grok-imagine-video-1.5 / grok-imagine-video-1.5-preview
prompt画面描述。中英文均可,英文细节通常更稳
seconds建议字符串,如 "4"。数字会 400
duration可选数字或字符串都可以
aspect_ratio / resolution可选可透传
image不要图生视频上游拒绝(422/415),自动退款

建议先 4–8 秒试效果。grok-imagine / grok-imagine-edit 走图像接口,不是本页。

4. 提交

bash
curl https://api.ashpetals.com/v1/videos \
  -H "Authorization: Bearer ***" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "grok-imagine-video",
    "prompt": "A red paper boat on calm blue water, slow cinematic push-in, daylight",
    "seconds": "4"
  }'

记下返回的 id。上游可能只给 request_id,本站会写成 id

5. 轮询与下载

status下载
queued / pending
in_progress
completed / done是,马上拉 /content
failed否(已退款)

每 5–10 秒查一次。下载必须用任务 id,不要用 video.url 里的内部路径(会 Task not found)。

成片 URL 大约 25 分钟后 404。/content 不重复扣费。

6. 计费

预扣 = 广场 ModelPrice × 秒 × Grok-Main 分组倍率。三个视频 SKU 同价;1.5@1080p 不另加价。失败退款。

散客 Grok-Main 0.08x、现网 ModelPrice 0.25 时,大约 $0.02 / 秒(4 秒约 $0.08)。下游身份倍率不同,以广场和消费日志为准。充值仍是 1.3 元 = 1 余额。

7. 排错

现象处理
401Key / Bearer sk-
无渠道 / 403分组改成 Grok-MainGET /v1/models 核对
400 + chat不要打 /v1/chat/completions
400 invalid_jsonseconds 改成字符串
422 / 415删掉 image 字段
一直 queued等几分钟,不要重提
Task not found用提交时的 id 下载
/content 404超过约 25 分钟,需重新生成

8. Python

python
import time
import requests

BASE = "https://api.ashpetals.com"
HEAD = {"Authorization": "Bearer sk-你的APIKey", "Content-Type": "application/json"}

r = requests.post(f"{BASE}/v1/videos", headers=HEAD, json={
    "model": "grok-imagine-video",
    "prompt": "A red paper boat on calm blue water, slow cinematic push-in, daylight",
    "seconds": "4",
})
r.raise_for_status()
task_id = r.json()["id"]

while True:
    st = requests.get(f"{BASE}/v1/videos/{task_id}", headers=HEAD).json()
    status = st.get("status")
    if status in ("completed", "done"):
        break
    if status == "failed":
        raise SystemExit(st.get("error") or st)
    time.sleep(6)

mp4 = requests.get(f"{BASE}/v1/videos/{task_id}/content", headers=HEAD)
open("out.mp4", "wb").write(mp4.content)

从其它中转迁移:删掉 image / reference_images / async=true;模型名用本站列表;seconds 用字符串。

AshPetals API — 单主站 · OpenAI 兼容