{
  "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": []
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "description": "Bearer token authentication. Use your CometAPI key."
      }
    }
  },
  "paths": {
    "/mj/submit/imagine": {
      "post": {
        "summary": "Create a Midjourney imagine task",
        "operationId": "imagine",
        "description": "Submit the primary Midjourney generation request. Poll the returned task id with the fetch endpoint until the task reaches a terminal state.",
        "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 \\\n  -H \"Authorization: Bearer $COMETAPI_KEY\" \\\n  -H \"Content-Type: application/json\" \\\n  -d '{\n      \"botType\": \"MID_JOURNEY\",\n      \"prompt\": \"a paper boat floating on calm water at sunrise --v 6.1\",\n      \"accountFilter\": {\n        \"modes\": [\n          \"FAST\"\n        ]\n      }\n    }'\n"
          },
          {
            "lang": "Python",
            "label": "Default",
            "source": "import os\nimport requests\n\nresponse = requests.post(\n    \"https://api.cometapi.com/mj/submit/imagine\",\n    headers={\"Authorization\": \"Bearer \" + os.environ[\"COMETAPI_KEY\"]},\n    json={\n            \"botType\": \"MID_JOURNEY\",\n            \"prompt\": \"a paper boat floating on calm water at sunrise --v 6.1\",\n            \"accountFilter\": {\n                    \"modes\": [\n                            \"FAST\"\n                    ]\n            }\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/imagine\", {\n    method: \"POST\",\n    headers: {\n        Authorization: `Bearer ${process.env.COMETAPI_KEY}`,\n        \"Content-Type\": \"application/json\",\n    },\n    body: JSON.stringify({\n            \"botType\": \"MID_JOURNEY\",\n            \"prompt\": \"a paper boat floating on calm water at sunrise --v 6.1\",\n            \"accountFilter\": {\n                \"modes\": [\n                    \"FAST\"\n                ]\n            }\n        }),\n});\n\nconst task = await response.json();\nconsole.log(task.code, task.result); // code 1 means submitted; result is the task id\n"
          }
        ]
      }
    }
  }
}
