Image Generation
Grok Image async image generation endpoint
The Grok Image image generation endpoint. Submits a generation task from a prompt. The interface is async: on success it returns an image.task object; poll the Query Result endpoint with the returned task ID until status becomes completed to fetch the final image.
Billing model
This endpoint is billed under the model specified by the model field (grok-imagine-1.0 / grok-imagine-2.0 / grok-imagine-image / grok-imagine-image-quality / grok-imagine-image-2.0), and the fee is deducted from your account balance.
Async flow
POST /v1/images/async/generationssubmits the task and returnstask_id(prefixed withtask_) andstatus=queued/in_progress;- Poll
GET /v1/images/async/generations/{task_id}with thattask_id; - When
status=completed, thedataarray contains the final image URL (urlfield); whenfailed,errorexplains why.
Images are kept for about 2 hours
The returned image URL is temporary (metadata.assetsExpireAt holds the expiry time in Unix seconds); images are kept for about 2 hours and then deleted automatically. Download them before they expire if you need long-term storage.
Authorization
BearerAuth
使用 Bearer Token 认证。
格式: Authorization: Bearer sk-xxxxxx
令牌需开通对应模型的调用权限。
In: header
Request Body
application/json
模型名称,可选:grok-imagine-1.0、grok-imagine-2.0、grok-imagine-image、grok-imagine-image-quality、grok-imagine-image-2.0
提示词,描述希望生成的图片内容
生成数量(1-4),默认 1
1 <= value <= 4输出比例。可传 OpenAI 风格尺寸(如 1024x1024、1536x1024、1024x1536),网关会映射为最接近的宽高比;也可直接传宽高比(如 1:1、16:9、9:16、3:2、2:3)。grok-imagine-1.0 / grok-imagine-2.0 仅支持基础比例,Grok Image 系列支持更多比例(含 auto)。不传默认 1:1
画质:low / medium。仅 grok-imagine-image-2.0 支持;其余模型忽略该字段
"low" | "medium"Response Body
application/json
application/json
application/json
curl -X POST "https://www.omwai.xyz/v1/images/async/generations" \ -H "Content-Type: application/json" \ -d '{ "model": "grok-imagine-2.0", "prompt": "a cute cat, cyberpunk style, neon background", "size": "1024x1024", "n": 1 }'{
"id": "task_01J8ABCDEFGHIJKLMNOPQRST",
"task_id": "task_01J8ABCDEFGHIJKLMNOPQRST",
"object": "image.task",
"model": "grok-imagine-2.0",
"status": "queued",
"progress": "20%",
"created_at": 1788256630,
"completed_at": 1788256720
}{
"code": "invalid_request",
"message": "string"
}{
"code": "string",
"message": "string"
}Note
A successful submission (HTTP 200) only means the task was accepted, not that the image is ready. Always poll the query endpoint until status=completed.
How is this guide?
Last updated on