> ## 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.

# Create a Midjourney blend task

> Submit images to the POST /mj/submit/blend endpoint to blend one or more inputs into a new Midjourney-style image with CometAPI.

Use this endpoint to blend 2 to 5 source images into a new Midjourney composition. It is a direct entry point and does not require a prior imagine task.

## Before you call it

* Prepare 2 to 5 source images
* Keep the first test small and skip extra account-routing options unless you need them
* Save the returned task id, because blending is still asynchronous

## Task flow

<Steps>
  <Step title="Submit the blend task">
    Send the source images through the blend endpoint and store the returned task id.
  </Step>

  <Step title="Poll the task">
    Use [Fetch Single Task](./task-fetching-api/fetch-single-task) until the task reaches a terminal state.
  </Step>

  <Step title="Continue from the result">
    When action buttons appear, use [Action](./action) for upscale, variation, or other follow-up steps.
  </Step>
</Steps>


## OpenAPI

````yaml api/openapi/image/midjourney/post-blend.openapi.json POST /mj/submit/blend
openapi: 3.1.0
info:
  title: Blend (image -> image) API
  version: 1.0.0
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /mj/submit/blend:
    post:
      summary: Blend (image -> image)
      operationId: blend
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - base64Array
              properties:
                base64Array:
                  type: array
                  description: >-
                    Two or more base64-encoded images to blend. Each item should
                    be a data URI such as `data:image/png;base64,xxx`.
                  items:
                    type: string
                  default:
                    - data:image/png;base64,<your-image-base64>
                dimensions:
                  type: string
                  description: Output aspect ratio.
                  enum:
                    - PORTRAIT
                    - SQUARE
                    - LANDSCAPE
                notifyHook:
                  type: string
                  description: >-
                    Webhook URL to receive task status updates. Falls back to
                    your account-level webhook if omitted.
                state:
                  type: string
                  description: >-
                    Custom state string. Returned as-is in the task result and
                    webhook callback for your own tracking.
                botType:
                  type: string
                  description: >-
                    Bot type to use. `MID_JOURNEY` for Midjourney (default),
                    `NIJI_JOURNEY` for Niji.
                  enum:
                    - MID_JOURNEY
                    - NIJI_JOURNEY
              default:
                base64Array:
                  - data:image/png;base64,<your-image-base64>
            examples:
              Default:
                summary: Default
                value:
                  botType: MID_JOURNEY
                  base64Array:
                    - data:image/png;base64,xxx1
                    - data:image/png;base64,xxx2
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - description
                  - properties
                  - result
                properties:
                  code:
                    type: integer
                    description: Status code
                  description:
                    type: string
                    description: >-
                      Human-readable description message corresponding to the
                      status code
                  properties:
                    type: object
                    description: Additional properties or metadata
                    properties: {}
                  result:
                    type: integer
                    description: Returned task ID
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            IMG1=$(base64 < first.jpg | tr -d '\n')
            IMG2=$(base64 < second.jpg | tr -d '\n')

            curl https://api.cometapi.com/mj/submit/blend \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d "{
                \"botType\": \"MID_JOURNEY\",
                \"base64Array\": [
                  \"data:image/jpeg;base64,$IMG1\",
                  \"data:image/jpeg;base64,$IMG2\"
                ],
                \"dimensions\": \"SQUARE\"
              }"
        - lang: Python
          label: Default
          source: |
            import base64
            import os
            import requests

            def to_data_uri(path):
                with open(path, "rb") as f:
                    return "data:image/jpeg;base64," + base64.b64encode(f.read()).decode()

            response = requests.post(
                "https://api.cometapi.com/mj/submit/blend",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                    "botType": "MID_JOURNEY",
                    "base64Array": [to_data_uri("first.jpg"), to_data_uri("second.jpg")],
                    "dimensions": "SQUARE",
                },
            )

            task = response.json()
            print(task["code"], task.get("result"))
        - lang: JavaScript
          label: Default
          source: >
            import { readFile } from "node:fs/promises";


            async function toDataUri(path) {
                return `data:image/jpeg;base64,${(await readFile(path)).toString("base64")}`;
            }


            const response = await
            fetch("https://api.cometapi.com/mj/submit/blend", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                    botType: "MID_JOURNEY",
                    base64Array: [await toDataUri("first.jpg"), await toDataUri("second.jpg")],
                    dimensions: "SQUARE",
                }),
            });


            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.

````