Skip to main content
POST
使用此路由通过 Grok 图像模型根据文本创建图像。请求正文使用 application/jsonmodel prompt 为必填项。

选择模型

模型页面中选择一个 Grok 图像模型 ID。API 示例使用 grok-imagine-image-2.0 quality 仅适用于 grok-imagine-image-2.0,并接受 lowmedium。当应用程序依赖特定质量级别时,请显式设置它。对于 Image 2.0,省略 resolution 时,CometAPI 会使用 1k

配置输出

  • 使用 aspect_ratio 选择输出形状,或使用 auto 让模型选择形状。
  • 使用 resolution 请求 1k2k 输出。
  • 使用 n 请求 1 到 10 张图像。默认值为 1
  • 使用 response_format 返回临时 URL 或 Base64 编码的图像数据。
有关特定模型的行为,请参阅 xAI 图像生成指南.
请求完成后请及时下载 URL 结果。生成的图像 URL 是临时的。当应用程序需要在 API 响应中获取图像字节时,请使用 b64_json

授权

Authorization
string
header
必填

Use your CometAPI API key as the bearer value.

请求体

application/json
model
enum<string>
必填

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"

prompt
string
必填

A text description of the image to generate.

Minimum string length: 1
示例:

"A glass observatory above a quiet alpine lake at sunrise"

n
integer
默认值:1

The number of images to generate. Use an integer from 1 through 10.

必填范围: 1 <= x <= 10
aspect_ratio
enum<string>

The 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"

resolution
enum<string>
默认值:1k

The requested output resolution. Image 2.0 uses 1k when this field is omitted.

可用选项:
1k,
2k
示例:

"1k"

quality
enum<string>

Image quality for grok-imagine-image-2.0. This field is not available for the older Grok image model IDs.

可用选项:
low,
medium
示例:

"low"

response_format
enum<string>
默认值:url

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

响应

200 - application/json

The generated image results.

data
object[]
必填

The generated images.

Minimum array length: 1
usage
object

Additional usage metadata returned for the request. Its contents can vary by model.

最后修改于 2026年8月21日