> ## 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 imagine task

> Use POST /mj/submit/imagine in CometAPI to create Midjourney imagine tasks with full Discord params, track task_id status, and enable image-to-video motion effects.

Use this endpoint to start the main Midjourney workflow. Every later step, including upscale, variation, and custom zoom, begins with a successful imagine task.

## What the first response gives you

* `result` is the task id you will poll next
* `code` can still be a success code even when it is not HTTP-style `200`

## Core workflow

<Steps>
  <Step title="Submit the imagine task">
    Send the prompt and store the returned task id.
  </Step>

  <Step title="Poll until the task finishes">
    Use [Fetch Single Task](./task-fetching-api/fetch-single-task) until the task reaches `SUCCESS`, `MODAL`, or `FAILURE`.
  </Step>

  <Step title="Continue with post-processing">
    When buttons appear, use [Action](./action) for upscale, variation, reroll, zoom, and similar follow-up operations.
  </Step>
</Steps>

## Optional video prompt pattern

If you want motion from a source image, add an image URL plus Midjourney video flags in the prompt, such as `--video` and `--motion`.


## OpenAPI

````yaml api/openapi/image/midjourney/post-imagine.openapi.json POST /mj/submit/imagine
openapi: 3.1.0
info:
  title: Imagine API
  version: 1.0.0
  description: >-
    Create a Midjourney imagine task through CometAPI and receive a task id for
    later polling.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /mj/submit/imagine:
    post:
      summary: Create a Midjourney imagine task
      description: >-
        Submit the primary Midjourney generation request. Poll the returned task
        id with the fetch endpoint until the task reaches a terminal state.
      operationId: imagine
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - prompt
              properties:
                botType:
                  type: string
                  description: >-
                    Bot type to use. `MID_JOURNEY` for Midjourney (default),
                    `NIJI_JOURNEY` for Niji.
                  default: MID_JOURNEY
                  enum:
                    - MID_JOURNEY
                    - NIJI_JOURNEY
                prompt:
                  type: string
                  description: >-
                    Text prompt for the generation. Supports standard Midjourney
                    parameters such as `--v`, `--ar`, `--stylize`, etc.
                  example: a paper boat floating on calm water at sunrise --v 6.1
                accountFilter:
                  type: object
                  description: >-
                    Filter which Midjourney account modes may be used for this
                    task.
                  properties:
                    modes:
                      type: array
                      description: Allowed speed modes, e.g. `FAST`, `RELAX`, or `TURBO`.
                      items:
                        type: string
                base64Array:
                  type: array
                  description: >-
                    Base64-encoded reference images. Each item should be a data
                    URI such as `data:image/png;base64,xxx`.
                  items:
                    type: string
                state:
                  type: string
                  description: >-
                    Custom state string. Returned as-is in the task result and
                    webhook callback for your own tracking.
              default:
                botType: MID_JOURNEY
                prompt: a paper boat floating on calm water at sunrise --v 6.1
                accountFilter:
                  modes:
                    - FAST
            examples:
              Default:
                summary: Default
                value:
                  botType: MID_JOURNEY
                  prompt: a paper boat floating on calm water at sunrise --v 6.1
                  accountFilter:
                    modes:
                      - FAST
      responses:
        '200':
          description: Task accepted.
          content:
            application/json:
              schema:
                type: object
                required:
                  - code
                  - description
                  - result
                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
                  properties:
                    type: object
                    properties:
                      discordChannelId:
                        type: string
                      discordInstanceId:
                        type: string
                  result:
                    type: string
                    description: Task id returned after submission.
                example:
                  code: 1
                  description: Submission successful
                  result: '1773314942177684'
                  properties:
                    discordChannelId: 5e6ca8e1f40e4de6
                    discordInstanceId: 5e6ca8e1f40e4de6
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/mj/submit/imagine \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                  "botType": "MID_JOURNEY",
                  "prompt": "a paper boat floating on calm water at sunrise --v 6.1",
                  "accountFilter": {
                    "modes": [
                      "FAST"
                    ]
                  }
                }'
        - lang: Python
          label: Default
          source: >
            import os

            import requests


            response = requests.post(
                "https://api.cometapi.com/mj/submit/imagine",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                        "botType": "MID_JOURNEY",
                        "prompt": "a paper boat floating on calm water at sunrise --v 6.1",
                        "accountFilter": {
                                "modes": [
                                        "FAST"
                                ]
                        }
                },
            )


            task = response.json()

            print(task["code"], task.get("result"))  # code 1 means submitted;
            result is the task id
        - lang: JavaScript
          label: Default
          source: >
            const response = await
            fetch("https://api.cometapi.com/mj/submit/imagine", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                        "botType": "MID_JOURNEY",
                        "prompt": "a paper boat floating on calm water at sunrise --v 6.1",
                        "accountFilter": {
                            "modes": [
                                "FAST"
                            ]
                        }
                    }),
            });


            const task = await response.json();

            console.log(task.code, task.result); // code 1 means submitted;
            result is the task id
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: Bearer token authentication. Use your CometAPI key.

````