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

> Use CometAPI POST /mj/submit/action to apply Midjourney actions—upscale, variation, reroll, zoom, and more—on generated images.

Use this endpoint after a Midjourney task returns action buttons. It starts a new downstream task such as upscale, variation, reroll, zoom, or pan.

## You need two values

* `taskId` from the original or most recent Midjourney task
* `customId` from the latest `buttons` array returned by [Fetch Single Task](./task-fetching-api/fetch-single-task)

<Warning>
  `customId` is not stable. Never hardcode it. Always read it from the latest polling response.
</Warning>

## Common actions

* `U1` to `U4`: upscale one image from the grid
* `V1` to `V4`: generate variations from one image position
* Reroll: regenerate the full grid
* Zoom and Pan: extend the existing composition

## After you submit an action

<Steps>
  <Step title="Create the follow-up task">
    Send `taskId` and `customId`, then store the new returned task id.
  </Step>

  <Step title="Poll the new task">
    Query [Fetch Single Task](./task-fetching-api/fetch-single-task) again until the action finishes.
  </Step>

  <Step title="Handle modal-only actions">
    If the new task reaches `MODAL`, continue with [Modal](./modal) to supply the extra input.
  </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.

````