Skip to content

Grok Imagine Image 2.0 Segment Edit ​

This page is generated from the upstream official OpenAPI documentation. Endpoints, parameters and examples match the official docs; brand and API domain are replaced with ModelFold.

Endpoint ​

POST /jobs/createTask

Full URL: https://ai.modelfold.online/v1/jobs/createTask

Authentication: every request must include the Authorization: Bearer <API_KEY> header.

Create Task ​

  • Get Task Details — After submission, use the unified query endpoint to check task progress and retrieve results

TIP

For production use, we recommend providing the callBackUrl parameter so your service can receive completion notifications instead of polling for task status.

Request Parameters ​

Body (application/json) ​

ParameterTypeRequiredDescription
modelstringYesThe model name used for generation. This field is required. This endpoint must use the grok-imagine-image-2-0/segment-edit model. Default:"grok-imagine-image-2-0/segment-edit"。 Allowed values:grok-imagine-image-2-0/segment-edit。 示例:grok-imagine-image-2-0/segment-edit。
callBackUrlstringNoCallback URL for task completion notifications. Optional parameter. If provided, the system will send a POST request to this URL when the task completes, whether it succeeds or fails. If omitted, no callback notification will be sent. 示例:https://your-domain.com/api/callback。
inputobjectYesInput parameters for the Grok Imagine image editing task.
  input.promptstringYesText prompt describing the desired image. Up to 65,000 characters. 示例:Change the background to a sunset beach while preserving the subject.。
  input.task_idstringYesThe source task ID to use for image editing(This can be a task ID generated by the grok-imagine-image-2-0/text-to-image model, or a task ID generated by the grok-imagine-image-2-0/segment-map model by passing an image_url.). 示例:task_grok_imagine_1234567890。
  input.mask_indexsarray&lt;integer&gt;NoIndexes of the segments to edit, taken from resultObject.segments[].index of the segment-map task (0-based). Example: [0, 2].

Request Example ​

bash
curl -X POST "https://ai.modelfold.online/v1/jobs/createTask" \
  -H "Authorization: Bearer $MODELFOLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "model": "grok-imagine-image-2-0/segment-edit",
  "callBackUrl": "https://your-domain.com/api/callback",
  "input": {
    "prompt": "Change the background to a sunset beach while preserving the subject.",
    "task_id": "task_grok_imagine_1234567890",
    "mask_indexs": [
      1,
      2
    ]
  }
}'
json
{
  "model": "grok-imagine-image-2-0/segment-edit",
  "callBackUrl": "https://your-domain.com/api/callback",
  "input": {
    "prompt": "Change the background to a sunset beach while preserving the subject.",
    "task_id": "task_grok_imagine_1234567890",
    "mask_indexs": [
      1,
      2
    ]
  }
}

Response ​

200 — Request successful ​

参数类型必填说明
dataobject否—
  data.taskIdstring否Task ID used to query task status and results. 示例:task_grok_imagine_1234567890。
json
{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_grok_imagine_1234567890"
  }
}

Callback ​

onImageGenerated ​

Callback URL: {$request.body#/callBackUrl} (the callBackUrl in the request body).

Sent when the task succeeds or fails.

Callback body parameters

参数类型必填说明
codeinteger是200: success. 501: failure; see data.failCode and data.failMsg. Allowed values:200 / 501。 示例:200。
msgstring是Callback status message. 示例:Playground task completed successfully.。
dataobject是Task completion data returned by the image editing task.
  data.completeTimeinteger否Task completion time, represented as a Unix timestamp in milliseconds. 示例:1786431871000。
  data.costTimeinteger否Processing time in seconds. Present on both success and failure callbacks. 示例:11。
  data.createTimeinteger否Task creation time, represented as a Unix timestamp in milliseconds. 示例:1786431859000。
  data.creditsConsumednumber否Credits consumed by the task; 0 for failed tasks. 示例:4。
  data.modelstring否The model used for the task. Allowed values:grok-imagine-image-2-0/segment-edit。 示例:grok-imagine-image-2-0/segment-edit。
  data.paramstring否JSON string containing the parameters submitted when creating the task. 示例:{"input":"{\"prompt\":\"Change the background to a sunset beach while preserving the subject.\",\"task_id\":\"task_grok_imagine_1234567890\",\"mask_indexs\":[1,2]}","callBackUrl":"https://your-domain.com/api/callback","model":"grok-imagine-image-2-0/segment-edit"}。
  data.resultJsonstring否JSON string containing the generated image URLs. Present only when state is success. 示例:{"resultUrls":["https://tempfile.aiquickdraw.com/g/users/example/generated/example/image.jpg"]}。
  data.statestring否Terminal task state. Allowed values:success / fail。 示例:success。
  data.taskIdstring否The unique task identifier. 示例:task_grok_imagine_image_edit_1234567890。
  data.updateTimeinteger否Use completeTime as the completion time; updateTime may equal createTime. 示例:1786431871000。
  data.failCodestring否Failure code, a numeric string such as "400" or "500". Present only when state is fail. 示例:500。
  data.failMsgstring否Failure reason. Present only when state is fail. 示例:&lt;error detail&gt;。

Task completed successfully

json
{
  "code": 200,
  "msg": "Playground task completed successfully.",
  "data": {
    "taskId": "task_grok_imagine_image_edit_1234567890",
    "model": "grok-imagine-image-2-0/segment-edit",
    "state": "success",
    "param": "{\"input\":\"{\\\"prompt\\\":\\\"Change the background to a sunset beach while preserving the subject.\\\",\\\"task_id\\\":\\\"task_grok_imagine_1234567890\\\",\\\"mask_indexs\\\":[1,2]}\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"model\":\"grok-imagine-image-2-0/segment-edit\"}",
    "resultJson": "{\"resultUrls\":[\"https://tempfile.aiquickdraw.com/g/users/example/generated/example/image.jpg\"]}",
    "costTime": 11,
    "createTime": 1786431859000,
    "completeTime": 1786431871000,
    "updateTime": 1786431871000,
    "creditsConsumed": 4
  }
}

Task failed

json
{
  "code": 501,
  "msg": "Playground task failed.",
  "data": {
    "taskId": "task_grok_imagine_image_edit_1234567890",
    "model": "grok-imagine-image-2-0/segment-edit",
    "state": "fail",
    "param": "{\"input\":\"{\\\"prompt\\\":\\\"Change the background to a sunset beach while preserving the subject.\\\",\\\"task_id\\\":\\\"task_grok_imagine_1234567890\\\",\\\"mask_indexs\\\":[1,2]}\",\"callBackUrl\":\"https://your-domain.com/api/callback\",\"model\":\"grok-imagine-image-2-0/segment-edit\"}",
    "costTime": 11,
    "createTime": 1786431859000,
    "completeTime": 1786431871000,
    "updateTime": 1786431871000,
    "creditsConsumed": 0,
    "failCode": "500",
    "failMsg": "<error detail>"
  }
}

ModelFold — one API for all the best AI models.