Grok
使用 Grok 生成圖像
使用 Grok Imagine Image 2.0 生成圖像,包括 quality、aspect ratio、resolution、image-count 與 response-format 控制項。
POST
/
v1
/
images
/
generations
curl https://api.cometapi.com/v1/images/generations \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-binary '{
"model": "grok-imagine-image-2.0",
"prompt": "A glass observatory above a quiet alpine lake at sunrise",
"aspect_ratio": "16:9",
"resolution": "1k",
"quality": "low",
"response_format": "url"
}'{
"data": [
{
"url": "https://cdn.example.com/generated-image.jpg",
"mime_type": "image/jpeg"
}
]
}使用此路由,透過 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 編碼的圖像資料。
請在請求完成後立即下載 URL 結果。生成的圖像 URL 為暫時性。當您的應用程式需要 API 回應中的圖像位元組時,請使用
b64_json。主體
application/json
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"
最後修改於 2026年8月21日
⌘I
curl https://api.cometapi.com/v1/images/generations \
-H "Authorization: Bearer $COMETAPI_KEY" \
-H "Content-Type: application/json" \
--data-binary '{
"model": "grok-imagine-image-2.0",
"prompt": "A glass observatory above a quiet alpine lake at sunrise",
"aspect_ratio": "16:9",
"resolution": "1k",
"quality": "low",
"response_format": "url"
}'{
"data": [
{
"url": "https://cdn.example.com/generated-image.jpg",
"mime_type": "image/jpeg"
}
]
}