{
  "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": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer token authentication. Use your CometAPI key."
      }
    }
  },
  "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 \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n      \"taskId\": \"<task_id>\",\n      \"customId\": \"MJ::JOB::upsample::1::<custom_id_hash>\"\n    }'\n"
          },
          {
            "lang": "Python",
            "label": "Default",
            "source": "import os\nimport requests\n\nresponse = requests.post(\n    \"https://api.cometapi.com/mj/submit/action\",\n    headers={\"Authorization\": \"Bearer \" + os.environ[\"COMETAPI_KEY\"]},\n    json={\n            \"taskId\": \"<task_id>\",\n            \"customId\": \"MJ::JOB::upsample::1::<custom_id_hash>\"\n    },\n)\n\ntask = response.json()\nprint(task[\"code\"], task.get(\"result\"))  # code 1 means submitted; result is the task id\n"
          },
          {
            "lang": "JavaScript",
            "label": "Default",
            "source": "const response = await fetch(\"https://api.cometapi.com/mj/submit/action\", {\n    method: \"POST\",\n    headers: {\n        Authorization: `Bearer ${process.env.COMETAPI_KEY}`,\n        \"Content-Type\": \"application/json\",\n    },\n    body: JSON.stringify({\n            \"taskId\": \"<task_id>\",\n            \"customId\": \"MJ::JOB::upsample::1::<custom_id_hash>\"\n        }),\n});\n\nconst task = await response.json();\nconsole.log(task.code, task.result); // code 1 means submitted; result is the task id\n"
          }
        ]
      }
    }
  }
}
