Skip to main content

Basic Generation

Generate an image by providing a model and a text prompt.
import os
from openai import OpenAI

client = OpenAI(
    base_url="https://api.routeway.ai/v1",
    api_key=os.getenv("ROUTEWAY_API_KEY"),
)

response = client.images.generate(
    model="gpt-image-1",
    prompt="A watercolor painting of a mountain lake at dawn",
)

print(response.data[0].url)

Image Sizes

Control the output dimensions with the size parameter.
SizeAspect RatioBest For
1024x10241:1Square images, avatars, icons
1792x102416:9Landscape, banners, headers
1024x17929:16Portrait, mobile wallpapers, stories
response = client.images.generate(
    model="gpt-image-1",
    prompt="A panoramic view of a tropical beach",
    size="1792x1024",
)

Quality Settings

The quality parameter controls the detail level and generation time.
QualityDescription
autoAutomatically selects the best quality for the prompt.
lowFastest generation, lower detail.
mediumBalanced speed and detail.
highMaximum detail, slower generation.
Use auto for most use cases. It provides the best balance without manual tuning.

Generating Multiple Images

Set n to generate multiple images in a single request.
response = client.images.generate(
    model="gpt-image-1",
    prompt="A minimalist logo for a coffee shop",
    n=4,
    size="1024x1024",
)

for i, image in enumerate(response.data):
    print(f"Image {i + 1}: {image.url}")
Generating multiple images multiplies token/credit usage accordingly.

Response Format

Choose between a temporary URL or base64-encoded image data.
FormatUse Case
urlDefault. Returns a short-lived URL to download the image.
b64_jsonReturns the image as a base64-encoded string for direct embedding or saving.
URLs are temporary and expire after a short period. If you need to persist the image, download it immediately or use b64_json.

Saving Images Locally

import base64

response = client.images.generate(
    model="gpt-image-1",
    prompt="A detailed sketch of a cat wearing a top hat",
    response_format="b64_json",
)

image_data = base64.b64decode(response.data[0].b64_json)

with open("output.png", "wb") as f:
    f.write(image_data)

print("Image saved to output.png")

Tips for Better Prompts

Instead of “a dog”, try “a golden retriever sitting in a sunlit meadow, photorealistic, soft bokeh background”. More detail gives the model stronger guidance.
Include style cues like “watercolor”, “3D render”, “pixel art”, “oil painting”, or “studio photography” to steer the aesthetic.
Mention framing details such as “close-up”, “bird’s-eye view”, “centered”, or “rule of thirds” for more intentional compositions.