Skip to content

Grok Imagine 图生视频 ​

本页由 ModelFold 文档站根据上游官方 OpenAPI 文档同步生成。接口路径、参数、示例与官方保持一致;品牌与 API 域名已替换为 ModelFold。

接口 ​

POST /jobs/createTask

完整 URL: https://ai.modelfold.online/v1/jobs/createTask

鉴权:所有请求都需要 Authorization: Bearer <API_KEY> 请求头。

输出为 MP4 视频,带与画面同步生成的音轨(prompt 中的台词会被念出)。音频无法关闭。

查询任务状态 ​

提交任务后,使用统一的查询端点检查进度并获取结果:

TIP

对于生产环境,我们建议使用 callBackUrl 参数接收自动通知,而不是轮询状态端点。

相关资源 ​

请求参数 ​

请求体 (application/json) ​

参数类型必填说明
modelstring是用于生成的模型名称。必填字段。
- 此端点必须使用 grok-imagine/image-to-video 默认值:"grok-imagine/image-to-video"。 可选值:grok-imagine/image-to-video。 示例:grok-imagine/image-to-video。
callBackUrlstring否接收视频生成任务完成更新的 URL。可选但建议在生产环境中使用。
- 当视频生成完成时,系统将向此 URL POST 任务状态和结果
- 回调包含生成的视频 URL 和任务信息
- 您的回调端点应接受包含视频结果的 JSON 负载的 POST 请求
- 或者,使用获取任务详情端点轮询任务状态 示例:https://your-domain.com/api/callback。
inputobject是视频生成任务的输入参数
  input.image_urlsarray&lt;string&gt;否提供一个外部图像 URL 作为视频生成的参考。支持最多7个图像,不要与 task_id 同时使用。在提示词中引用已上传图片时,请输入 @image(n),并在其后加一个空格(例如:@image1 海边日落)。
- 支持 JPEG、PNG、WEBP 格式
- 每张图像最大文件大小:10MB
- 使用外部图像时 Spicy 模式不可用
- 数组最多包含七个 URL
- resolution为1080p时只支持一张。
  input.task_idstring否之前生成的 Grok 图像的任务 ID。与 index 配合使用选择特定图像,不要与 image_urls 同时使用。
- 使用 grok-imagine/text-to-image 生成的任务 ID
- 支持所有模式,包括 Spicy
- 最大长度:100 字符 示例:task_grok_12345678。
  input.indexinteger否使用 task_id 时,指定使用第几张图(从 0 开始)。grok-imagine/text-to-image 每个任务返回 2 张,所以取值为 0 或 1,默认 0。
- 如果提供了 image_urls 则忽略此参数 默认值:0。 示例:0。
  input.promptstring否描述期望视频运动的文本提示。可选字段。
- 应该对期望的视觉运动详细具体
- 描述运动、动作序列、摄影工作和时间安排
- 包含主体、环境和运动动态的细节
- 最大长度:5000 字符
- 支持英文提示 示例:POV hand comes into frame handing the girl a cup of take away coffee, the girl steps out of the screen looking tired, then takes it and she says happily: "thanks! Back to work" she exits the frame and walks right to a different part of the office.。
  input.modestring否指定影响运动风格和强度的生成模式。注意:外部图像输入不支持 Spicy 模式。
- fun: 更有创意和趣味的解读
- normal: 平衡方法,具有良好的运动质量
- spicy: 更有活力和强烈的运动效果(外部图像不可用)
默认值:normal 默认值:"normal"。 可选值:fun / normal / spicy。 示例:normal。
  input.durationnumber否生成的视频时长(秒)(6-30)。(最小值:6,最大值:30,步长:1)
  input.resolutionstring否生成视频的分辨率。 默认值:"480p"。 可选值:480p / 720p / 1080p。 示例:480p。
  input.aspect_ratiostring否图像比例选择,仅适用于多图生成模式,单图模式下视频宽高参考图片宽高。 默认值:"16:9"。 可选值:2:3 / 3:2 / 1:1 / 16:9 / 9:16。 示例:16:9。
  input.nsfw_checkerboolean否默认 false。为 false 时不额外进行内容过滤,结果由模型直接返回。

请求示例 ​

bash
curl -X POST "https://ai.modelfold.online/v1/jobs/createTask" \
  -H "Authorization: Bearer $MODELFOLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "grok-imagine/image-to-video",
  "callBackUrl": "https://your-domain.com/api/callback",
  "input": {
    "image_urls": [
      "https://file.aiquickdraw.com/custom-page/akr/section-images/1762247692373tw5di116.png"
    ],
    "prompt": "POV hand comes into frame handing the girl a cup of take away coffee, the girl steps out of the screen looking tired, then takes it and she says happily: \"thanks! Back to work\" she exits the frame and walks right to a different part of the office.",
    "mode": "normal",
    "duration": "6",
    "resolution": "480p",
    "aspect_ratio": "16:9"
  }
}'
json
{
  "model": "grok-imagine/image-to-video",
  "callBackUrl": "https://your-domain.com/api/callback",
  "input": {
    "image_urls": [
      "https://file.aiquickdraw.com/custom-page/akr/section-images/1762247692373tw5di116.png"
    ],
    "prompt": "POV hand comes into frame handing the girl a cup of take away coffee, the girl steps out of the screen looking tired, then takes it and she says happily: \"thanks! Back to work\" she exits the frame and walks right to a different part of the office.",
    "mode": "normal",
    "duration": "6",
    "resolution": "480p",
    "aspect_ratio": "16:9"
  }
}

