Midjourney integration for image generation
Midjourney doesn't offer an official REST API—only a Discord interface. However, there are approaches for business automation: an unofficial API proxy, Discord Bot automation, and alternatives of comparable quality.
Unofficial API via Discord automation
import asyncio
import discord
from discord.ext import commands
import httpx
class MidjourneyProxy:
"""
Использует Discord User Token для взаимодействия с Midjourney Bot.
Внимание: нарушает ToS Discord — только для приватных/тестовых серверов.
"""
def __init__(self, discord_token: str, channel_id: int):
self.token = discord_token
self.channel_id = channel_id
self.base_url = "https://discord.com/api/v10"
async def imagine(self, prompt: str) -> str:
"""Отправляем команду /imagine и ждём результат"""
# Отправляем slash-command через API
async with httpx.AsyncClient() as client:
response = await client.post(
f"{self.base_url}/interactions",
headers={"Authorization": self.token},
json={
"type": 2,
"application_id": "936929561302675456", # Midjourney App ID
"channel_id": str(self.channel_id),
"data": {
"id": "938956540159881230",
"name": "imagine",
"options": [{"name": "prompt", "value": prompt}]
}
}
)
# Polling результата (Midjourney занимает 30–120 сек)
return await self.poll_for_result(prompt, timeout=180)
Official alternatives with API
For production, services with a real API are recommended:
# FLUX.1 Pro через Replicate — сравнимое с MJ качество
import replicate
async def generate_flux_pro(prompt: str) -> str:
output = await replicate.async_run(
"black-forest-labs/flux-pro",
input={"prompt": prompt, "aspect_ratio": "1:1", "output_format": "png"}
)
return str(output)
# Ideogram — сильный в тексте на изображениях
async def generate_ideogram(prompt: str, api_key: str) -> bytes:
async with httpx.AsyncClient() as client:
response = await client.post(
"https://api.ideogram.ai/generate",
headers={"Api-Key": api_key},
json={
"image_request": {
"prompt": prompt,
"aspect_ratio": "ASPECT_1_1",
"model": "V_2",
"magic_prompt_option": "AUTO"
}
}
)
return response.json()["data"][0]["url"]
Prompt Strategies for Midjourney
# Художественный стиль
"portrait of {subject}, oil painting style, renaissance lighting, --ar 3:4 --stylize 750"
# Архитектура
"modern minimalist house, aerial view, surrounded by nature, golden hour, --ar 16:9 --v 6"
# Продуктовая съёмка
"luxury watch on marble surface, studio lighting, macro photography, ultra detailed --v 6 --q 2"
# Параметры версии 6:
# --ar ratio - соотношение сторон
# --stylize N - стилизация (0-1000)
# --v 6 - версия модели
# --q 2 - качество (0.25, 0.5, 1, 2)
# --chaos N - случайность (0-100)
Selecting a tool for the task
| Task | Recommendation | Why |
|---|---|---|
| Highly artistic content | Midjourney | Best style |
| Automation / API Integration | FLUX.1 Pro | Official API |
| Text on Images | Ideogram V2 | Best in Class |
| Photorealism | FLUX.1 Dev | Detailing |
| Complete control over style | SDXL + LoRA | Flexibility |
Midjourney is suitable for manual production of high-quality content. For automation and API integrations, use FLUX.1 or DALL-E 3. FLUX/DALL-E API integration times are 1–3 days.







