Skip to content

Grok Imagine Image 2.0 Segment Edit ​

本页由 ModelFold 文档站根据上游官方 OpenAPI 文档同步生成。接口路径、参数、示例与官方保持一致;品牌与 API 域名已替换为 ModelFold。

接口 ​

POST /jobs/createTask

完整 URL: https://ai.modelfold.online/v1/jobs/createTask

鉴权:所有请求都需要 Authorization: Bearer <API_KEY> 请求头。

创建任务 ​

  • 查询任务详情 — 提交任务后,可通过统一查询接口查看任务进度并获取生成结果

TIP

生产环境建议优先使用 callBackUrl 参数接收任务完成通知,而不是持续轮询任务状态接口。

相关资源 ​

请求参数 ​

请求体 (application/json) ​

参数类型必填说明
modelstring是用于生成任务的模型名称。该字段为必填项。此接口必须使用 grok-imagine-image-2-0/segment-edit 模型。 默认值:"grok-imagine-image-2-0/segment-edit"。 可选值:grok-imagine-image-2-0/segment-edit。 示例:grok-imagine-image-2-0/segment-edit。
callBackUrlstring否任务完成通知的回调 URL。该参数为可选项。如果提供,当任务完成时,无论成功或失败,系统都会向该 URL 发送 POST 请求。如果未提供,则不会发送回调通知。 示例:https://your-domain.com/api/callback。
inputobject是Grok Imagine 图像编辑任务的输入参数。
  input.promptstring是描述所需图像的文本提示词。最多 65,000 个字符。 示例:将背景改为夕阳海滩,同时保留主体。。
  input.task_idstring是用于图像编辑的源任务 ID(可以是根据grok-imagine-image-2-0/text-to-image模型生成的taskid,也可以是grok-imagine-image-2-0/segment-map模型通过传递image_url生成的taskid)。 示例:task_grok_imagine_1234567890。
  input.mask_indexsarray&lt;integer&gt;否要编辑的分块编号,取自 segment-map 任务结果 resultObject.segments[].index(从 0 开始)。例如 [0, 2]。

请求示例 ​

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": "将背景改为夕阳海滩,同时保留主体。",
    "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": "将背景改为夕阳海滩,同时保留主体。",
    "task_id": "task_grok_imagine_1234567890",
    "mask_indexs": [
      1,
      2
    ]
  }
}

响应 ​

200 — 请求成功 ​

参数类型必填说明
codeinteger是请求状态码。请求失败时 HTTP 状态仍为 200,请始终以本字段判断:200 表示成功,其他值均表示失败,原因见 msg。常见值:401 API key 无效或缺失;402 积分不足;429 超出频率限制;422 或 500 请求未能处理(请先查看 msg、检查参数,再决定是否重试)。 可选值:200 / 401 / 402 / 404 / 422 / 429 / 433 / 455 / 500 / 501 / 505。 示例:200。
msgstring是响应消息,失败时的错误描述
dataobject是—
  data.taskIdstring否任务 ID,可用于调用任务详情接口查询任务状态和结果。 示例:task_grok_imagine_1234567890。
json
{
  "code": 200,
  "msg": "success",
  "data": {
    "taskId": "task_grok_imagine_1234567890"
  }
}

回调 ​

onImageGenerated ​

回调地址:{$request.body#/callBackUrl}(即请求体里的 callBackUrl)。

任务成功或失败时发送回调。

回调体参数

参数类型必填说明
codeinteger是200:成功;501:失败,原因见 data.failCode 与 data.failMsg。 可选值:200 / 501。 示例:200。
msgstring是回调状态消息。 示例:Playground task completed successfully.。
dataobject是图像编辑任务返回的完成数据。
  data.completeTimeinteger否任务完成时间,使用 Unix 毫秒时间戳表示。 示例:1786431871000。
  data.costTimeinteger否处理耗时(秒),成功和失败回调都会返回。 示例:11。
  data.createTimeinteger否任务创建时间,使用 Unix 毫秒时间戳表示。 示例:1786431859000。
  data.creditsConsumednumber否本任务消耗的积分;失败任务为 0。 示例:4。
  data.modelstring否任务使用的模型。 可选值:grok-imagine-image-2-0/segment-edit。 示例:grok-imagine-image-2-0/segment-edit。
  data.paramstring否创建任务时提交的参数,使用 JSON 字符串格式表示。 示例:{"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否生成的图像 URL,使用 JSON 字符串格式表示。仅在 state 为 success 时出现。 示例:{"resultUrls":["https://tempfile.aiquickdraw.com/g/users/example/generated/example/image.jpg"]}。
  data.statestring否任务最终状态。 可选值:success / fail。 示例:success。
  data.taskIdstring否任务唯一标识。 示例:task_grok_imagine_image_edit_1234567890。
  data.updateTimeinteger否完成时间请以 completeTime 为准;updateTime 可能与 createTime 相同。 示例:1786431871000。
  data.failCodestring否失败码,数字字符串,如 "400"、"500"。仅在 state 为 fail 时出现。 示例:500。
  data.failMsgstring否失败原因,仅在 state 为 fail 时出现。 示例:&lt;error detail&gt;。

任务成功

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
  }
}

任务失败

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 — 一个 API,接入所有主流 AI 模型。