Skip to content

Images Generation

The image generation API allows you to create images based on textual descriptions, leveraging models like Qwen-Image.

API Call Parameters

  • prompt: A string describing the desired image, such as "A white cat resting in Rome."
  • n: An integer specifying the number of images to generate. Generating more images increases response time, so it's best to keep this number small for faster performance.
  • model: The identifier for the model used in image generation, e.g., "Qwen-Image."
  • size: The image dimensions as a WIDTHxHEIGHT string, e.g. "1024x1024". Regolo passes size through to the model; which sizes a given model actually honors is model-dependent.
  • aspect_ratio: The desired aspect ratio, e.g. "16:9", "1:1", or "9:16". Like size, it is forwarded to the model. Support is model-dependent — not every model honors non-square ratios, and some accept size or aspect_ratio but not both.

Larger images take longer to generate, so consider using smaller sizes for quicker results.

Tip

If you require larger images, consider using an image upscaler after generation. This can help achieve the desired resolution without increasing the generation time

import regolo
from io import BytesIO
from PIL import Image

# pip install regolo Pillow

regolo.default_image_generation_model = "Qwen-Image"
regolo.default_key = "YOUR_REGOLO_KEY"

img_bytes = regolo.static_image_create(prompt="A Boat in the sea")[0]

image = Image.open(BytesIO(img_bytes))

# Save the Image
output_path = "generated_image.png"
image.save(output_path)
print(f"Image saved to: {output_path}")
import requests
import json
from PIL import Image
import io
import base64

url = 'https://api.regolo.ai/v1/images/generations'
headers = {
    'Authorization': 'Bearer YOUR_REGOLO_KEY',
    'Content-Type': 'application/json'
}

data = {
    "prompt": "A white cat resting in Rome",
    "n": 2,
    "model": "Qwen-Image",
    "size": "1024x1024"
}

response = requests.post(url, headers=headers, data=json.dumps(data))

if response.status_code == 200:
    response_data = response.json()

    for index, item in enumerate(response_data['data']):
        b64_image = item['b64_json']
        image_data = base64.b64decode(b64_image)

        image_stream = io.BytesIO(image_data)
        image = Image.open(image_stream)

        # Save the Image
        output_path = f"generated_image_{index + 1}.png"
        image.save(output_path)
        print(f"Image saved to: {output_path}")
else:
    print("Failed to generate images:", response.status_code, response.text)
curl --request POST \
  --url 'https://api.regolo.ai/v1/images/generations' \
  --header 'Authorization: Bearer YOUR_REGOLO_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "prompt": "A Boat in the sea",
    "n": 2,
    "model": "Qwen-Image",
    "size": "1024x1024"
}' | python3 -c "
import sys
import json
import base64

response = json.load(sys.stdin)
if 'data' in response:
    for index, item in enumerate(response['data']):
        b64_image = item['b64_json']
        image_data = base64.b64decode(b64_image)
        output_path = f'generated_image_{index + 1}.png'
        with open(output_path, 'wb') as f:
            f.write(image_data)
        print(f'Image saved to: {output_path}')
else:
    print('Failed to generate images:', response)
"

Non-square and custom sizes

Some image models accept an aspect_ratio or a custom size instead of the square presets. Both are passed straight to the model — what gets produced depends on the model.

curl --request POST \
  --url 'https://api.regolo.ai/v1/images/generations' \
  --header 'Authorization: Bearer YOUR_REGOLO_KEY' \
  --header 'Content-Type: application/json' \
  --data '{
    "prompt": "A wide cinematic shot of a boat on the sea at sunset",
    "n": 1,
    "model": "Qwen-Image",
    "aspect_ratio": "16:9"
}'

Check the model first

Not every model honors aspect_ratio or arbitrary size values. If a model ignores the parameter it usually falls back to its default square output. Test in the Playground to see what a model actually produces.

For the exhaustive API's endpoints documentation visit docs.api.regolo.ai.