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.