> ## 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ụ hành động Midjourney

> Sử dụng CometAPI POST /mj/submit/action để áp dụng các hành động Midjourney—upscale, variation, reroll, zoom và nhiều hơn nữa—lên các hình ảnh đã được tạo.

Sử dụng endpoint này sau khi một tác vụ Midjourney trả về các nút hành động. Endpoint này bắt đầu một tác vụ downstream mới như upscale, variation, reroll, zoom hoặc pan.

## Bạn cần hai giá trị

* `taskId` từ tác vụ Midjourney gốc hoặc gần nhất
* `customId` từ mảng `buttons` mới nhất được trả về bởi [Fetch Single Task](./task-fetching-api/fetch-single-task)

<Warning>
  `customId` không cố định. Đừng bao giờ hardcode nó. Luôn đọc nó từ phản hồi polling mới nhất.
</Warning>

## Các hành động phổ biến

* `U1` đến `U4`: upscale một hình ảnh từ lưới
* `V1` đến `V4`: tạo các biến thể từ một vị trí hình ảnh
* Reroll: tạo lại toàn bộ lưới
* Zoom và Pan: mở rộng bố cục hiện có

## Sau khi bạn gửi một hành động

<Steps>
  <Step title="Tạo tác vụ tiếp theo">
    Gửi `taskId` và `customId`, sau đó lưu task id mới được trả về.
  </Step>

  <Step title="Poll tác vụ mới">
    Truy vấn [Fetch Single Task](./task-fetching-api/fetch-single-task) một lần nữa cho đến khi hành động hoàn tất.
  </Step>

  <Step title="Xử lý các hành động chỉ hỗ trợ modal">
    Nếu tác vụ mới đạt đến `MODAL`, tiếp tục với [Modal](./modal) để cung cấp dữ liệu đầu vào bổ sung.
  </Step>
</Steps>


## OpenAPI

````yaml api/openapi/image/midjourney/post-action.openapi.json POST /mj/submit/action
openapi: 3.1.0
info:
  title: Action API
  version: 1.0.0
  description: >-
    Create a Midjourney follow-up task such as upscale, variation, reroll, zoom,
    or pan using the latest button customId from the fetch response.
servers:
  - url: https://api.cometapi.com
security:
  - bearerAuth: []
paths:
  /mj/submit/action:
    post:
      summary: Create a Midjourney follow-up action task
      operationId: action
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - customId
                - taskId
              properties:
                customId:
                  type: string
                  description: >-
                    Action id taken from the latest `buttons` array returned by
                    the fetch endpoint.
                taskId:
                  type: string
                  description: Midjourney task id you want to continue from.
                state:
                  type: string
                  description: >-
                    Custom state string. Returned as-is in the task result and
                    webhook callback for your own tracking.
                enableRemix:
                  type: boolean
                  description: >-
                    Whether to force remix mode when the current action supports
                    it.
                chooseSameChannel:
                  type: boolean
                  description: >-
                    Whether to prefer the same provider account used by the
                    current task.
              default:
                customId: MJ::JOB::variation::3::example
                taskId: '1773314942177684'
                enableRemix: false
            examples:
              Upscale U1:
                summary: Upscale the first image (U1)
                value:
                  taskId: <task_id>
                  customId: MJ::JOB::upsample::1::<custom_id_hash>
              Vary Region:
                summary: >-
                  Open the Vary (Region) modal; the response returns code 21 and
                  a task id to use with /mj/submit/modal
                value:
                  taskId: <task_id>
                  customId: MJ::Inpaint::1::<custom_id_hash>::SOLO
      responses:
        '200':
          description: Action 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
                  result:
                    type: string
                    description: New Midjourney task id created for the action.
                  properties:
                    type: object
                    properties:
                      numberOfQueues:
                        type: integer
                      discordInstanceId:
                        type: string
                      discordChannelId:
                        type: string
      x-codeSamples:
        - lang: Shell
          label: Default
          source: |
            curl https://api.cometapi.com/mj/submit/action \
              -H "Authorization: Bearer $COMETAPI_KEY" \
              -H "Content-Type: application/json" \
              -d '{
                  "taskId": "<task_id>",
                  "customId": "MJ::JOB::upsample::1::<custom_id_hash>"
                }'
        - lang: Python
          label: Default
          source: >
            import os

            import requests


            response = requests.post(
                "https://api.cometapi.com/mj/submit/action",
                headers={"Authorization": "Bearer " + os.environ["COMETAPI_KEY"]},
                json={
                        "taskId": "<task_id>",
                        "customId": "MJ::JOB::upsample::1::<custom_id_hash>"
                },
            )


            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/action", {
                method: "POST",
                headers: {
                    Authorization: `Bearer ${process.env.COMETAPI_KEY}`,
                    "Content-Type": "application/json",
                },
                body: JSON.stringify({
                        "taskId": "<task_id>",
                        "customId": "MJ::JOB::upsample::1::<custom_id_hash>"
                    }),
            });


            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.

````