How to get Midjourney's API

You need to purchase a subscription for your Discord account on the website midjourney.com

Like most people in the community, we do not recommend purchasing the Pro and Mega Plan. It's better to create multiple Discord accounts and purchase a Standard or Basic plan for each.

Access to your account

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

/imagine nice girl in the red hat

Before the first image generation, the bot will ask you to accept the ToS. Be sure to accept these terms before adding your account to the userapi panel.

Getting Channel ID and Token

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

To find out the Channel ID, go to direct with the bot and copy the long number marked with the number “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 /info command to the bot. After that, find “interactions” among the requests and click on it. In the left pane, select “Headers” and copy the value of the “Authorization” field. For example, the key might look like this:

MTE0MTkRN4zW_KWYjM1lDkqozMzOMEREyMw.GbvrVR.hI1nZqalc6jg5NmLdRgaJZs2LhYDz

You need to use these two values ​​when adding your account to control Panel (You need to log in to the site first). (This is not an advertisement, this is just the only thing I found for free)

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

You can now create your first request /imagine

For the request, you need to specify a valid API key value in the request header using the following header: api-key:

/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
}

Answer:

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

Parameter is_disable_prefilter is optional and defaults to false. If set to true, the request will not be subject to eligibility analysis for submission to Midjourney. This potential adjustment may extend the life of the account.

If specified webhook_urlupdates to the task object will be sent via the POST method whenever the task status changes.

If for the parameter webhook_type set to “progress”, webhooks will provide updates on the progress of the task, as well as notify about task completion or errors. On the other hand, if for the parameter webhook_type set to result, webhooks will only be sent after the task is completed or in case of errors.

So, in just a couple of minutes we were able to make our first request to the Midjourney API.

Documentation for all Midjourney commands

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *