Skip to main content
POST
使用此路由通过 Grok 图像模型根据文本创建图像。请求正文使用 application/json。 该请求支持 modelpromptnaspect_ratioresolutionresponse_format

选择模型

模型页面中选择一个 Grok 图像模型 ID。API 示例使用 grok-imagine-image-quality

配置输出

  • 使用 aspect_ratio 选择输出形状,或使用 auto 让模型选择形状。
  • 使用 resolution 请求 1k2k 输出。
  • 使用 n 最多请求 10 张图像。
  • 使用 response_format 返回临时 URL 或 Base64 编码的图像数据。
有关提供商参数的详细信息,请参阅 xAI 图像生成指南.
请求完成后下载 URL 结果。生成的图像 URL 可能会过期。

授权

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

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>

The requested output resolution.

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

"1k"

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
必填

Usage details for the request.