English / 简体中文
Based on the Discord Midjourney API.
Add Midjourney Banned Words Entry issue
Refer to the project integration demo: issue31
If the above process & code is difficult for you to operate, or maintaining a pool of accounts consumes a lot of your energy and cost. Here is a highly integrated and cost effective Midjouney API platform recommendation TTAPI for price and stability.
The TTAPI supports functions related to Midjourney:
- imagine
- U V pan zoom
- describe
- blend
- vary_region and all other advanced features included in Midjourney.
- In addition to this there is support for the Luma API, the Face Swap API, the relatively inexpensive ChatGPT, and the Claude API.
How to start with TTAPI
- Just Sign In With Github, and than you will get 30 quota of free credits (can be used to 10 times imagine endpoint in fast mode for testing).
- For complete docs of TTAPI
sequenceDiagram
participant ThirdServer
participant APIServer
participant DiscordAPI
ThirdServer->>APIServer: Request interface to trigger task
APIServer->>APIServer: Add to task queue
APIServer->>DiscordAPI: Call interface to trigger drawing task
APIServer-->>ThirdServer: Return whether the trigger was successful
DiscordAPI->>DiscordAPI: Trigger Midjourney bot drawing task
DiscordAPI->>DiscordAPI: Monitor MidJourney bot messages
DiscordAPI-->>ThirdServer: Return real-time message monitoring
DiscordAPI-->>APIServer: Clear queue task
- Ensure the program's runtime environment can access Discord
- Have Midjourney and Discord accounts
- Create a Discord channel and add the bot, refer to the tutorial Midjourney|How to Integrate into Your Own Platform
git clone
pip install -r requirements.txt
Rename the file .env.template
to .env
and fill in the parameter values:
USER_TOKEN=User token
BOT_TOKEN=Bot token
GUILD_ID=Server ID
CHANNEL_ID=Channel ID
CALLBACK_URL=Callback URL, default is HTTP POST request, used for receiving midjourney drawing progress and results
# Start the bot listener
python task_bot.py
# Start the HTTP service
python server.py
git pull
# Start the bot listener
python task_bot.py
# Start the HTTP service
python server.py
Fill in the environment variables after -e
in start.sh and start directly:
sh start.sh
Or build the image locally:
# Build the image
sh build.sh
# Start the container
sh start.sh
docker rmi kunyu/midjourney-api:1.0
sh start.sh
API swagger
documentation: http://127.0.0.1:8062/docs
midjourney-api
provides interfaces:
-
/v1/api/trigger/imagine
: Trigger drawing task (image-to-image, add image link before the prompt) -
/v1/api/trigger/upscale
: U -
/v1/api/trigger/variation
: V -
/v1/api/trigger/solo_variation
: Make Variations -
/v1/api/trigger/solo_low_variation
: Vary(Subtle) -
/v1/api/trigger/solo_high_variation
: Vary(Strong) -
/v1/api/trigger/zoomout
: Zoom Out 2x/1.5x -
/v1/api/trigger/expand
: ⬅️ ➡️ ⬆️ ⬇️ -
/v1/api/trigger/reset
: Redraw -
/v1/api/trigger/upload
: Upload image -
/v1/api/trigger/describe
: Generate prompt by uploading image name -
/v1/api/trigger/message
: Send image message, return image link for image-to-image functionality
Text-to-image
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/imagine' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"prompt": "a cute cat"
}'
Image-to-image, must include the image URL
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/imagine' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"prompt": "a cute cat",
"picurl": "https://xxxxxx/xxxxxxxxxxxx.jpg"
}'
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/upscale' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"index": 1,
"msg_id": "xxxxxxxxxx",
"msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
"trigger_id": "xxxxxxxxxx"
}'
index
: Image index, values: 1, 2, 3, 4msg_id
:imagine
callback messageid
field after drawing completionmsg_hash
:imagine
callback messageattachments[0].filename.split("_")[-1].split(".")[0]
after drawing completiontrigger_id
:imagine
callback messagetrigger_id
field after drawing completion
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/variation' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"index": 2,
"msg_id": "xxxxxxxxxx",
"msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
"trigger_id": "xxxxxxxxxx"
}'
Perform "Make Variations" on a single image from upscale
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/solo_variation' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"index": 1,
"msg_id": "xxxxxxxxxx",
"msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
"trigger_id": "xxxxxxxxxx"
}'
index
: Image index, not used here, value: 1msg_id
:upscale
callback messageid
field after drawing completionmsg_hash
:upscale
callback messageattachments[0].filename.split("_")[-1].split(".")[0]
after drawing completiontrigger_id
:upscale
callback messagetrigger_id
field after drawing completion
Perform "Vary(Subtle)" on a single image from upscale
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/solo_low_variation' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"index": 1,
"msg_id": "xxxxxxxxxx",
"msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
"trigger_id": "xxxxxxxxxx"
}'
index
: Image index, not used here, value: 1msg_id
:upscale
callback messageid
field after drawing completionmsg_hash
:upscale
callback messageattachments[0].filename.split("_")[-1].split(".")[0]
after drawing completiontrigger_id
:upscale
callback messagetrigger_id
field after drawing completion
Perform "Vary(Strong)" on a single image from upscale
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/solo_high_variation' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"index": 1,
"msg_id": "xxxxxxxxxx",
"msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
"trigger_id": "xxxxxxxxxx"
}'
index
: Image index, not used here, value: 1msg_id
:upscale
callback messageid
field after drawing completionmsg_hash
:upscale
callback messageattachments[0].filename.split("_")[-1].split(".")[0]
after drawing completiontrigger_id
:upscale
callback messagetrigger_id
field after drawing completion
Perform Zoom Out 2x/1.5x on a single image from upscale
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/zoomout' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"msg_id": "xxxxxxxxxx",
"msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
"zoomout": 50
"trigger_id": "xxxxxxxxxx"
}'
zoomout
: Image enlargement (Outpaint) factor, 2x -> 50, 1.5x -> 75
Perform expansion in a specific direction on a single image from upscale
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/expand' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"msg_id": "xxxxxxxxxx",
"msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
"direction": "up"
"trigger_id": "xxxxxxxxxx"
}'
direction
: Image expansion direction, values: left/right/up/down
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/reset' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"msg_id": "xxxxxxxxxx",
"msg_hash": "xxxxx-xxx-xxxx-xxxx-xxxxxx",
"trigger_id": "xxxxxxxxxx"
}'
- First, upload the image
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/upload' \
-H 'accept: application/json' \
-H 'Content-Type: multipart/form-data' \
-F '[email protected];type=image/jpeg'
- Based on the returned image filename, call describe
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/describe' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"upload_filename": "b56ca21a-5fbe-40b4-89ab-6e0aa732f561/9231228408.jpg",
"trigger_id": "9231228408"
}'
trigger_id
: Use the trigger_id returned by upload firstupload_filename
: Filename returned by upload
Same as describe
, first /v1/api/trigger/upload
to upload the image, then send the message based on the returned filename:
curl -X 'POST' \
'http://127.0.0.1:8062/v1/api/trigger/message' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"upload_filename": "560a1e26-36a2-4d5f-a48d-9dd877642b51/7185811546.jpg"
}'
After sending the image, an image link will be returned.
This link is used in image-to-image, concatenating the prompt in the form ImageURL Prompt
, calling /v1/api/trigger/imagine
.
- imagine
- upscale
- variation
- solo_variation
- solo_low_variation
- solo_high_variation
- zoomout
- expand
- reset
- describe
- Image-to-image (obtain the link of the uploaded image)
- Sensitive word filtering and reporting
- Task queue (in-memory storage, external storage is not preferred, but can add exception handling for persistence)
- tests