Image / Grok-imagine

Grok Imagine Image / Video Generation

Overview

Grok Imagine Image / Video Generationendpoint, supported Text-to-Image, Image-to-Image, Text-to-Video, Image-to-Video four modes.

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 Grok task (Text-to-Image)

curl -X POST "https://mm-internal-cn.leonecloud.com/api/v2/open/aigc/grok" \
 -H "Authorization: Bearer your_auth_token_here" \
 -H "Content-Type: application/json" \
 -d '{
 "prompt": "A beautiful sunset over the ocean, oil painting style",
 "aspectRatio": "16:9",
 "enablePro": true
 }'

create Grok task (Image-to-Image)

curl -X POST "https://mm-internal-cn.leonecloud.com/api/v2/open/aigc/grok" \
 -H "Authorization: Bearer your_auth_token_here" \
 -H "Content-Type: application/json" \
 -d '{
 "prompt": "Transform the image into watercolor style",
 "genType": "i2i",
 "imageUrls": ["https://example.com/reference.jpg"]
 }'

create Grok task (Text-to-Video)

curl -X POST "https://mm-internal-cn.leonecloud.com/api/v2/open/aigc/grok" \
 -H "Authorization: Bearer your_auth_token_here" \
 -H "Content-Type: application/json" \
 -d '{
 "prompt": "A couple dancing in a bed",
 "genType": "t2v",
 "mode": "normal",
 "duration": 6,
 "resolution": "480p"
 }'

create Grok task (Image-to-Video)

curl -X POST "https://mm-internal-cn.leonecloud.com/api/v2/open/aigc/grok" \
 -H "Authorization: Bearer your_auth_token_here" \
 -H "Content-Type: application/json" \
 -d '{
 "prompt": "Make the person in the image dance",
 "genType": "i2v",
 "imageUrls": ["https://example.com/reference.jpg"],
 "mode": "fun",
 "duration": 6
 }'

Query Task Status

curl -X GET "https://mm-internal-cn.leonecloud.com/api/v2/open/aigc/task_abc123" \
 -H "Authorization: Bearer your_auth_token_here"

Query Account Balance

curl -X GET "https://mm-internal-cn.leonecloud.com/api/v2/open/balance" \
 -H "Authorization: Bearer your_auth_token_here"

Endpoints

1. create Grok Imagine task**POST** /api/v2/open/aigc/grok

Create a Grok Imagine imageor Video Generationtask.

Content-Type: application/json

Request Parameters

ParameterTypeRequiredDescription
promptstringYesimage/videoPrompt
genTypestringNoGeneration type:t2i(Text-to-Image,default) / i2i(Image-to-Image) / t2v(Text-to-Video) / i2v(Image-to-Video)
imageUrlsstring[]ConditionReference image URL list, Image-to-Image/Image-to-Videowhen Required
base64FilestringNoBase64 encoded image data, supports jpg/png/gif/webp, maximum 10MB
base64FileListstring[]NoBase64 multiple encoded imagesdata, each supports jpg/png/gif/webp, single imagemaximum 10MB
aspectRatiostringNoAspect ratio:2:3 / 3:2 / 1:1 / 16:9 / 9:16, default 1:1
enableProbooleanNoquality(onlyText-to-Imagevalid), true=height quality, false=localized example text
modestringNo(onlyvideovalid):fun / normal(default) / spicy
durationintegerNovideoDuration (onlyvideovalid):6/10/15/20/30seconds, default6seconds
resolutionstringNovideoResolution (onlyvideovalid):480p(default) / 720p
callbackUrlstringNoCallback notification URL after the task is complete
Description:
- base64File, imageUrls, base64FileList can be used together, image processing order is:base64File (single image, placed first)→ imageUrls (URLlist)→ base64FileList (multiple imagesbase64, appended to the end)
- Image-to-Image/Image-to-Videowhen must provide Reference image> - videoParameter (mode/duration/resolution)onlyint2v andi2v localized example text> - A pre-authorization charge is applied on task creation; insufficient balance returns an error

Request Example

Text-to-Image:

{
 "prompt": "A beautiful sunset over the ocean, oil painting style",
 "aspectRatio": "16:9",
 "enablePro": true
}

Image-to-Image:

{
 "prompt": "Transform this image into watercolor style",
 "genType": "i2i",
 "imageUrls": ["https://example.com/reference.jpg"]
}

Text-to-Video:

{
 "prompt": "A couple dancing in a romantic setting",
 "genType": "t2v",
 "aspectRatio": "16:9",
 "mode": "normal",
 "duration": 10,
 "resolution": "720p"
}

Image-to-Video:

{
 "prompt": "Make the person wave their hand",
 "genType": "i2v",
 "imageUrls": ["https://example.com/reference.jpg"],
 "mode": "fun",
 "duration": 6,
 "resolution": "480p"
}

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_20260422103000_abc12345",
 "status": "processing",
 "createdAt": "2026-04-22 10:30:00"
 }
}

Insufficient balance

