How to get Midjourney’s API

Divan Brexov
3 min readOct 19, 2023

--

This how-to shows you how to create a simple automation using the Midjourney /imagine command in an example.

For this task you will need a Discord account with an active Midjourney subscription, the $10 Basic plan will do.

Prerequisites

  1. You need a Discord account.
  2. You must purchase a subscription for your Discord account on the midjourney.com website.

Like most people in the community, we do not recommend buying the Pro Plan and Mega Plan. It’s better to create several Discord accounts and purchase either the Standard or Basic plan for each one.

Accessing Your Account

After purchasing a Midjourney subscription, you need to access your Discord account in a browser (via discord.com) in incognito mode (I will explain why below). Find the Midjourney Bot, open a direct message with it, and try to execute a command, for example:

/imagine nice girl in the red hat

The bot may instruct you to accept the ToS before you can work with it. Do so, and generate your first image!

Getting Channel ID and Token

The image below shows where to find the Channel ID and Token. You will need these two values to add your account to the project.

To find the Channel ID, go into direct messages with the bot and copy the long number marked with “1”:

“2” indicates where you should obtain the Token. To find it, open Developer Tools in your browser, go to the Network tab, and send the bot the /info command. Afterward, among the requests, find “interactions” and click on it. On the left panel, select “Headers” and copy the value of the “Authorization” field. For example, the key may look like this:

MTE0MTkRN4zW_KWYjM1lDkqozMzOMEREyMw.GbvrVR.hI1nZqalc6jg5NmLdRgaJZs2LhYDz

You need to use these two values when adding your account on the dashboard. (This is not an advertisement, it’s just the only thing I found for free)

After adding your account, within 20–40 seconds, if you’ve followed the steps described in the article, your account will be successfully activated in the project.

Now u can create your first /imagine request

For request, you need to provide a valid API key value in the request header, using the following header: api-key: <your api-key>

Inclined font parameters are optional

Imagine

POST: https://api.userapi.ai/midjourney/v2/imagine Request body:

{
"prompt": "nice girl",
"webhook_url": "https://example.com/imagine/webhook-url",
"webhook_type": "progress", // or result
"account_hash": "a7d44910-88a6-4673-acc8-d60ffc3479a6",
"is_disable_prefilter": false
}

Response:

{
"hash": "6794f6ef-866a-4bc3-b0bc-7b28ec010d1b"
}

The is_disable_prefilter parameter is optional and is set to false by default. If set to true, the request will not undergo eligibility analysis for submission to Midjourney. This potential adjustment can prolong the account’s operational duration.

When the webhook_url is provided, task object updates will be sent via the POST method whenever the task status changes.

If the webhook_type is set to progress, webhooks will provide updates on the task’s progress and also notify upon task completion or errors. On the other hand, when webhook_type is set to result, webhooks will be sent solely upon task completion or in case of errors.

So, in just three or a couple of minutes we were able to make our first Midjourney’s API request.

5 likes and I will show you an example of implementation /imagine, /describe, /upscale, /variation, /blend, /info on Python! 😜🙃😉

--

--