# midjourney-api

> Midjourney API (third party)

Latest version **2.0.0** (published 2023-08-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install midjourney-api
pnpm add midjourney-api
yarn add midjourney-api
bun add midjourney-api
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.0 |
| Published | 2023-08-05 |
| First published | 2023-04-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 1.7 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 32 |
| Author | MIDJOURNEYAPI.IO |
| Maintainers | midjourneybyapi |
| Keywords | midjourney client, midjourney api, api midjourney, midjourney ai api, midjourney bot api, api midjourney api, api midjourney bot, midjourney api access |

## Links

- npm: https://www.npmjs.com/package/midjourney-api
- Repository: https://github.com/midjourney-api/midjourney-api
- Homepage: https://github.com/midjourney-api/midjourney-api#readme
- Issues: https://github.com/midjourney-api/midjourney-api/issues
- npm.io page: https://npm.io/package/midjourney-api

## Dependencies (2)

- [axios](https://npm.io/package/axios.md) ^1.4.0
- [form-data](https://npm.io/package/form-data.md) ^4.0.0

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 2.0.0 (latest) — 2023-08-05
- 1.0.3 — 2023-05-09
- 1.0.2 — 2023-04-28
- 1.0.1 — 2023-04-28
- 1.0.0 — 2023-04-28

## README

# [Midjourney API](https://slashimagine.pro) (unofficial)

A simple NPM module that wraps the [Midjourney API](https://slashimagine.pro), providing an easy-to-use interface for interacting with the [Midjourney API](https://slashimagine.pro) services.

## Installation

```bash
npm install midjourney-api
```

## Usage

Import the `MidjourneyAPI` class and create an instance with your API key and desired options. You can get your API Key and API Base URL at [Midjourney AI API](https://slashimagine.pro)

```javascript
const MidjourneyAPI = require('midjourney-api');

const apiKey = 'your-api-key';
const verbose = true;

const midjourney = new MidjourneyAPI(apiKey, verbose);
```

### Methods

The module provides the following methods:

- `imagine(prompt, callbackURL)`: Generate an image using a text prompt.
- `upscale(taskId, position)`: Upscale one of the 4 generated images by the Imagine command.
- `variations(taskId, position, callbackURL)`: Create 4 new variations of one of the 4 generated images by the Imagine command.
- `uploadImage(image)`: Upload an image and get an image URL back.
- `getSeed(taskId, callbackURL)`: Get the seed of a generated image.
- `describe(image, callbackURL)`: Writes four example prompts based on an uploaded image.
- `faceswap(targetImageURL, faceImageURL)`: Swap the face on the target image with the face on source image.
- `getResult(taskId)`: Get the final result for a submitted job.

For more detailed information about these methods and their parameters, please refer to the [Midjourney API documentation](https://slashimagine.pro/docs).

## Example

```javascript
const MidjourneyAPI = require('midjourney-api');
const fs = require('fs');

const apiKey = 'your-api-key';
const verbose = true;

const midjourney = new MidjourneyAPI(apiKey, verbose);

(async () => {
  /**********  IMAGINE  ***********/

  // Imagine request
  const req1 = await midjourney.imagine('a red knight riding a blue horse', 'turbo');

  // wait 30 seconds
  await new Promise((resolve) => {
    setTimeout(resolve, 20 * 1000);
  });

  // Get result
  const res1 = await midjourney.getResult(req1.taskId);

  /**********  IMAGINE  ***********/

  /**********  UPSCALE IMAGE #2  ***********/

  // Upscale request
  const res2 = await midjourney.upscale(res1.taskId, 2);

  /**********  UPSCALE IMAGE #2 ***********/

  /**********  VARIATIONS OF IMAGE #3 ***********/

  // Variations request
  const req3 = await midjourney.variations(res1.taskId, 3);

  // wait 30 seconds
  await new Promise((resolve) => {
    setTimeout(resolve, 30 * 1000);
  });

  // Get result
  const res3 = await midjourney.getResult(req3.taskId);

  /**********  VARIATIONS OF IMAGE #3  ***********/

  /**********  GET SEED OF THE FIRST COMMAND  ***********/

  // seed request
  const req4 = await midjourney.getSeed(res1.taskId);

  // wait 5 seconds
  await new Promise((resolve) => {
    setTimeout(resolve, 5 * 1000);
  });

  // Get result
  const res4 = await midjourney.getResult(req4.taskId);


  /**********  GET SEED OF THE FIRST COMMAND ***********/


  /**********  DESCRIBE AN IMAGE  ***********/

  // seed request
  const req6 = await midjourney.describe(
    {  // FILE 1
        file: fs.createReadStream('./images/image2.png'),
        name: 'image2.png'
    }
  );

  // wait 30 seconds
  await new Promise((resolve) => {
    setTimeout(resolve, 30 * 1000);
  });

  // Get result
  const res6 = await midjourney.getResult(req6.resultId);

  /**********  DESCRIBE AN IMAGE  ***********/
})();

```

## License

This project is licensed under the MIT License.

---
_Source: https://npm.io/package/midjourney-api · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
