创建 Grok Imagine 视频任务
curl --request POST \
--url https://xxx.wengaocloud.com/v1/grok-imagine/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-imagine-video-1.5-preview",
"prompt": "一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节",
"image_urls": [
"https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop"
]
}
'import requests
url = "https://xxx.wengaocloud.com/v1/grok-imagine/videos/generations"
payload = {
"model": "grok-imagine-video-1.5-preview",
"prompt": "一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节",
"image_urls": ["https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'grok-imagine-video-1.5-preview',
prompt: '一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节',
image_urls: [
'https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop'
]
})
};
fetch('https://xxx.wengaocloud.com/v1/grok-imagine/videos/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://xxx.wengaocloud.com/v1/grok-imagine/videos/generations"
payload := strings.NewReader("{\n \"model\": \"grok-imagine-video-1.5-preview\",\n \"prompt\": \"一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节\",\n \"image_urls\": [\n \"https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "vidtask_87485721c5b54dc9a97467f8a1812b09",
"object": "video.generation.task",
"created": 1779782400,
"model": "grok-imagine-video-1.5-preview",
"status": "queued",
"expires_at": 1779955200
}{
"error": {
"type": "invalid_request_error",
"code": "model_endpoint_mismatch",
"message": "该模型不支持当前 endpoint。"
}
}{
"error": {
"type": "invalid_request_error",
"code": "model_endpoint_mismatch",
"message": "该模型不支持当前 endpoint。"
}
}{
"error": {
"type": "invalid_request_error",
"code": "model_endpoint_mismatch",
"message": "该模型不支持当前 endpoint。"
}
}{
"error": {
"type": "invalid_request_error",
"code": "model_endpoint_mismatch",
"message": "该模型不支持当前 endpoint。"
}
}视频生成
创建 Grok Imagine 视频任务
创建 Grok Imagine 异步图生视频任务。受理后立即返回任务 ID,视频生成结果通过查询接口获取。
当前模型配置通常要求传入参考图,建议在 image_urls 中传入 1 个公网可访问的 HTTPS 图片直链。
创建 Grok Imagine 视频任务
curl --request POST \
--url https://xxx.wengaocloud.com/v1/grok-imagine/videos/generations \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '
{
"model": "grok-imagine-video-1.5-preview",
"prompt": "一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节",
"image_urls": [
"https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop"
]
}
'import requests
url = "https://xxx.wengaocloud.com/v1/grok-imagine/videos/generations"
payload = {
"model": "grok-imagine-video-1.5-preview",
"prompt": "一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节",
"image_urls": ["https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop"]
}
headers = {
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
model: 'grok-imagine-video-1.5-preview',
prompt: '一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节',
image_urls: [
'https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop'
]
})
};
fetch('https://xxx.wengaocloud.com/v1/grok-imagine/videos/generations', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://xxx.wengaocloud.com/v1/grok-imagine/videos/generations"
payload := strings.NewReader("{\n \"model\": \"grok-imagine-video-1.5-preview\",\n \"prompt\": \"一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节\",\n \"image_urls\": [\n \"https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop\"\n ]\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("Authorization", "Bearer <token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}{
"id": "vidtask_87485721c5b54dc9a97467f8a1812b09",
"object": "video.generation.task",
"created": 1779782400,
"model": "grok-imagine-video-1.5-preview",
"status": "queued",
"expires_at": 1779955200
}{
"error": {
"type": "invalid_request_error",
"code": "model_endpoint_mismatch",
"message": "该模型不支持当前 endpoint。"
}
}{
"error": {
"type": "invalid_request_error",
"code": "model_endpoint_mismatch",
"message": "该模型不支持当前 endpoint。"
}
}{
"error": {
"type": "invalid_request_error",
"code": "model_endpoint_mismatch",
"message": "该模型不支持当前 endpoint。"
}
}{
"error": {
"type": "invalid_request_error",
"code": "model_endpoint_mismatch",
"message": "该模型不支持当前 endpoint。"
}
}提交 Grok Imagine 异步图生视频任务。平台受理后立即返回任务 ID,视频生成结果通过 查询 Grok Imagine 视频任务 接口获取。
保存响应中的
任务失败、取消或超时后,平台会退款到对应 API Key 余额。
更多说明见 Grok Imagine Video 001。
该接口当前需要传入参考图。建议始终显式传入
image_urls,并优先使用 1 张公网可访问的 HTTPS 图片直链。POST /v1/grok-imagine/videos/generations
Authorization: Bearer <API_KEY>
Content-Type: application/json
请求参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
model | string | 是 | 固定使用 grok-imagine-video-1.5-preview,或使用平台返回的可用模型名称。 |
prompt | string | 是 | 视频提示词,描述主体、动作、环境、镜头、风格等。 |
image_urls | string[] | 是 | 参考图 URL 数组。建议传 1 个公网可访问的 HTTPS 图片直链;如账号开通的模型配置支持多参考图,可按实际配置传入。 |
duration | integer/string | 否 | 视频时长(秒)。建议显式传入;常见范围为 5 到 15,部分模型配置要求 6 秒起。 |
aspect_ratio | string | 否 | 画面比例,通用值为 16:9、9:16、2:3;部分模型配置还支持 3:2、1:1。未传按模型配置默认值处理。 |
resolution | string | 否 | 分辨率档位,部分模型配置支持 480p、720p;未传按模型配置默认值处理。 |
size | string | 否 | resolution 的兼容别名。若同时传入 resolution 与 size,两者应保持一致。 |
image_urls 必须是模型服务可下载的公网图片地址。不要传本地文件路径、data:image/...;base64、asset://...、需要登录或会过期的临时 URL。若图片无法下载,任务会失败并退款。示例
curl -X POST "https://{your-domain}/v1/grok-imagine/videos/generations" \
-H "Authorization: Bearer $API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-video-1.5-preview",
"prompt": "一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,雨后湿润地面反光,巨物感,帅气、震撼、写实,高细节",
"duration": 6,
"aspect_ratio": "16:9",
"image_urls": [
"https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop"
]
}'
import requests
resp = requests.post(
"https://{your-domain}/v1/grok-imagine/videos/generations",
headers={
"Authorization": f"Bearer {API_KEY}",
"Content-Type": "application/json",
},
json={
"model": "grok-imagine-video-1.5-preview",
"prompt": "一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节",
"duration": 6,
"aspect_ratio": "16:9",
"image_urls": [
"https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop"
],
},
)
print(resp.json())
const response = await fetch("https://{your-domain}/v1/grok-imagine/videos/generations", {
method: "POST",
headers: {
Authorization: `Bearer ${process.env.API_KEY}`,
"Content-Type": "application/json",
},
body: JSON.stringify({
model: "grok-imagine-video-1.5-preview",
prompt: "一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节",
duration: 6,
aspect_ratio: "16:9",
image_urls: [
"https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop",
],
}),
});
console.log(await response.json());
响应示例
{
"id": "vidtask_87485721c5b54dc9a97467f8a1812b09",
"object": "video.generation.task",
"created": 1779782400,
"model": "grok-imagine-video-1.5-preview",
"status": "queued",
"expires_at": 1779955200
}
id,然后调用查询接口轮询任务状态。
计费说明
Grok Imagine 视频使用video_second 作为公开用量单位。对于输入图 + 输出视频秒数的价格配置,控制台账单会拆分输入图费用和输出视频费用。
| 字段 | 说明 |
|---|---|
billing_unit | video_second |
requested_units | 请求的 duration 秒数 |
billable_units | 任务成功后实际结算秒数,通常等于输出视频秒数 |
billable_input_images | 存在时表示本次计费的输入图张数 |
billable_output_seconds | 存在时表示本次计费的输出视频秒数 |
input_charge_amount | 存在时表示输入图费用 |
output_charge_amount | 存在时表示输出视频费用 |
charge_amount | 存在时表示本次任务总费用 |
常见错误
| 场景 | 可能错误 | 处理方式 |
|---|---|---|
| 未传参考图或传空数组 | model requires an input image | 传入至少一个公网可访问图片 URL。 |
| 图片 URL 需要登录、过期或被防盗链 | image_download_error / HTTP 403 | 换成可匿名下载的图片直链。 |
传入 data:image/...;base64 | 模型服务返回错误或 500 | 先将图片上传到公网对象存储,再传 URL。 |
| 模型服务额度不足 | permission-denied / credits / spending limit | 联系平台处理额度。 |
| 模型未授权 | model_not_allowed / model_not_visible | 检查 API Key 可用模型和域名可见性。 |
授权
Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
请求体
application/json
平台开通的 Grok Imagine 视频模型名称。
示例:
"grok-imagine-video-1.5-preview"
视频提示词,描述主体、动作、环境、镜头、风格等。
示例:
"一只哥斯拉在深圳湾海岸线与城市天际线之间缓慢行走,低机位电影镜头,电影感,写实,高细节"
参考图 URL 数组。建议传 1 个公网可访问的 HTTPS 图片直链;如账号开通的模型配置支持多参考图,可按实际配置传入。
不支持本地文件路径、data:image/...;base64、asset://...、需要登录或会过期的临时 URL。
Minimum array length:
1示例:
[
"https://images.unsplash.com/photo-1500530855697-b586d89ba3ee?w=1280&h=720&fit=crop"
]
视频时长(秒)。建议显式传入;常见范围为 5 到 15,部分模型配置要求 6 秒起。
示例:
6
画面比例。通用值为 16:9、9:16、2:3;部分模型配置还支持 3:2、1:1。
示例:
"16:9"
分辨率档位。部分模型配置支持 480p、720p;未传按模型配置默认值处理。
示例:
"720p"
resolution 的兼容别名。若同时传入 resolution 与 size,两者应保持一致。
示例:
"720p"
⌘I
.png?fit=max&auto=format&n=v_sJS-AFS6goKAv3&q=85&s=e03202fddb83c95be2a503ab9c79163a)