使用 Grok 生成图像
使用 Grok Imagine Image 2.0 生成图像,包括质量、宽高比、分辨率、图像数量和响应格式控制。
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 编码的图像数据。
b64_json。授权
Use your CometAPI API key as the bearer value.
请求体
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"
A text description of the image to generate.
1"A glass observatory above a quiet alpine lake at sunrise"
The number of images to generate. Use an integer from 1 through 10.
1 <= x <= 10The output shape. Use auto to let the model select the aspect ratio.
1:1, 3:4, 4:3, 9:16, 16:9, 2:3, 3:2, 9:19.5, 19.5:9, 9:20, 20:9, 1:2, 2:1, auto "16:9"
The requested output resolution. Image 2.0 uses 1k when this field is omitted.
1k, 2k "1k"
Image quality for grok-imagine-image-2.0. This field is not available for the older Grok image model IDs.
low, medium "low"
The image representation in each response item. Use url for a temporary download URL or b64_json for Base64-encoded image bytes.
url, b64_json