> ## Documentation Index
> Fetch the complete documentation index at: https://docs.legnext.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Image Generation

> Image generation API reference

## diffusion(text, callback=None)

Create a new text-to-image generation task.

```python theme={null}
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.

```python theme={null}
response = client.midjourney.variation(
    job_id="original-job-id",
    image_no=0,
    type=1,  # 0=Subtle, 1=Strong
    remix_prompt="add more clouds",
    callback="https://your-domain.com/webhook"  # Optional
)
```

**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.

```python theme={null}
response = client.midjourney.upscale(
    job_id="original-job-id",
    image_no=0,
    type=1,  # 0=Subtle, 1=Creative
    callback="https://your-domain.com/webhook"  # Optional
)
```

**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.

```python theme={null}
response = client.midjourney.reroll(
    job_id="original-job-id",
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `job_id` (str): Original image task ID
* `callback` (str, optional): Webhook URL

***

## blend(img\_urls, aspect\_ratio, callback=None)

Blend 2-5 images together.

```python theme={null}
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"
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `img_urls` (list): List of 2-5 image URLs
* `aspect_ratio` (str): Image ratio ("2:3", "1:1", or "3:2")
* `callback` (str, optional): Webhook URL

***

## describe(img\_url, callback=None)

Generate text descriptions from an image.

```python theme={null}
response = client.midjourney.describe(
    img_url="https://example.com/image.png",
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `img_url` (str): URL of image to describe
* `callback` (str, optional): Webhook URL

***

## shorten(prompt, callback=None)

Optimize and shorten a prompt.

```python theme={null}
response = client.midjourney.shorten(
    prompt="a very detailed and long prompt text...",
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `prompt` (str): Prompt text to optimize
* `callback` (str, optional): Webhook URL

***

## pan(job\_id, image\_no, direction, scale, remix\_prompt=None, callback=None)

Extend image in a specific direction.

```python theme={null}
response = client.midjourney.pan(
    job_id="original-job-id",
    image_no=0,
    direction=0,  # 0=Down, 1=Right, 2=Up, 3=Left
    scale=1.5,    # 1.1-3.0
    remix_prompt="add mountains",
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `job_id` (str): Original image task ID
* `image_no` (int): Image index (0-3)
* `direction` (int): Direction to pan (0=Down, 1=Right, 2=Up, 3=Left)
* `scale` (float): Expansion scale (1.1-3.0)
* `remix_prompt` (str, optional): Additional guidance
* `callback` (str, optional): Webhook URL

***

## outpaint(job\_id, image\_no, scale, remix\_prompt=None, callback=None)

Expand image in all directions.

```python theme={null}
response = client.midjourney.outpaint(
    job_id="original-job-id",
    image_no=0,
    scale=1.3,  # 1.1-2.0
    remix_prompt="add forest background",
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `job_id` (str): Original image task ID
* `image_no` (int): Image index (0-3)
* `scale` (float): Expansion scale (1.1-2.0)
* `remix_prompt` (str, optional): Additional guidance
* `callback` (str, optional): Webhook URL

***

## inpaint(job\_id, image\_no, mask, remix\_prompt=None, callback=None)

Edit specific regions using a mask.

```python theme={null}
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",
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `job_id` (str): Original image task ID
* `image_no` (int): Image index (0-3)
* `mask` (bytes): Binary mask data (PNG format)
* `remix_prompt` (str, optional): Description of edits
* `callback` (str, optional): Webhook URL

***

## remix(job\_id, image\_no, remix\_prompt, mode=None, callback=None)

Transform image with a new prompt.

```python theme={null}
response = client.midjourney.remix(
    job_id="original-job-id",
    image_no=0,
    remix_prompt="turn into a watercolor painting",
    mode=0,  # 0=Strong, 1=Subtle
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `job_id` (str): Original image task ID
* `image_no` (int): Image index (0-3)
* `remix_prompt` (str): New prompt for transformation
* `mode` (int, optional): Remix strength (0=Strong, 1=Subtle)
* `callback` (str, optional): Webhook URL

***

## edit(job\_id, image\_no, canvas, img\_pos, remix\_prompt, mask=None, callback=None)

Edit with canvas positioning.

```python theme={null}
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])
    ]),
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `job_id` (str): Original image task ID
* `image_no` (int): Image index (0-3)
* `canvas` (Canvas): Canvas dimensions (width, height)
* `img_pos` (CanvasImg): Image positioning on canvas
* `remix_prompt` (str): Description of edits
* `mask` (Mask, optional): Mask with polygon areas
* `callback` (str, optional): Webhook URL

***

## upload\_paint(img\_url, canvas, img\_pos, remix\_prompt, mask, callback=None)

Advanced painting on uploaded images.

```python theme={null}
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"),
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `img_url` (str): URL of image to paint on
* `canvas` (Canvas): Canvas dimensions (width, height)
* `img_pos` (CanvasImg): Image positioning on canvas
* `remix_prompt` (str): Description of effects
* `mask` (Mask): Mask with URL
* `callback` (str, optional): Webhook URL

***

## retexture(img\_url, remix\_prompt, callback=None)

Change textures and surfaces.

```python theme={null}
response = client.midjourney.retexture(
    img_url="https://example.com/image.png",
    remix_prompt="metallic and shiny surfaces",
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `img_url` (str): URL of image to retexture
* `remix_prompt` (str): Texture description
* `callback` (str, optional): Webhook URL

***

## remove\_background(img\_url, callback=None)

Remove the background from an image.

```python theme={null}
response = client.midjourney.remove_background(
    img_url="https://example.com/image.png",
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `img_url` (str): URL of image to process
* `callback` (str, optional): Webhook URL

***

## enhance(job\_id, image\_no, callback=None)

Enhance image quality (draft to high-res).

```python theme={null}
response = client.midjourney.enhance(
    job_id="draft-job-id",
    image_no=0,
    callback="https://your-domain.com/webhook"  # Optional
)
```

**Parameters:**

* `job_id` (str): Original image task ID
* `image_no` (int): Image index (0-3)
* `callback` (str, optional): Webhook URL

***

## Next Steps

* [Video Generation](/sdk/python/video-generation)
* [Task Management](/sdk/python/task-management)
