Skip to main content

Image Generation API

diffusion(text, callback=None)

Create a new text-to-image generation task.
response = client.midjourney.diffusion(
    text="a serene mountain landscape at sunset",
    callback="https://your-domain.com/webhook"  # Optional
)
Parameters:
  • text (str): Text prompt (1-8192 characters)
  • callback (str, optional): Webhook URL
Returns: TaskResponse with job_id and status

variation(job_id, image_no, type, remix_prompt=None, callback=None)

Create variations of a generated image.
response = client.midjourney.variation(
    job_id="original-job-id",
    image_no=0,
    type=1,  # 0=Subtle, 1=Strong
    remix_prompt="add more clouds"
)
Parameters:
  • job_id (str): Original image task ID
  • image_no (int): Image index (0-3)
  • type (int): Variation intensity (0=Subtle, 1=Strong)
  • remix_prompt (str, optional): Additional guidance
  • callback (str, optional): Webhook URL

upscale(job_id, image_no, type, callback=None)

Upscale a generated image.
response = client.midjourney.upscale(
    job_id="original-job-id",
    image_no=0,
    type=1  # 0=Subtle, 1=Creative
)
Parameters:
  • job_id (str): Original image task ID
  • image_no (int): Image index (0-3)
  • type (int): Upscaling type (0=Subtle, 1=Creative)
  • callback (str, optional): Webhook URL

reroll(job_id, callback=None)

Regenerate with the same prompt.
response = client.midjourney.reroll(job_id="original-job-id")

blend(img_urls, aspect_ratio, callback=None)

Blend 2-5 images together.
response = client.midjourney.blend(
    img_urls=[
        "https://example.com/image1.png",
        "https://example.com/image2.png"
    ],
    aspect_ratio="1:1"  # "2:3", "1:1", or "3:2"
)

describe(img_url, callback=None)

Generate text descriptions from an image.
response = client.midjourney.describe(
    img_url="https://example.com/image.png"
)

shorten(prompt, callback=None)

Optimize and shorten a prompt.
response = client.midjourney.shorten(
    prompt="a very detailed and long prompt text..."
)

pan(job_id, image_no, direction, scale, remix_prompt=None, callback=None)

Extend image in a specific direction.
response = client.midjourney.pan(
    job_id="original-job-id",
    image_no=0,
    direction=0,  # 0=UP, 1=DOWN, 2=LEFT, 3=RIGHT
    scale=1.5,    # 1.1-3.0
    remix_prompt="add mountains"
)

outpaint(job_id, image_no, scale, remix_prompt=None, callback=None)

Expand image in all directions.
response = client.midjourney.outpaint(
    job_id="original-job-id",
    image_no=0,
    scale=1.3,  # 1.1-2.0
    remix_prompt="add forest background"
)

inpaint(job_id, image_no, mask, remix_prompt=None, callback=None)

Edit specific regions using a mask.
with open("mask.png", "rb") as f:
    mask_data = f.read()

response = client.midjourney.inpaint(
    job_id="original-job-id",
    image_no=0,
    mask=mask_data,
    remix_prompt="add a rainbow in the sky"
)

remix(job_id, image_no, remix_prompt, mode=None, callback=None)

Transform image with a new prompt.
response = client.midjourney.remix(
    job_id="original-job-id",
    image_no=0,
    remix_prompt="turn into a watercolor painting",
    mode=0  # Optional: 0=Low, 1=High
)

edit(job_id, image_no, canvas, img_pos, remix_prompt, mask=None, callback=None)

Edit with canvas positioning.
from legnext.types import Canvas, CanvasImg, Mask, Polygon

response = client.midjourney.edit(
    job_id="original-job-id",
    image_no=0,
    canvas=Canvas(width=1024, height=1024),
    img_pos=CanvasImg(width=512, height=512, x=256, y=256),
    remix_prompt="change the sky to sunset colors",
    mask=Mask(areas=[
        Polygon(width=1024, height=1024, points=[100, 100, 500, 100, 500, 500, 100, 500])
    ])
)

upload_paint(img_url, canvas, img_pos, remix_prompt, mask, callback=None)

Advanced painting on uploaded images.
from legnext.types import Canvas, CanvasImg, Mask

response = client.midjourney.upload_paint(
    img_url="https://example.com/image.png",
    canvas=Canvas(width=1024, height=1024),
    img_pos=CanvasImg(width=768, height=768, x=128, y=128),
    remix_prompt="add magical effects",
    mask=Mask(url="https://example.com/mask.png")
)

retexture(img_url, remix_prompt, callback=None)

Change textures and surfaces.
response = client.midjourney.retexture(
    img_url="https://example.com/image.png",
    remix_prompt="metallic and shiny surfaces"
)

remove_background(img_url, callback=None)

Remove the background from an image.
response = client.midjourney.remove_background(
    img_url="https://example.com/image.png"
)

enhance(job_id, image_no, callback=None)

Enhance image quality (draft to high-res).
response = client.midjourney.enhance(
    job_id="draft-job-id",
    image_no=0
)

Next Steps