跳转到内容
免费注册
Grok

Grok Imagine 视频 API:文生与图生

用 BetterToken API Key 接入 Grok Imagine Video 与 Grok Imagine Video 1.5,按 Model ID 和操作选择字段、素材与生成方式。

你可以用文字生成 16:9 有声视频,也可以用一张首帧图片生成视频。grok-imagine-video-1.5 支持文生与图生,最高 1080p;grok-imagine-video 支持文生,最高 720p。

先准备 BetterToken API Key。Base URL 为 https://bettertoken.ai/v1,认证使用 Authorization: Bearer YOUR_API_KEY。原样复制 Model ID,大小写必须一致。

下方每份 request.json 都使用同一流程:先报价,再确认创建、轮询与下载。报价不启动生成;创建会提交付费任务。当前费用见模型广场。

型号与操作

下表按操作列出可选值;字段默认值、素材数量和组合限制见对应小节。素材大小按 1 MB = 1048576 字节换算。

Model ID操作时长(秒)输出档位比例音频素材角色
grok-imagine-videotext_to_video1–15,步长 1480p、720p16:9on无
grok-imagine-video-1.5image_to_video1–15,步长 1480p、720p、1080p不传onfirst_frame
grok-imagine-video-1.5text_to_video1–15,步长 1480p、720p、1080p16:9on无

两款型号的成片都带音频,音频固定为 on。图生不接受 output.aspect_ratio,成片画幅跟随首帧图片。

示例素材

图生示例使用白色桌面上的蓝色陶瓷杯。你可以保留样图试用,也可以先替换为自己有权使用且符合本页限制的公网 HTTPS 图片。样图为正方形,因此图生示例的成片也是正方形。

视频生成参考图:白色桌面上的蓝色陶瓷杯

文生视频

grok-imagine-video

你只有文字描述,并且 720p 以内的画质已经够用时,使用本操作。

把 model 设为本小节的 Model ID,把 operation 设为 text_to_video。仅使用下表列出的生成字段。

字段类型必填可选值或范围默认值
audio.modestring否onon
duration.modestring否fixedfixed
duration.secondsinteger否1–15,步长 1 秒;仅固定时长使用8
output.aspect_ratiostring否16:916:9
output.formatstring否mp4mp4
output.resolutionstring否480p、720p480p
promptstring是字符串无
watermarkboolean否falsefalse

素材要求

本操作不接收素材。

组合约束

  • 使用 duration.mode="fixed" 时必须有 duration.seconds。显式填写 fixed 时请同时填写秒数。

请求示例

将下方 JSON 保存为 request.json,然后按通用流程先报价、确认后创建。

{
"model": "grok-imagine-video",
"operation": "text_to_video",
"prompt": "A blue ceramic mug on a white table. Slowly move the camera closer in soft daylight.",
"duration": {
"mode": "fixed",
"seconds": 5
},
"output": {
"resolution": "720p",
"aspect_ratio": "16:9"
}
}

常见 422 错误

422 错误码处理方法
enum / range / step按本节字段表调整取值与步长。
unsupported_field删除本操作字段表中没有的字段。
requires按本节组合约束补齐秒数。

grok-imagine-video-1.5

你只有文字描述,并且需要 1080p 时,使用本操作。

把 model 设为本小节的 Model ID,把 operation 设为 text_to_video。仅使用下表列出的生成字段。

字段类型必填可选值或范围默认值
audio.modestring否onon
duration.modestring否fixedfixed
duration.secondsinteger否1–15,步长 1 秒;仅固定时长使用8
output.aspect_ratiostring否16:916:9
output.formatstring否mp4mp4
output.resolutionstring否480p、720p、1080p480p
promptstring是字符串无
watermarkboolean否falsefalse

素材要求

本操作不接收素材。

组合约束

  • 使用 duration.mode="fixed" 时必须有 duration.seconds。显式填写 fixed 时请同时填写秒数。

请求示例

将下方 JSON 保存为 request.json,然后按通用流程先报价、确认后创建。

{
"model": "grok-imagine-video-1.5",
"operation": "text_to_video",
"prompt": "A blue ceramic mug on a white table. Slowly move the camera closer in soft daylight.",
"duration": {
"mode": "fixed",
"seconds": 5
},
"output": {
"resolution": "1080p",
"aspect_ratio": "16:9"
}
}

常见 422 错误

422 错误码处理方法
enum / range / step按本节字段表调整取值与步长。
unsupported_field删除本操作字段表中没有的字段。
requires按本节组合约束补齐秒数。

图生视频

grok-imagine-video-1.5

你希望以一张图片确定起始画面时,使用本操作。

把 model 设为本小节的 Model ID,把 operation 设为 image_to_video。仅使用下表列出的生成字段;首帧图片放在 media 数组中。

字段类型必填可选值或范围默认值
audio.modestring否onon
duration.modestring否fixedfixed
duration.secondsinteger否1–15,步长 1 秒;仅固定时长使用8
output.formatstring否mp4mp4
output.resolutionstring否480p、720p、1080p480p
promptstring是字符串无
watermarkboolean否falsefalse

素材要求

素材角色类型与数量格式单文件限制
first_frameimage,1 个(必填)jpg、jpeg、png、webp大小不超过 20 MB;宽 1–16384 px;高 1–16384 px

组合约束

  • 使用 duration.mode="fixed" 时必须有 duration.seconds。显式填写 fixed 时请同时填写秒数。
  • 必须提供 1 张 first_frame。不要传 output.aspect_ratio,成片画幅跟随首帧图片。

图生除按视频时长计费外,还按首帧图片计费。创建前请核对报价中的金额。

请求示例

将下方 JSON 保存为 request.json,然后按通用流程先报价、确认后创建。

{
"model": "grok-imagine-video-1.5",
"operation": "image_to_video",
"prompt": "Slowly move the camera closer to the blue ceramic mug. Preserve its shape and the white table.",
"duration": {
"mode": "fixed",
"seconds": 5
},
"output": {
"resolution": "720p"
},
"media": [
{
"id": "first",
"type": "image",
"role": "first_frame",
"source": "https://docs.bettertoken.ai/images/nano-banana-guide/sample-07.png"
}
]
}

常见 422 错误

422 错误码处理方法
enum / range / step按本节字段表调整取值与步长。
unsupported_field删除本操作字段表中没有的字段,例如 output.aspect_ratio。
requires按本节组合约束补齐秒数或首帧图片。
count / media_role按本节素材表只传 1 张 first_frame。
video_input_unsupported检查公网 HTTPS 地址、Content-Type 与文件格式,再重新报价。

官方资料

调用 BetterToken 时,使用本页字段与实时模型目录中的对应操作。