PHPackages                             batdan/midjourney-api-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Image &amp; Media](/categories/media)
4. /
5. batdan/midjourney-api-php

ActiveLibrary[Image &amp; Media](/categories/media)

batdan/midjourney-api-php
=========================

Generate images Midjourney (Discord API). URLs in prompt accepted

v2.1.4(2y ago)222.2k↓45%4[1 PRs](https://github.com/batdan/midjourney-api-php/pulls)MITPHPPHP &gt;=7.2.5

Since Jun 25Pushed 2y ago2 watchersCompare

[ Source](https://github.com/batdan/midjourney-api-php)[ Packagist](https://packagist.org/packages/batdan/midjourney-api-php)[ Fund](https://ko-fi.com/danielgomes53123)[ RSS](/packages/batdan-midjourney-api-php/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (26)Used By (0)

Utilize the Discord API to generate images with the Midjourney Bot.
===================================================================

[](#utilize-the-discord-api-to-generate-images-with-the-midjourney-bot)

This PHP library offers a user-friendly interface for creating images with the Midjourney Bot, leveraging the capabilities of the Discord API.

This version has the capability to incorporate example **images via URLs** into the Midjourney prompts, providing full compatibility with both **private and public channels**.

Installation
------------

[](#installation)

You can seamlessly integrate this library into your project using Composer. To do so, execute the following command in your project's root directory:

`composer require batdan/midjourney-api-php`

Usage
-----

[](#usage)

### Fundamental Usage Instructions

[](#fundamental-usage-instructions)

To generate an image with the Midjourney Bot, initiate an instance of the Midjourney class:

```
use batdan\ai\MidjourneyImageCreator;

$discordChannelId = 'YOUR_DISCORD_CHANNEL_ID';
$discordUserToken = 'YOUR_DISCORD_USER_TOKEN';

$midjourney = new MidjourneyImageCreator($discordChannelId, $discordUserToken);

// Example of a prompt: text is separated from tags
$promptText = "aerial view of a giant fish tank shaped like a tower in the middle of new york city, https://depuismonhamac.jardiland.com/wp-content/uploads/2019/06/AdobeStock_196378179.jpeg";
$promptTags = "8k octane render, photorealistic --ar 9:20 --v 5";

/**
 * The imageCreationV2 method is responsible for randomly selecting an image from the 4 options provided by Midjourney.
 * If you want to specify a particular image, you can pass its identifier (ranging from 0 to 3) as the third parameter.
 *
 * Example: $midjourneyImageCreator->imageCreation($promptText, $promptTags, 0);
 *
 * This will generate an image for the given prompt, using the specified image identifier (in this case, 0).
 */
$message = $midjourney->imageCreationV2($promptText, $promptTags);
$imgUrl  = $message->upscaled_photo_url;

echo chr(10) . chr(10);
echo $imgUrl;
echo chr(10) . chr(10);
```

### Constructor

[](#constructor)

- `$discordChannelId`:

    - Substitute this value with the Channel ID where the Midjourney Bot has been installed. The Channel ID can be obtained by right-clicking on the channel and **selecting Copy Channel ID**.
    - Keep in mind that you can invite the Midjourney Bot to your own server to better organize your work. For more information, refer to
- `$discordUserToken`:

    - To retrieve your Discord User Token, you will need to use the Developer Tools in your browser and look into the network data. Here are the steps:

        - Open Discord in your browser (not the app).
        - Open the Developer Tools (you can typically open this by pressing F12 or Ctrl + Shift + I on Windows/Linux or Cmd + Option + I on MacOS).
        - Navigate to the **"Network"** tab.
        - In the filter box, type **"messages"** to narrow down the list of network requests.
        - Send a message in any Discord channel.

            [![](img/send-message.png)](img/send-message.png)
        - Look at the network requests that pop up after sending the message, select the one that has **"messages"** in its name.
        - Within the Headers tab, look for the request header named "Authorization". The value of this header **is your User Token**.

            [![](img/get-user-token.png)](img/get-user-token.png)

    **Important Note:** Keep your User Token strictly confidential. Anyone who has your token can take control of your Discord account. Never share it with anyone and don't publish it online. If you think your token may have been compromised, change your password immediately as this will cause your current token to become invalid.

Optimal Performance: Consider Using the CLI Script
--------------------------------------------------

[](#optimal-performance-consider-using-the-cli-script)

To ensure optimal performance and avoid any potential execution time issues, we recommend utilizing the CLI (Command Line Interface) script for your task. The CLI script provides a streamlined and efficient environment, allowing for faster processing and smoother execution.

Before running the script, please fill in the **Channel ID** and **User Token** in the **example.php** file:
[![](img/credentials.png)](img/credentials.png)

[![](img/cli-php.png)](img/cli-php.png)

The process can take approximately one minute.

Automatically Generated Image:

[![](img/result.png)](img/result.png)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity31

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity49

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

25

Last Release

1033d ago

Major Versions

v1.0.9 → v2.0.02023-06-25

PHP version history (2 changes)v1.0.0PHP ^8.1

v2.0.8PHP &gt;=7.2.5

### Community

Maintainers

![](https://www.gravatar.com/avatar/665b1d34ee9a53822f92198ae5284f6e686025c8cb216f4d3d680dc8398b6e02?d=identicon)[batdan](/maintainers/batdan)

---

Top Contributors

[![batdan](https://avatars.githubusercontent.com/u/12898074?v=4)](https://github.com/batdan "batdan (10 commits)")

---

Tags

phpimage manipulationimage processinggraphicsimage-generationmidjourneyimage-linkimage-creationdynamic-images

### Embed Badge

![Health badge](/badges/batdan-midjourney-api-php/health.svg)

```
[![Health](https://phpackages.com/badges/batdan-midjourney-api-php/health.svg)](https://phpackages.com/packages/batdan-midjourney-api-php)
```

###  Alternatives

[imagine/imagine

Image processing for PHP

4.5k72.4M341](/packages/imagine-imagine)[opentok/opentok

OpenTok is a platform for creating real time streaming video applications, created by TokBox.

1413.0M10](/packages/opentok-opentok)[rokka/imagine-vips

libvips adapter for imagine

43564.1k5](/packages/rokka-imagine-vips)[pixelandtonic/imagine

Image processing for PHP

133.4M3](/packages/pixelandtonic-imagine)[ambroisemaupate/intervention-request

A customizable Intervention Image wrapper to use image simple re-sampling features over urls and a configurable cache.

4242.4k2](/packages/ambroisemaupate-intervention-request)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
