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)
import OpenAI from "openai" ;
const client = new OpenAI ({
baseURL: "https://api.routeway.ai/v1" ,
apiKey: process . env . ROUTEWAY_API_KEY ,
});
const response = await client . images . generate ({
model: "flux-1-schnell" ,
prompt: "A serene Japanese garden at dawn, soft mist, cherry blossoms, photorealistic" ,
size: "1024x1024" ,
n: 1 ,
});
console . log ( response . data [ 0 ]. url );
curl https://api.routeway.ai/v1/images/generations \
-H "Authorization: Bearer $ROUTEWAY_API_KEY " \
-H "Content-Type: application/json" \
-d '{
"model": "flux-1-schnell",
"prompt": "A serene Japanese garden at dawn, soft mist, cherry blossoms, photorealistic",
"size": "1024x1024",
"n": 1
}'
Request parameters
Parameter Type Default Description modelstring required Image model ID (e.g. "flux-1-schnell", "dall-e-3") promptstring required Text description of the image to generate ninteger 1Number of images to generate (1–10) sizestring model default Output resolution, e.g. "1024x1024", "1792x1024" qualitystring model default Provider-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..."
}
]
}
Field Description 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" )
import OpenAI from "openai" ;
import fs from "fs" ;
const client = new OpenAI ({
baseURL: "https://api.routeway.ai/v1" ,
apiKey: process . env . ROUTEWAY_API_KEY ,
});
const response = await client . images . generate ({
model: "flux-1-schnell" ,
prompt: "A futuristic cityscape at night, neon lights, rain-slicked streets" ,
size: "1024x1024" ,
});
const imageUrl = response . data [ 0 ]. url ;
const imageResponse = await fetch ( imageUrl );
const buffer = Buffer . from ( await imageResponse . arrayBuffer ());
fs . writeFileSync ( "output.png" , buffer );
console . log ( "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:
Size Aspect ratio Typical use 1024x1024Square Social media, avatars, thumbnails 1792x1024Landscape Banners, hero images 1024x1792Portrait Mobile wallpapers, posters
Quality Trade-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:
Be specific about style and medium
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"
Describe composition and perspective
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"
Add technical photography terms
Terms like shallow depth of field, 35mm lens, shot on film, bokeh, and golden hour reliably improve photorealistic outputs.
Use negative prompts where supported
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:
Status Cause 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