> For the complete documentation index, see [llms.txt](https://docs.parasail.io/parasail-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.parasail.io/parasail-docs/products/overview-2.md).

# Image Generation

Parasail supports batch image generation and editing for diffusion models such as [OmniGen](https://huggingface.co/Shitao/OmniGen-v1) and [Qwen-Image-Edit](https://huggingface.co/Qwen/Qwen-Image-Edit). Prompts are submitted as JSONL files—one prompt per line—through either the OpenAI-compatible [Batch API](/parasail-docs/api-reference/batch-api.md) or the [Parasail Batch helper library](/parasail-docs/products/quickstart.md), which wraps the OpenAI client.

Input and output images are encoded as raw Base64 (not Data URLs like `data:image/png;base64,...`, just the raw Base64 image data). Batch results are returned as JSONL with Base64-encoded output images. Batch submission files have a **1000 MB** limit; see [Batch file format](/parasail-docs/products/quickstart/file-format.md) for the full limits.

## Minimal example

The quickest way to generate an image is the batch helper library, which builds the JSONL request file and submits it for you:

```python
from openai_batch import Batch

with Batch() as batch:
    batch.add_to_batch(
        model="Shitao/OmniGen-v1",
        prompt="A serene mountain lake at sunrise, photorealistic",
        size="1024x1024",
        response_format="b64_json",
    )
    result, output_path, error_path = batch.submit_wait_download()
```

For editing, pass one or more Base64-encoded input images and reference them in the prompt:

```python
import base64

with open("person.jpg", "rb") as f:
    img = base64.b64encode(f.read()).decode("utf-8")

batch.add_to_batch(
    model="Shitao/OmniGen-v1",
    prompt="A man in a black shirt is reading a book. The man is the right man in <img><|image_1|></img>.",
    size="1024x1024",
    image=[img],
    response_format="b64_json",
)
```

## Supported parameters

| Parameter         | Description                                                                                 |
| ----------------- | ------------------------------------------------------------------------------------------- |
| `model`           | For example `Shitao/OmniGen-v1` or `Qwen/Qwen-Image-Edit`                                   |
| `prompt`          | The prompt to guide generation. Reference input images inline as `<img><\|image_1\|></img>` |
| `size`            | Formatted as `WxH` in pixels, for example `1024x1024`                                       |
| `image`           | A **list** of Base64-encoded JPGs or PNGs (used for editing)                                |
| `response_format` | Currently only `b64_json` is supported                                                      |

## Advanced: process a directory of images

The script below uses the batch helper library to process every image in an input directory and save the generated results to an output directory. The batch library has many additional features for building processing pipelines—see the [Batch quickstart](/parasail-docs/products/quickstart.md), which also shows how to monitor batch jobs in Parasail's UI.

To run it:

```sh
pip3 install openai-batch
PARASAIL_API_KEY=<YOUR-API-KEY> python3 test_omnigen_batch.py
```

<pre class="language-python"><code class="lang-python"><strong>#test_omnigen_batch.py
</strong>
<strong>#pip install openai-batch
</strong><strong>from openai_batch import Batch, providers
</strong>from PIL import Image
import os
import base64
import json
import io
from pathlib import Path


def extract_and_save_images(input_file: str, output_dir: str):
    """Extract base64 encoded images from batch output and save as JPG files."""
    Path(output_dir).mkdir(parents=True, exist_ok=True)
    counter = 1
    with open(input_file, "r", encoding="utf-8") as f:
        for line in f:
            try:
                data = json.loads(line.strip())
                b64_data = data["response"]["body"]["data"][0]["b64_json"]
                image_bytes = base64.b64decode(b64_data)
                image = Image.open(io.BytesIO(image_bytes))
                output_path = os.path.join(output_dir, f"image-{counter}.jpg")
                image.convert("RGB").save(output_path, format="JPEG")
                print(f"Saved {output_path}")
                counter += 1
            except Exception as e:
                print(f"Error processing line {counter}: {e}")
                counter += 1
                continue


# Input and output directories
input_images_dir = Path("omnigen_input_images")
output_images_dir = Path("omnigen_output_images")

# Batch files
output_file = Path("output.jsonl")
error_file = Path("error.jsonl")
submission_file = Path("batch_submission.jsonl")

# Get all image files from input directory
image_extensions = {".jpg", ".jpeg", ".png"}
image_files = [
    f
    for f in input_images_dir.iterdir()
    if f.is_file() and f.suffix.lower() in image_extensions
]

if not image_files:
    print(f"No image files found in {input_images_dir}")
    print(f"Supported extensions: {', '.join(image_extensions)}")
    exit(1)

print(f"Found {len(image_files)} images to process")

# Create a batch with transfusion request
with Batch(
    submission_input_file=submission_file,
    output_file=output_file,
    error_file=error_file,
) as batch_obj:
    # Process each image and add to batch
    for image_path in image_files:
        print(f"Processing: {image_path.name}")

        # Read and encode the image as base64
        with open(image_path, "rb") as img_file:
            image_data = img_file.read()
            base64_image = base64.b64encode(image_data).decode("utf-8")

        # Add transfusion request to the batch
        batch_obj.add_to_batch(
            model="Shitao/OmniGen-v1",
            prompt="A man in a black shirt is reading a book. The man is the right man in &#x3C;img>&#x3C;|image_1|>&#x3C;/img>.",
            size="1024x1024",
            image=[base64_image],
            response_format="b64_json",
        )

    print(f"\nSubmitting batch with {len(image_files)} requests...")

    # Submit, wait for completion, and download results
    result, output_path, error_path = batch_obj.submit_wait_download()

    # Verify the batch completed successfully
    assert result.status == "completed", f"Batch failed with status: {result.status}"

# Verify output file exists
assert output_file.exists(), "Output file not created for transfusion"

# Extract and save generated images
extract_and_save_images(str(output_file), str(output_images_dir))
</code></pre>

## Next steps

* [Batch quickstart](/parasail-docs/products/quickstart.md)—batch helper library fundamentals
* [Batch image understanding](/parasail-docs/products/quickstart.md#batch-image-understanding)—batch image processing reference
* [Batch API reference](/parasail-docs/api-reference/batch-api.md)—OpenAI-compatible API spec
* [Batch file format](/parasail-docs/products/quickstart/file-format.md)—JSONL input format and limits
