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

# Créer une tâche imagine Midjourney

> Utilisez POST /mj/submit/imagine dans CometAPI pour créer des tâches imagine Midjourney avec tous les paramètres Discord, suivre l’état du task_id et activer des effets de mouvement d’image vers vidéo.

Utilisez ce endpoint pour démarrer le workflow principal de Midjourney. Chaque étape ultérieure, y compris l’upscale, la variation et le zoom personnalisé, commence par une tâche imagine réussie.

## Ce que la première réponse vous fournit

* `result` est l’identifiant de tâche que vous interrogerez ensuite
* `code` peut toujours être un code de réussite même lorsqu’il ne s’agit pas d’un `200` au format HTTP

## Workflow principal

<Steps>
  <Step title="Soumettre la tâche imagine">
    Envoyez le prompt et stockez l’identifiant de tâche renvoyé.
  </Step>

  <Step title="Interroger jusqu’à la fin de la tâche">
    Utilisez [Fetch Single Task](./task-fetching-api/fetch-single-task) jusqu’à ce que la tâche atteigne `SUCCESS`, `MODAL` ou `FAILURE`.
  </Step>

  <Step title="Continuer avec le post-traitement">
    Lorsque des boutons apparaissent, utilisez [Action](./action) pour l’upscale, la variation, le reroll, le zoom et les opérations de suivi similaires.
  </Step>
</Steps>

## Modèle facultatif de prompt vidéo

Si vous souhaitez du mouvement à partir d’une image source, ajoutez une URL d’image ainsi que des flags vidéo Midjourney dans le prompt, comme `--video` et `--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.

````