响应 ​

200 — 请求成功 ​

参数类型必填说明
codeinteger是请求状态码。请求失败时 HTTP 状态仍为 200,请始终以本字段判断:200 表示成功,其他值均表示失败,原因见 msg。常见值:401 API key 无效或缺失;402 积分不足;429 超出频率限制;422 或 500 请求未能处理(请先查看 msg、检查参数,再决定是否重试)。 可选值:200 / 401 / 402 / 404 / 422 / 429 / 433 / 455 / 500 / 501 / 505。 示例:200。
msgstring是响应消息,失败时的错误描述
dataobject是—
  data.taskIdstring是可以使用任务 ID 与“获取任务详细信息”端点一起查询任务状态。
json
{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "281e5b0*********************f39b9"
  }
}

回调 ​

videoTaskCompleted ​

回调地址:{request.body#/callBackUrl}(即请求体里的 callBackUrl)。

当 grok-imagine/image-to-video 任务成功或失败时,系统会发送此回调。

回调体参数

参数类型必填说明
codeinteger是统一回调状态码:成功为 200,失败为 501。 可选值:200 / 501。 示例:200。
msgstring是统一回调消息。 可选值:Playground task completed successfully. / Playground task failed.。 示例:Playground task completed successfully.。
dataobject是—
  data.taskIdstring是任务唯一标识符。
  data.modelstring是任务使用的模型。 可选值:grok-imagine/image-to-video。 示例:grok-imagine/image-to-video。
  data.statestring是任务最终状态。 可选值:success / fail。 示例:success。
  data.paramstring是包含已提交任务参数的 JSON 字符串。
  data.resultJsonstring否任务成功时,包含 resultUrls、firstFrameUrl、lastFrameUrl 或 resultObject 的 JSON 字符串;任务。仅在 state 为 success 时出现。
  data.failCodestring否失败码,数字字符串,如 "400"、"500"。仅在 state 为 fail 时出现。
  data.failMsgstring否失败原因,仅在 state 为 fail 时出现。
  data.costTimeinteger否处理耗时(秒),成功和失败回调都会返回。
  data.completeTimeinteger否任务完成时间戳。
  data.createTimeinteger否任务创建时间戳。
  data.updateTimeinteger否完成时间请以 completeTime 为准;updateTime 可能与 createTime 相同。
  data.creditsConsumednumber否本任务消耗的积分;失败任务为 0。

任务成功完成

json
{
  "code": 200,
  "msg": "Playground task completed successfully.",
  "data": {
    "taskId": "task_example_video_webhook_001",
    "model": "grok-imagine/image-to-video",
    "state": "success",
    "param": "{\"input\":\"{\\\"task_id\\\":\\\"task_grok_12345678\\\",\\\"image_urls\\\":[\\\"https://example.com/input-image.jpg\\\"],\\\"prompt\\\":\\\"POV hand comes into frame handing the girl a cup of take away coffee, the girl steps out of the screen looking tired,...\\\",\\\"mode\\\":\\\"normal\\\",\\\"duration\\\":\\\"6\\\",\\\"resolution\\\":\\\"480p\\\",\\\"aspect_ratio\\\":\\\"16:9\\\"}\",\"callBackUrl\":\"https://example.com/callback\",\"model\":\"grok-imagine/image-to-video\"}",
    "resultJson": "{\"resultUrls\":[\"https://example.com/generated-video.mp4\"]}",
    "costTime": 12,
    "completeTime": 1234567890,
    "createTime": 1234560000,
    "updateTime": 1234567890,
    "creditsConsumed": 1.23
  }
}

任务失败

json
{
  "code": 501,
  "msg": "Playground task failed.",
  "data": {
    "taskId": "task_example_video_webhook_001",
    "model": "grok-imagine/image-to-video",
    "state": "fail",
    "param": "{\"input\":\"{\\\"task_id\\\":\\\"task_grok_12345678\\\",\\\"image_urls\\\":[\\\"https://example.com/input-image.jpg\\\"],\\\"prompt\\\":\\\"POV hand comes into frame handing the girl a cup of take away coffee, the girl steps out of the screen looking tired,...\\\",\\\"mode\\\":\\\"normal\\\",\\\"duration\\\":\\\"6\\\",\\\"resolution\\\":\\\"480p\\\",\\\"aspect_ratio\\\":\\\"16:9\\\"}\",\"callBackUrl\":\"https://example.com/callback\",\"model\":\"grok-imagine/image-to-video\"}",
    "failCode": "400",
    "failMsg": "<error detail>",
    "costTime": 12,
    "creditsConsumed": 0
  }
}

ModelFold — 一个 API,接入所有主流 AI 模型。