Skip to main content
The /v1/images/generations endpoint takes a text prompt and returns one or more images. It is compatible with the OpenAI images.generate() SDK method — only the base URL and key need to change.

Basic example

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="flux-1-schnell",
    prompt="A serene Japanese garden at dawn, soft mist, cherry blossoms, photorealistic",
    size="1024x1024",
    n=1,
)

print(response.data[0].url)

Request parameters

ParameterTypeDefaultDescription
modelstringrequiredImage model ID (e.g. "flux-1-schnell", "dall-e-3")
promptstringrequiredText description of the image to generate
ninteger1Number of images to generate (1–10)
sizestringmodel defaultOutput resolution, e.g. "1024x1024", "1792x1024"
qualitystringmodel defaultProvider-specific preset, e.g. "standard", "hd"
response_formatstring"url""url" or "b64_json"

Response object

{
  "created": 1749052800,
  "data": [
    {
      "url": "https://cdn.routeway.ai/images/abc123.png",
      "revised_prompt": "A serene Japanese garden at dawn..."
    }
  ]
}
FieldDescription
data[].urlTemporary URL to the generated image (expires in 1 hour)
data[].b64_jsonBase64 PNG data, present when response_format: "b64_json"
data[].revised_promptThe prompt as interpreted by the model, if the model revised it

Saving images locally

URLs expire after 1 hour. Download the image immediately if you need to keep it.
import os
import requests
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="flux-1-schnell",
    prompt="A futuristic cityscape at night, neon lights, rain-slicked streets",
    size="1024x1024",
)

image_url = response.data[0].url
image_bytes = requests.get(image_url).content

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

print("Saved to output.png")
Alternatively, request response_format: "b64_json" to receive the image bytes directly in the API response — no second HTTP request needed.
import base64

response = client.images.generate(
    model="flux-1-schnell",
    prompt="Abstract watercolour landscape",
    response_format="b64_json",
)

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

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

Generating multiple images

Set n to receive several variations in a single call. Each item in data is an independent generation.
response = client.images.generate(
    model="flux-1-schnell",
    prompt="A cosy mountain cabin in winter, warm light from the windows",
    size="1024x1024",
    n=4,
)

for i, image in enumerate(response.data):
    print(f"Image {i + 1}: {image.url}")

Choosing size and quality

Available sizes and quality presets vary by model. As a general guide:
SizeAspect ratioTypical use
1024x1024SquareSocial media, avatars, thumbnails
1792x1024LandscapeBanners, hero images
1024x1792PortraitMobile wallpapers, posters
QualityTrade-off
standardFaster, lower cost, slightly less detail
hdSlower, higher cost, finer details
Use flux-1-schnell for iteration and prototyping — it generates in seconds. Switch to flux-1-dev or dall-e-3 when quality matters for production output.

Writing effective prompts

Image models are sensitive to how prompts are written. A few techniques that consistently improve results:
Vague prompts produce generic results. Name a style, medium, or artist reference to anchor the output.
# Vague
"A forest"

# Specific
"A dense pine forest at dusk, oil painting, dramatic lighting, muted earth tones"
Tell the model where to place things and from what angle.
"Close-up portrait of an elderly sailor, weathered face, looking off-camera,
shallow depth of field, golden hour light"
Terms like shallow depth of field, 35mm lens, shot on film, bokeh, and golden hour reliably improve photorealistic outputs.
Some models (like FLUX) accept a negative_prompt parameter to exclude unwanted elements.
{
  "prompt": "A clean minimal product photo of a white ceramic mug",
  "negative_prompt": "blurry, watermark, text, cluttered background, low quality"
}

Error handling

from openai import BadRequestError

try:
    response = client.images.generate(
        model="flux-1-schnell",
        prompt="...",
    )
    print(response.data[0].url)
except BadRequestError as e:
    # Prompt was rejected (content policy, invalid parameters, etc.)
    print(f"Request error: {e.message}")
except Exception as e:
    print(f"Unexpected error: {e}")
Common errors:
StatusCause
400Invalid parameters or prompt rejected by content policy
401Missing or invalid API key
429Rate limit or insufficient balance
500Upstream model error — retry with exponential backoff