Welcome aboard the unofficial Midjourney API 🎈🚀. A Python wrapper around the midjourney software to generate AI-based images.
To get started, follow the steps below to run it on your machine:
-
Clone the repository:
git clone https://github.com/yachty66/unofficial_midjourney_python_api.git
-
Install the required packages from
requirements.txt
. -
If your folder structure resembles the one shown below and you wish to use the API in a file named
main.py
:project_directory │ main.py │ └───unofficial_midjourney_python_api │ midjourney_api.py
Then, you can import the API in
main.py
as follows:from unofficial_midjourney_python_api.midjourney_api import MidjourneyApi
-
If you haven't subscribed to midjourney yet, you should do so now.
-
With the same Discord account you used for your midjourney subscription, create a new server (name isn't crucial) and add the midjourney bot from midjourney to this server.
-
Next, you need to gather specific information to call the API appropriately - prompt, application_id, guild_id, channel_id, version, id, and authorization.
-
Navigate to your discord server, open your developer console (on mac, you can use fn+f12), and open the network tab.
-
Activate the midjourney bot with the slash command
/imagine
followed by an arbitrary prompt, then click on theinteractions
option. -
Firstly, visit the
Headers
tab and note down yourAuthorization
key. Then, navigate to thePayload
window and save the application_id, guild_id, channel_id, version, id, and authorization values from the JSON. -
In your project root, create a new folder named
images
. Any image created by the API will be saved here. -
Invoke the API as follows:
midjourney = MidjourneyApi(prompt="prompt", application_id="application_id", guild_id="guild_id", channel_id="channel_id", version="version", id="id", authorization="authorization")
Wait for about 1-2 minutes, and you should find your generated image within the images
folder.
Have you created an exciting project using the API? DM me the details at Twitter!
Happy journeying with Midjourney API!