> ## Documentation Index
> Fetch the complete documentation index at: https://docs.inputapi.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Midjourney task integration

> Inspect existing tasks and understand action routes and business errors.

Midjourney uses a separate `/mj/*` task protocol, not the request or response format of `/v1/images/generations`. Configure a matching channel and use a gateway Bearer token. `/{mode}/mj/*` variants also exist; available modes depend on the deployment.

## Minimal read example

Use the [REST runtime](/en/guides/http-runtime.md) with an existing public task ID. The script queries once, submits no generation, and downloads no returned URLs.

```bash theme={null}
export API_MJ_TASK_ID="YOUR_MJ_TASK_ID"
node examples/midjourney-status.mjs
```

Successful reads return fields such as `id`, `status`, and `progress`. Business errors may use HTTP 200 with `code` / `description`; the example rejects that envelope and validates the ID and status. A successful process exit means the query succeeded; only `completed: true` means task success. `imageUrl` may be a signed gateway URL: keep it out of public logs. Video tasks also have `videoUrl` / `videoUrls`; do not assume every result is an image. See [task API](/en/api-reference/midjourney-task.md).

A newly accepted task can temporarily have an empty `status`. The example labels it `PENDING` locally and does not mark it complete; this does not add a server status.

## Submission and follow-up actions

`MidjourneyRequest` includes action-dependent fields such as `prompt`, `taskId`, `customId`, `action`, `index`, and `base64Array`. Submission typically returns `code`, `description`, `result`, and `properties`. Retain the task ID after business acceptance and query it; HTTP 200 is not image completion. Upstream proxies differ in action and `customId` formats. Obtain valid payloads from the operator instead of deriving parameters from button labels.

The following routes are registered, but the table does not replace provider payload documentation. `/mj/notify` is not registered; a `notifyHook` DTO field does not mean the gateway hosts a callback receiver.

| POST path | Purpose |
| - | - |
| `/mj/submit/imagine` | Text-to-image |
| `/mj/submit/action`, `/mj/submit/modal` | Returned button action and modal input |
| `/mj/submit/change`, `/mj/submit/simple-change` | Variants and changes |
| `/mj/submit/describe`, `/mj/submit/blend` | Description and image blending |
| `/mj/submit/shorten`, `/mj/submit/edits` | Prompt shortening and edits |
| `/mj/submit/video` | Video action |
| `/mj/submit/upload-discord-images` | Image upload action |
| `/mj/insight-face/swap` | Separate face-swap request structure |
| `/mj/task/list-by-condition` | Accepts `ids`; returns owned tasks without guaranteed input order |

Also available: `GET /mj/task/{id}/image-seed` for seeds and `GET /mj/image/{id}` for proxied images. Neither response is the task JSON contract. Avoid automatic generation retries and validate polling, business codes, and final artifacts against the selected upstream.

```javascript theme={null}
import { requestJSON } from './http-client.mjs';

try {
  const id = process.env.API_MJ_TASK_ID;
  if (!/^[A-Za-z0-9_-][A-Za-z0-9._~-]{0,127}$/.test(id || '')) throw new Error('Set API_MJ_TASK_ID.');
  const result = await requestJSON(`/mj/task/${encodeURIComponent(id)}/fetch`);
  if ('code' in result || result.id !== id
    || !['', 'NOT_START', 'SUBMITTED', 'IN_PROGRESS', 'SUCCESS', 'FAILURE'].includes(result.status)) {
    throw new Error('Invalid task or business error.');
  }
  // Query once; SUCCESS describes task state, not a downloaded or verified image.
  console.log(JSON.stringify({ id, status: result.status || 'PENDING', completed: result.status === 'SUCCESS' }));
} catch {
  console.error('Midjourney status request failed. No automatic submission or retry.');
  process.exitCode = 1;
}
```

[阅读中文版](/zh/guides/midjourney.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.