Grok
使用 Grok 生成图像
使用 Grok Imagine Image 2.0 生成图像,包括质量、宽高比、分辨率、图像数量和响应格式控制。
POST
/
v1
/
images
/
generations
curl https://api.cometapi.com/v1/images/generations \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-binary '{
"model": "grok-imagine-image-2.0",
"prompt": "A glass observatory above a quiet alpine lake at sunrise",
"aspect_ratio": "16:9",
"resolution": "1k",
"quality": "low",
"response_format": "url"
}'{
"data": [
{
"url": "https://cdn.example.com/generated-image.jpg",
"mime_type": "image/jpeg"
}
]
}使用此路由通过 Grok 图像模型根据文本创建图像。请求正文使用
application/json。
model prompt 为必填项。
选择模型
从 模型页面中选择一个 Grok 图像模型 ID。API 示例使用grok-imagine-image-2.0。
quality 仅适用于 grok-imagine-image-2.0,并接受 low 或 medium。当应用程序依赖特定质量级别时,请显式设置它。对于 Image 2.0,省略 resolution 时,CometAPI 会使用 1k。
配置输出
- 使用
aspect_ratio选择输出形状,或使用auto让模型选择形状。 - 使用
resolution请求1k或2k输出。 - 使用
n请求 1 到 10 张图像。默认值为1。 - 使用
response_format返回临时 URL 或 Base64 编码的图像数据。
请求完成后请及时下载 URL 结果。生成的图像 URL 是临时的。当应用程序需要在 API 响应中获取图像字节时,请使用
b64_json。请求体
application/json
The Grok image model ID. See the Models page for available model IDs.
可用选项:
grok-imagine-image, grok-imagine-image-quality, grok-imagine-image-2.0 示例:
"grok-imagine-image-2.0"
最后修改于 2026年8月21日
⌘I
curl https://api.cometapi.com/v1/images/generations \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-binary '{
"model": "grok-imagine-image-2.0",
"prompt": "A glass observatory above a quiet alpine lake at sunrise",
"aspect_ratio": "16:9",
"resolution": "1k",
"quality": "low",
"response_format": "url"
}'{
"data": [
{
"url": "https://cdn.example.com/generated-image.jpg",
"mime_type": "image/jpeg"
}
]
}