Overview
Grok Imagine 2.0 Image Generationendpoint, create endpoint+ extra_body.operation fieldlocalized example text4 Method (method):
| Method | operation | Description |
|---|---|---|
| Text-to-Image | text-to-image | Image |
| Image-to-Image | image-edit | 1~5 images Reference image+ Prompt/ repainting |
| image | segment-map | image, return image+ localized example text+ localized example text |
| localized example text | segment-edit | first task, |
with Method astask:create endpoint returntaskId, query endpointPolling.
Base URL: https://mm-internal-cn.leonecloud.com
Authentication
All endpoints require a token in the request header for authentication:
Authorization: Bearer {YOUR_AUTH_TOKEN}Quick Start
cURL Example
Create Task (Text-to-Image)
curl -X POST "https://mm-internal-cn.leonecloud.com/v1/images/generations" \
-H "Authorization: Bearer your_auth_token_here" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-2-0",
"prompt": "A beautiful sunset over the ocean, oil painting style",
"size": "16:9",
"extra_body": { "operation": "text-to-image" }
}'Create Task (Image-to-Image, Reference image)
curl -X POST "https://mm-internal-cn.leonecloud.com/v1/images/generations" \
-H "Authorization: Bearer your_auth_token_here" \
-H "Content-Type: application/json" \
-d '{
"model": "grok-imagine-2-0",
"prompt": "Transform the image into watercolor style",
"image": ["https://example.com/reference.jpg"],
"size": "auto",
"extra_body": { "operation": "image-edit" }
}'Query Task Status
curl -X GET "https://mm-internal-cn.leonecloud.com/v1/images/generations/task_abc123" \
-H "Authorization: Bearer your_auth_token_here"Endpoints
1. create Grok Imagine 2.0 task
POST /v1/images/generations
Create a Grok Imagine 2.0 Image Generationtask.localized example textextra_body.operation Method.
Content-Type: application/json
Request Parameters| Parameter | Type | Required | Description |
|-----|------|-----|------|
| model | string | Yes | localized example textgrok-imagine-2-0 |
| prompt | string | Yes | Prompt.with MethodRequired (segment-map use, )|
| extra_body | object | Yes | MethodParameter, see belowextra_body fieldDescription |
| size | string | No | Aspect ratio, only text-to-image / image-edit localized example text|
| image | string[] | Condition | Reference image URL list.image-edit Required (1~5 images );segment-map can use single image as ( andsource_task_id )|
| callback_url | string | No | Callback notification URL after the task is complete |
| task_nickname | string | No | Task label, query / when|
extra_body field
| Parameter | Type | Required | Description |
|---|---|---|---|
| operation | string | Yes | Method:text-to-image / image-edit / segment-map / segment-edit |
| source_task_id | string | Condition | first tasktaskId; segment-edit Required, segment-map andimage localized example text |
| mask_indexs | int[] | No | , onlysegment-edit Optional.localized example text= segment-map returnindex + 1 (see belowDescription) |
MethodParameter① Text-to-Image text-to-image
| Parameter | Required | Description |
|---|---|---|
| prompt | Yes | imagePrompt |
| size | No | Aspect ratio, default 1:1, Optional 1:1 / 2:3 / 3:2 / 16:9 / 9:16 |
{
"model": "grok-imagine-2-0",
"prompt": "A futuristic city at night, neon lights, cyberpunk",
"size": "16:9",
"extra_body": { "operation": "text-to-image" }
}② Image-to-Image image-edit
| Parameter | Required | Description |
|---|---|---|
| prompt | Yes | reference images to |
| image | Yes | Reference image URL list, 1~5 images (exceeds 5 images first 5 images ) |
| size | No | Aspect ratio, Values, supportedauto (Reference image) |
{
"model": "grok-imagine-2-0",
"prompt": "Transform this image into watercolor style",
"image": [
"https://example.com/ref1.jpg",
"https://example.com/ref2.jpg"
],
"size": "auto",
"extra_body": { "operation": "image-edit" }
}③ imagesegment-map
images image, return image+ localized example text+ (index), localized example textsegment-edit localized example text.: | Parameter | Required | Description |
|---|---|---|---|
| prompt | Yes | Requirements, can ("segment") | |
| extra_body.source_task_id | localized example text | first tasktaskId (as first Success Grok Imagine 2.0 task) | |
| image | localized example text | single imageimage URL as ( number images ).andsource_task_id provide |
first task as:```json
{
"model": "grok-imagine-2-0",
"prompt": "segment",
"extra_body": {
"operation": "segment-map",
"source_task_id": "task_20260810103000_abc12345"
}
}
Reference image as:```json
{
"model": "grok-imagine-2-0",
"prompt": "segment",
"image": ["https://example.com/photo.jpg"],
"extra_body": { "operation": "segment-map" }
}Description:MethodSuccess after,result[](image URL list), ingrokOutput.segments[]in returnmaskUrl/name/index.index0; willindexlocalized example textsegment-editwhen+1 (Method④).
④ localized example textsegment-edit
firstsegment-map task,.
| Parameter | Required | Description |
|---|---|---|
| prompt | Yes | localized example text |
| extra_body.source_task_id | Yes | firstsegment-map tasklocalized example texttaskId |
| extra_body.mask_indexs | No | ; If omitteddefault |
(Important):mask_indexslocalized example text=segment-mapreturngrokOutput.segments[].index1.segment-maplocalized example textindexlocalized example text0,mask_indexslocalized example text1 localized example text.
:segment-mapinindex=0,mask_indexslocalized example text[1]; localized example textindex=2localized example text[3].
{
"model": "grok-imagine-2-0",
"prompt": "Change the sky to a starry night",
"extra_body": {
"operation": "segment-edit",
"source_task_id": "task_20260810103000_abc12345",
"mask_indexs": [1, 3]
}
}Response Parameters
| Parameter | Type | Description |
|---|---|---|
| code | int | Status Code, 0 indicates success |
| msg | string | Message |
| data.taskId | string | Task ID, used to query task status |
| data.status | string | Task Status, fixed to processing |
| data.createdAt | string | Created Time |
Response Example
Success
{
"code": 0,
"msg": "success",
"data": {
"taskId": "task_20260810103000_abc12345",
"status": "processing",
"createdAt": "2026-08-10 10:30:00"
}
}2. Query Task Status
GET /v1/images/generations/{taskId}
query task execute Status.
Path Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
| taskId | string | Yes | Task ID |
Response Parameters
| Parameter | Type | Description |
|---|---|---|
| code | int | Status Code, 0 indicates success |
| msg | string | Message |
| data.taskId | string | Task ID |
| data.status | string | Task Status:processing / success / failed |
| data.result | string[] | image URL list (Successreturned when applicable;segment-map return image URL list) |
| data.grokOutput | object | only segment-map Successreturned when applicable, see below grokOutput Description |
| data.errorCode | string | Error Codes (Failurereturned when applicable) |
| data.errorMsg | string | Error Message (Failurereturned when applicable) |
| data.progress | int | , 0-100 |
| data.pointConsume | string | (decimal characters) |
| data.taskNickname | string | Task label (create when return ) |
| data.createdAt | string | Created Time (characters) |
| data.updatedAt | string | Updated Time (characters) |
grokOutput field (only segment-map Successreturned when applicable)
| Parameter | Type | Description |
|---|---|---|
| grokOutput.segments | object[] | list |
| grokOutput.segments[].maskUrl | string | image URL |
| grokOutput.segments[].name | string | localized example text |
| grokOutput.segments[].index | int | ,0; localized example textsegment-edit when+1 |
Response Example
Success
{
"code": 0,
"msg": "success",
"data": {
"taskId": "task_20260810103000_abc12345",
"status": "success",
"result": [
"https://fc-gw-sh.oss-accelerate.aliyuncs.com/images/2026/08/10/output_001.png"
],
"createdAt": "2026-08-10 10:30:00",
"updatedAt": "2026-08-10 10:31:30"
}
}Success (segment-map, data)
{
"code": 0,
"msg": "success",
"data": {
"taskId": "task_20260810103000_abc12345",
"status": "success",
"result": [
"https://fc-gw-sh.oss-accelerate.aliyuncs.com/images/2026/08/10/mask_000.png",
"https://fc-gw-sh.oss-accelerate.aliyuncs.com/images/2026/08/10/mask_001.png"
],
"grokOutput": {
"segments": [
{ "maskUrl": "https://fc-gw-sh.oss-accelerate.aliyuncs.com/images/2026/08/10/mask_000.png", "name": "sky", "index": 0 },
{ "maskUrl": "https://fc-gw-sh.oss-accelerate.aliyuncs.com/images/2026/08/10/mask_001.png", "name": "person", "index": 1 }
]
},
"createdAt": "2026-08-10 10:30:00",
"updatedAt": "2026-08-10 10:31:30"
}
}inindex=0(sky)when,segment-editlocalized example textmask_indexslocalized example text[1].
{
"code": 0,
"msg": "success",
"data": {
"taskId": "task_20260810103000_abc12345",
"status": "failed",
"errorMsg": "Failure:",
"createdAt": "2026-08-10 10:30:00",
"updatedAt": "2026-08-10 10:30:45"
}
}Callback Notification
task complete (Success or Failure) when, if Create Task when providecallback_url, was provided when creating the task, the system sends a POST request to that URL.
Headers
Content-Type: application/json
X-Funcloud-Event: task.completed
X-Funcloud-Signature: {localized example text}Body (taskindata fieldin, and「Query Task Status」endpointlocalized example textdata ):```json
{
"event": "task.completed",
"timestamp": "2026-08-10T10:31:30+08:00",
"signature": "a1b2c3d4e5f6...",
"data": {
"taskId": "task_20260810103000_abc12345",
"status": "success",
"result": ["https://fc-gw-sh.oss-accelerate.aliyuncs.com/images/output_001.png"],
"createdAt": "2026-08-10 10:30:00",
"updatedAt": "2026-08-10 10:31:30"
}
}
---
## Error Codes
| code | Description |
|------|------|
| 0 | Success |
| 10002 | Parametermissing or malformed |
| 10005 | API Key invalid or missing |
| 30003 | Task not found, taskId|
| 90003 | Internal server error |
---
## Best Practices
### Method-→ `text-to-image`
- with Reference image repainting /→ `image-edit`
- images image→ localized example text`segment-map` localized example text`grokOutput.segments` (localized example text`index`), localized example text`segment-edit` localized example text`mask_indexs` (= localized example text`index + 1`)localized example text### Polling Strategy
- First 30 seconds:query every 3 seconds
- 30 seconds ~ 2 minutes:query every 5 seconds
- After 2 minutes:query every 10 seconds
### Processing Time Reference
- Text-to-Image / Image-to-Image:Usually 10 ~ 60 seconds
- image /:Usually 10~ 60 seconds
### Prompt recommended
- use,, can ( oil painting, watercolor, digital art etc. )
- Image-to-Image andwhen, prompt
- supported, Usually