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

# Tạo một tác vụ Midjourney imagine

> Sử dụng POST /mj/submit/imagine trong CometAPI để tạo các tác vụ Midjourney imagine với đầy đủ tham số Discord, theo dõi trạng thái task_id và bật hiệu ứng chuyển động image-to-video.

Sử dụng endpoint này để bắt đầu quy trình chính của Midjourney. Mọi bước về sau, bao gồm upscale, variation và custom zoom, đều bắt đầu từ một tác vụ imagine thành công.

## Phản hồi đầu tiên cung cấp gì

* `result` là id tác vụ mà bạn sẽ poll tiếp theo
* `code` vẫn có thể là mã thành công ngay cả khi nó không phải kiểu HTTP `200`

## Quy trình cốt lõi

<Steps>
  <Step title="Gửi tác vụ imagine">
    Gửi prompt và lưu task id được trả về.
  </Step>

  <Step title="Poll cho đến khi tác vụ hoàn tất">
    Sử dụng [Fetch Single Task](./task-fetching-api/fetch-single-task) cho đến khi tác vụ đạt `SUCCESS`, `MODAL` hoặc `FAILURE`.
  </Step>

  <Step title="Tiếp tục với hậu xử lý">
    Khi các nút xuất hiện, hãy dùng [Action](./action) cho upscale, variation, reroll, zoom và các thao tác tiếp theo tương tự.
  </Step>
</Steps>

## Mẫu prompt video tùy chọn

Nếu bạn muốn tạo chuyển động từ một ảnh nguồn, hãy thêm URL ảnh cùng các cờ video của Midjourney vào prompt, chẳng hạn như `--video` và `--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.

````