Skip to content

Grok Imagine Image 2.0 Text To Image ​

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 ​

Use this endpoint to create a new image generation task with Grok Imagine Image 2.0.

  • Get Task Details — After submitting a task, use the unified task detail endpoint to check progress and retrieve generated images

TIP

For production use, we recommend providing the callBackUrl parameter so your service can receive task 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/text-to-image model. Default:"grok-imagine-image-2-0/text-to-image"。 Allowed values:grok-imagine-image-2-0/text-to-image。 示例:grok-imagine-image-2-0/text-to-image。
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 image generation task.
  input.promptstringYesText prompt describing the desired image. This field is required. Up to 8,000 characters. 示例:A small wooden cabin beside a calm lake at sunrise, soft mist over the water。
  input.aspect_ratiostringYesSpecifies the width-to-height ratio of the generated image. Controls the aspect ratio of the output. This field is required. Allowed values:1:1 / 2:3 / 3:2 / 16:9 / 9:16。 示例:1:1。

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/text-to-image",
  "callBackUrl": "https://your-domain.com/api/callback",
  "input": {
    "prompt": "A small wooden cabin beside a calm lake at sunrise, soft mist over the water",
    "aspect_ratio": "1:1"
  }
}'
json
{
  "model": "grok-imagine-image-2-0/text-to-image",
  "callBackUrl": "https://your-domain.com/api/callback",
  "input": {
    "prompt": "A small wooden cabin beside a calm lake at sunrise, soft mist over the water",
    "aspect_ratio": "1:1"
  }
}

Response ​

200 — Request successful ​

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

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否Status message. 示例:Playground task completed successfully.。
dataobject否Task completion details and generated image results.
  data.completeTimeinteger否Task completion time, represented as a Unix timestamp in milliseconds.
  data.costTimeinteger否Processing time in seconds. Present on both success and failure callbacks.
  data.createTimeinteger否Task creation time, represented as a Unix timestamp in milliseconds.
  data.creditsConsumednumber否Credits consumed by the task; 0 for failed tasks.
  data.modelstring否Image generation model used for the task. 示例:grok-imagine-image-2-0/text-to-image。
  data.paramstring否Parameters submitted when creating the task, in JSON string format.
  data.resultJsonstring否Image generation result in JSON string format. The result URLs are contained in the resultUrls property. Present only when state is success. 示例:{"resultUrls":["https://example.com/generated-image-1.jpg"]}。
  data.statestring否Task status. Allowed values:success / fail。 示例:success。
  data.taskIdstring否Task ID. 示例:task_grok_imagine_image_2_0_12345678。
  data.updateTimeinteger否Use completeTime as the completion time; updateTime may equal createTime.
  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_2_0_12345678",
    "model": "grok-imagine-image-2-0/text-to-image",
    "state": "success",
    "resultJson": "{\"resultUrls\":[\"https://example.com/generated-image-1.jpg\"]}"
  }
}

Task failed

json
{
  "code": 501,
  "msg": "Playground task failed.",
  "data": {
    "taskId": "task_grok_imagine_image_2_0_12345678",
    "model": "grok-imagine-image-2-0/text-to-image",
    "state": "fail",
    "failCode": "500",
    "failMsg": "<error detail>",
    "creditsConsumed": 0
  }
}

ModelFold — one API for all the best AI models.