{
 "code": 40001,
 "msg": "Insufficient balance, first: 0.0100 USD,: 0.0750 USD",
 "data": null
}

2. Query Task Status

GET /api/v2/open/aigc/{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[]Generated image/video URL list (Successreturned when applicable)
data.errorMsgstringError Message (Failurereturned when applicable)
data.createdAtstringCreated Time
data.updatedAtstringUpdated Time

Response Example

processing

{
 "code": 0,
 "msg": "success",
 "data": {
 "taskId": "task_20260422103000_abc12345",
 "status": "processing",
 "createdAt": "2026-04-22 10:30:00",
 "updatedAt": "2026-04-22 10:30:05"
 }
}

Success

{
 "code": 0,
 "msg": "success",
 "data": {
 "taskId": "task_20260422103000_abc12345",
 "status": "success",
 "result": [
 "https://fc-gw-sh.oss-accelerate.aliyuncs.com/images/2026/04/22/output_001.png"
 ],
 "createdAt": "2026-04-22 10:30:00",
 "updatedAt": "2026-04-22 10:31:30"
 }
}

Failure

{
 "code": 0,
 "msg": "success",
 "data": {
 "taskId": "task_20260422103000_abc12345",
 "status": "failed",
 "errorMsg": "Failure:",
 "createdAt": "2026-04-22 10:30:00",
 "updatedAt": "2026-04-22 10:30:45"
 }
}

3. Batch Query Task Status

POST /api/v2/open/aigc/batch

query task execute Status (up to 100 ).

Request Parameters

ParameterTypeRequiredDescription
taskIdsstring[]YesTask ID list, up to 100

Request Example

{
 "taskIds": ["task_20260422103000_abc12345", "task_20260422103200_def67890"]
}

Response Example

{
 "code": 0,
 "msg": "success",
 "data": {
 "tasks": [
 {
 "taskId": "task_20260422103000_abc12345",
 "status": "success",
 "result": ["https://fc-gw-sh.oss-accelerate.aliyuncs.com/images/output_001.png"],
 "createdAt": "2026-04-22 10:30:00",
 "updatedAt": "2026-04-22 10:31:30"
 },
 {
 "taskId": "task_20260422103200_def67890",
 "status": "processing",
 "createdAt": "2026-04-22 10:32:00",
 "updatedAt": "2026-04-22 10:32:05"
 }
 ]
 }
}

4. Query Account Balance

GET /api/v2/open/balance

Query the current user's account balance.

Response Parameters

ParameterTypeDescription
codeintStatus Code, 0 indicates success
msgstringMessage
data.userIdstringID
data.balancestringcan use (USD)
data.frozenBalancestring(USD)
data.currencystringType

Response Example

{
 "code": 0,
 "msg": "success",
 "data": {
 "userId": "user@example.com",
 "balance": "19.9250",
 "frozenBalance": "0.0750",
 "currency": "USD"
 }
}

Callback Notification

task complete (Success or Failure) when, if Create Task when providecallbackUrl, was provided when creating the task, the system sends a POST request to that URL.

Callback Request

Headers

Content-Type: application/json
X-Funcloud-Event: task.completed
X-Funcloud-Signature: {localized example text}

Body

{
 "event": "task.completed",
 "taskId": "task_20260422103000_abc12345",
 "status": "success",
 "result": ["https://fc-gw-sh.oss-accelerate.aliyuncs.com/images/output_001.png"],
 "errorMsg": "",
 "timestamp": "2026-04-22T10:31:30+08:00",
 "signature": "a1b2c3d4e5f6..."
}

Callback Response

return HTTP 2xx Status Codeindicates success:```json
{
"code": 0,
"msg": "ok"
}


---

## Description (mode Parameter)| localized example text| Description |
|-----|------|
| fun | with,, /Scenario|
| normal | (default),|
| spicy |,|

---

## Error Codes

| code | Description |
|------|------|
| 0 | Success |
| 10002 | Parametermissing or malformed |
| 10005 | API Key invalid or missing |
| 30003 | Task not found |
| 40001 | Insufficient balance |
| 90003 | Internal server error |

---

## Best Practices

### 1. Polling Strategy

recommendedPolling:
- First 30 seconds:query every 3 seconds
- 30 seconds~ 2 minutes:query every 5 seconds
- After 2 minutes:query every 10 seconds

### 2. Use Callback, recommended use Callback NotificationPolling, can:
- reduce API calls
- receive result notifications faster
- reduce server load

### 3. Processing Time Reference

- Text-to-Image:Usually 10 ~ 30 seconds
- Image-to-Image:Usually 10 ~ 30 seconds
- Text-to-Video:Usually 1 ~ 3 minutes (Duration)
- Image-to-Video:Usually 1~ 3 minutes (Duration)### 4. Balance Management

- Create Taskfirst recommended query, Insufficient balancetaskFailure
- taskSuccessdeducts from the frozen balanceafter success
- taskFailureafter the frozen amount is automatically returnedto available balance
Updated 2026-09-02