# Grok Imagine Image 2.0 Segment Edit

## OpenAPI Specification

```yaml
openapi: 3.0.1
info:
  title: ''
  description: ''
  version: 1.0.0
paths:
  /api/v1/jobs/createTask:
    post:
      summary: Grok Imagine Image 2.0 Segment Edit
      deprecated: false
      description: >-
        ## Create Task


        <Card title="Get Task Details" icon="lucide-search"
        href="/market/common/get-task-detail">
          After submission, use the unified query endpoint to check task progress and retrieve results
        </Card>


        ::: tip[]

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

        :::


        ## Related Resources


        <CardGroup cols={2}>
          <Card title="Model Marketplace" icon="lucide-store" href="/market/quickstart">
            Explore all available models and capabilities
          </Card>
          <Card title="Common API" icon="lucide-cog" href="/common-api/get-account-credits">
            Check account credits and usage
          </Card>
        </CardGroup>
      operationId: grok-imagine-image-2-0-segment-edit
      tags:
        - docs/en/Market/Image    Models/Grok Imagine
      parameters: []
      requestBody:
        content:
          application/json:
            schema:
              type: object
              required:
                - model
                - input
              properties:
                model:
                  type: string
                  enum:
                    - grok-imagine-image-2-0/segment-edit
                  default: grok-imagine-image-2-0/segment-edit
                  description: >-
                    The model name used for generation. This field is required.
                    This endpoint must use the
                    `grok-imagine-image-2-0/segment-edit` model.
                  examples:
                    - grok-imagine-image-2-0/segment-edit
                callBackUrl:
                  type: string
                  format: uri
                  description: >-
                    Callback 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.
                  examples:
                    - https://your-domain.com/api/callback
                input:
                  type: object
                  description: Input parameters for the Grok Imagine image editing task.
                  required:
                    - prompt
                    - task_id
                  properties:
                    prompt:
                      type: string
                      description: >-
                        Text prompt describing the desired image. Up to 65,000
                        characters.
                      examples:
                        - >-
                          Change the background to a sunset beach while
                          preserving the subject.
                      maxLength: 65000
                    task_id:
                      type: string
                      description: >-
                        The 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`.).
                      examples:
                        - task_grok_imagine_1234567890
                    mask_indexs:
                      type: array
                      minItems: 1
                      items:
                        type: integer
                        minimum: 0
                      description: >-
                        Indexes of the segments to edit, taken from
                        resultObject.segments[].index of the segment-map task
                        (0-based). Example: [0, 2].
                      examples:
                        - - 1
                          - 2
                  x-apidog-orders:
                    - prompt
                    - task_id
                    - mask_indexs
                  x-apidog-ignore-properties: []
              x-apidog-orders:
                - model
                - callBackUrl
                - input
              x-apidog-ignore-properties: []
            example:
              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
      responses:
        '200':
          description: Request successful
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/response%20not%20with%20recordId'
                  - type: object
                    properties:
                      data:
                        type: object
                        properties:
                          taskId:
                            type: string
                            description: Task ID used to query task status and results.
                            examples:
                              - task_grok_imagine_1234567890
                        x-apidog-orders:
                          - taskId
                        x-apidog-ignore-properties: []
                    x-apidog-orders:
                      - data
                    x-apidog-ignore-properties: []
              example:
                code: 200
                msg: success
                data:
                  taskId: task_grok_imagine_1234567890
          headers: {}
          x-apidog-name: ''
      security: []
      callbacks:
        onImageGenerated:
          '{$request.body#/callBackUrl}':
            post:
              summary: Image Generation Callback
              description: Sent when the task succeeds or fails.
              requestBody:
                required: true
                content:
                  application/json:
                    schema:
                      type: object
                      required:
                        - code
                        - msg
                        - data
                      properties:
                        code:
                          type: integer
                          description: >-
                            200: success. 501: failure; see data.failCode and
                            data.failMsg.
                          enum:
                            - 200
                            - 501
                          example: 200
                        msg:
                          type: string
                          description: Callback status message.
                          example: Playground task completed successfully.
                        data:
                          type: object
                          description: >-
                            Task completion data returned by the image editing
                            task.
                          properties:
                            completeTime:
                              type: integer
                              format: int64
                              description: >-
                                Task completion time, represented as a Unix
                                timestamp in milliseconds.
                              example: 1786431871000
                            costTime:
                              type: integer
                              description: >-
                                Processing time in seconds. Present on both
                                success and failure callbacks.
                              example: 11
                            createTime:
                              type: integer
                              format: int64
                              description: >-
                                Task creation time, represented as a Unix
                                timestamp in milliseconds.
                              example: 1786431859000
                            creditsConsumed:
                              type: number
                              format: double
                              description: >-
                                Credits consumed by the task; 0 for failed
                                tasks.
                              example: 4
                            model:
                              type: string
                              description: The model used for the task.
                              enum:
                                - grok-imagine-image-2-0/segment-edit
                              example: grok-imagine-image-2-0/segment-edit
                            param:
                              type: string
                              description: >-
                                JSON string containing the parameters submitted
                                when creating the task.
                              example: >-
                                {"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:
                              type: string
                              description: >-
                                JSON string containing the generated image URLs.
                                Present only when state is success.
                              example: >-
                                {"resultUrls":["https://tempfile.aiquickdraw.com/g/users/example/generated/example/image.jpg"]}
                            state:
                              type: string
                              description: Terminal task state.
                              enum:
                                - success
                                - fail
                              example: success
                            taskId:
                              type: string
                              description: The unique task identifier.
                              example: task_grok_imagine_image_edit_1234567890
                            updateTime:
                              type: integer
                              format: int64
                              description: >-
                                Use completeTime as the completion time;
                                updateTime may equal createTime.
                              example: 1786431871000
                            failCode:
                              type: string
                              description: >-
                                Failure code, a numeric string such as "400" or
                                "500". Present only when state is fail.
                              example: '500'
                            failMsg:
                              type: string
                              description: Failure reason. Present only when state is fail.
                              example: <error detail>
                    examples:
                      success:
                        summary: Task completed successfully
                        value:
                          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
                      failure:
                        summary: Task failed
                        value:
                          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>
              responses:
                '200':
                  description: Callback received successfully
      x-apidog-folder: docs/en/Market/Image    Models/Grok Imagine
      x-apidog-status: released
      x-run-in-apidog: https://app.apidog.com/web/project/1184766/apis/api-41734530-run
components:
  schemas:
    response not with recordId:
      type: object
      required:
        - data
      properties:
        code:
          type: integer
          description: >-
            Status code of the request. The HTTP status is 200 even when the
            request fails, so always check this field: 200 means success; any
            other value means the request failed and msg describes the reason.
            Common values: 401 invalid or missing API key; 402 insufficient
            credits; 429 rate limit exceeded; 422 or 500 the request could not
            be processed (read msg and check your parameters before retrying).
          enum:
            - 200
            - 401
            - 402
            - 404
            - 422
            - 429
            - 433
            - 455
            - 500
            - 501
            - 505
        msg:
          type: string
          description: Response message, error description upon failure
          examples:
            - success
        data:
          type: object
          required:
            - taskId
          properties:
            taskId:
              type: string
              description: >-
                The task ID can be used with the "Get Task Details" endpoint to
                query the task status.
              examples:
                - dc1928bfcbc77cb6c85f3359a9c718b3
          x-apidog-orders:
            - taskId
          x-apidog-ignore-properties: []
      x-apidog-orders:
        - code
        - msg
        - data
      x-apidog-ignore-properties: []
      x-apidog-folder: ''
  securitySchemes:
    BearerAuth:
      type: bearer
      scheme: bearer
      bearerFormat: API Key
      description: >-
        All API requests require a Bearer Token. Add the header `Authorization:
        Bearer YOUR_API_KEY` to authenticate requests.
    BearerAuth1:
      type: bearer
      scheme: bearer
      bearerFormat: API Key
      description: >-
        所有 API 请求都需要 Bearer Token。请在请求头中添加 `Authorization: Bearer YOUR_API_KEY`
        进行身份验证。
servers:
  - url: https://api.kie.ai
    description: 正式环境
security:
  - BearerAuth: []
    x-apidog:
      schemeGroups:
        - id: kn8M4YUlc5i0A0179ezwx
          schemeIds:
            - BearerAuth
      required: true
      use:
        id: kn8M4YUlc5i0A0179ezwx
      scopes:
        kn8M4YUlc5i0A0179ezwx:
          BearerAuth: []

```
