跳轉到主要內容
POST
使用此路由,透過 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 編碼的圖像資料。
如需瞭解模型特定行為,請參閱 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日