Image / Grok-imagine

Grok Imagine 2.0 Image Generation

Overview

Grok Imagine 2.0 Image Generationendpoint, create endpoint+ extra_body.operation fieldlocalized example text4 Method (method):

MethodoperationDescription
Text-to-Imagetext-to-imageImage
Image-to-Imageimage-edit1~5 images Reference image+ Prompt/ repainting
imagesegment-mapimage, return image+ localized example text+ localized example text
localized example textsegment-editfirst 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

ParameterTypeRequiredDescription
operationstringYesMethod:text-to-image / image-edit / segment-map / segment-edit
source_task_idstringConditionfirst tasktaskId; segment-edit Required, segment-map andimage localized example text
mask_indexsint[]No, onlysegment-edit Optional.localized example text= segment-map returnindex + 1 (see belowDescription)

MethodParameter① Text-to-Image text-to-image

ParameterRequiredDescription
promptYesimagePrompt
sizeNoAspect 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

ParameterRequiredDescription
promptYesreference images to
imageYesReference image URL list, 1~5 images (exceeds 5 images first 5 images )
sizeNoAspect 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.:ParameterRequiredDescription
promptYesRequirements, can ("segment")
extra_body.source_task_idlocalized example textfirst tasktaskId (as first Success Grok Imagine 2.0 task)
imagelocalized example textsingle 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.index 0; willindex localized example textsegment-edit when+1 (Method④).

④ localized example textsegment-edit

firstsegment-map task,.

ParameterRequiredDescription
promptYeslocalized example text
extra_body.source_task_idYesfirstsegment-map tasklocalized example texttaskId
extra_body.mask_indexsNo; If omitteddefault
(Important):mask_indexs localized example text= segment-map returngrokOutput.segments[].index 1.
segment-map localized example textindex localized example text0,mask_indexs localized example text1 localized example text.
:segment-map inindex=0,mask_indexs localized example text[1]; localized example textindex=2 localized 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

ParameterTypeDescription
codeintStatus Code, 0 indicates success
msgstringMessage
data.taskIdstringTask ID, used to query task status
data.statusstringTask Status, fixed to processing
data.createdAtstringCreated 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

ParameterTypeRequiredDescription
taskIdstringYesTask ID

Response Parameters

ParameterTypeDescription
codeintStatus Code, 0 indicates success
msgstringMessage
data.taskIdstringTask ID
data.statusstringTask Status:processing / success / failed
data.resultstring[]image URL list (Successreturned when applicable;segment-map return image URL list)
data.grokOutputobjectonly segment-map Successreturned when applicable, see below grokOutput Description
data.errorCodestringError Codes (Failurereturned when applicable)
data.errorMsgstringError Message (Failurereturned when applicable)
data.progressint, 0-100
data.pointConsumestring(decimal characters)
data.taskNicknamestringTask label (create when return )
data.createdAtstringCreated Time (characters)
data.updatedAtstringUpdated Time (characters)
grokOutput field (only segment-map Successreturned when applicable)
ParameterTypeDescription
grokOutput.segmentsobject[]list
grokOutput.segments[].maskUrlstringimage URL
grokOutput.segments[].namestringlocalized example text
grokOutput.segments[].indexint,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-edit localized example textmask_indexs localized 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
Updated 2026-09-02