> ## Documentation Index
> Fetch the complete documentation index at: https://apidoc.cometapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 创建 Midjourney 编辑任务

> 使用 CometAPI Submit Editor API（POST /mj/submit/edits）通过 maskBase64、prompt、可选原图以及透明编辑来编辑 Midjourney 图像。

使用此端点可以通过蒙版编辑 Midjourney 图像，或者基于 prompt 和源图像生成透明背景结果。

## 两种常见模式

* 蒙版编辑：发送 `maskBase64` 和 `prompt`，也可选择附带原始 `image`
* 透明绘制：当你希望在不提供单独蒙版的情况下获得透明背景结果时，发送 `image` 和 `prompt`

## 任务流程

<Steps>
  <Step title="提交编辑任务">
    选择编辑模式，发送 prompt 和源数据，然后保存返回的任务 id。
  </Step>

  <Step title="轮询任务">
    使用 [获取单个任务](./task-fetching-api/fetch-single-task) 直到任务进入终态。
  </Step>

  <Step title="基于结果继续操作">
    直接使用最终资源，或者当编辑结果提供后续操作按钮时触发 [Action](./action)。
  </Step>
</Steps>


## OpenAPI

````yaml api/openapi/image/midjourney/post-submit-editor.openapi.json POST /mj/submit/edits
openapi: 3.1.0
info:
  title: Submit Editor API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /mj/submit/edits:
    post:
      summary: Submit Editor
      operationId: submit_editor
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - prompt
                - image
              properties:
                prompt:
                  type: string
                  description: Text prompt describing the desired edit.
                  default: Change to white background
                image:
                  type: string
                  description: >-
                    Image to edit. Pass a public URL or a base64-encoded data
                    URI.
                  default: https://your-image-host/source.png
                state:
                  type: string
                  description: >-
                    Custom state string. Returned as-is in the task result and
                    webhook callback for your own tracking.
                notifyHook:
                  type: string
                  description: >-
                    Webhook URL to receive task status updates. Falls back to
                    your account-level webhook if omitted.
                noStorage:
                  type: boolean
                  description: >-
                    When `true`, return the original provider image URL instead
                    of a CometAPI-proxied link.
              default:
                prompt: Change to white background
                image: https://your-image-host/source.png
            examples:
              Edit by image URL:
                summary: >-
                  Edit an existing image referenced by URL (replace the URL with
                  your image)
                value:
                  prompt: Change to white background
                  image: https://your-image-host/source.png
              Edit by base64 image:
                summary: >-
                  Edit an inline base64 image. Replace the data URI with your
                  own image data.
                value:
                  prompt: Change to white background
                  image: data:image/jpeg;base64,<your-image-base64>
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  code:
                    type: integer
                    description: >-
                      Submission status code. `1` = submitted successfully
                      (`result` carries the task id). `21` = the action opened a
                      confirmation modal; continue with `/mj/submit/modal` using
                      the returned task id. `4` = parameter error; `description`
                      explains the cause.
                  description:
                    type: string
                  result:
                    type: string
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/mj/submit/edits \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                "prompt": "Change to white background",
                "image": "https://your-image-host/source.png"
              }'
        - lang: Python
          label: Default
          source: |
            import os
            import requests

            response = requests.post(
                "https://api.cometapi.com/mj/submit/edits",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                    "prompt": "Change to white background",
                    "image": "https://your-image-host/source.png",
                },
            )

            task = response.json()
            print(task["code"], task.get("result"))
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/mj/submit/edits", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                    prompt: "Change to white background",
                    image: "https://your-image-host/source.png",
                }),
            });


            const task = await response.json();

            console.log(task.code, task.result);
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````