Images
Generate, edit, and create variations of images via DALL-E, Stable Diffusion, Flux, Imagen, and Ideogram models.
Overview
The Images API exposes three operations behind a single OpenAI-compatible interface:
- Generation (
/v1/images/generations) -- create an image from a text prompt - Edit (
/v1/images/edits) -- inpaint/extend an existing image - Variations (
/v1/images/variations) -- generate variations of a source image
You can route to DALL-E 3, Stable Diffusion 3, Flux, Imagen 3, Ideogram, or Recraft by changing the model identifier.
Generation
POST https://api.allroutes.ai/v1/images/generations
Request Body
| Field | Type | Required | Description |
|---|---|---|---|
model | string | Yes | Image model (e.g., dall-e-3, flux-pro-1.1, stable-diffusion-3.5-large) |
prompt | string | Yes | Text description (max 4000 characters for DALL-E 3) |
size | string | No | 1024x1024 (default), 1024x1792, 1792x1024, 512x512 |
n | integer | No | Number of images (1 for DALL-E 3, up to 10 for SD/Flux) |
quality | string | No | standard (default) or hd |
style | string | No | vivid (default) or natural (DALL-E 3 only) |
response_format | string | No | url (default) or b64_json |
negative_prompt | string | No | Things to avoid (SD/Flux only) |
seed | integer | No | Reproducible generation (SD/Flux only) |
aspect_ratio | string | No | Flux/SD-style aspect ratio: 1:1, 16:9, 4:3 |
Example
curl https://api.allroutes.ai/v1/images/generations \
-H "Authorization: Bearer allroutes_sk_..." \
-H "Content-Type: application/json" \
-d '{
"model": "dall-e-3",
"prompt": "A cyberpunk city at sunset, photorealistic, ultra detailed",
"size": "1024x1792",
"quality": "hd",
"n": 1
}'
Response
{
"created": 1714000000,
"data": [
{
"url": "https://cdn.allroutes.ai/img/abc123.png",
"revised_prompt": "A cyberpunk metropolis at golden hour, ..."
}
]
}
URLs returned in url mode expire after 1 hour. Use response_format: "b64_json" for permanent storage in your own infrastructure.
Edit (Inpainting / Outpainting)
POST https://api.allroutes.ai/v1/images/edits
Multipart upload with an image and a mask. Transparent pixels in the mask indicate regions to regenerate.
curl https://api.allroutes.ai/v1/images/edits \
-H "Authorization: Bearer allroutes_sk_..." \
-F [email protected] \
-F [email protected] \
-F prompt="A cat sitting where the dog used to be" \
-F model="dall-e-2" \
-F size="1024x1024"
Supported models: dall-e-2, flux-pro-edit, stable-diffusion-inpaint.
Variations
POST https://api.allroutes.ai/v1/images/variations
Generate variations of a source image while preserving subject, composition, and style.
curl https://api.allroutes.ai/v1/images/variations \
-H "Authorization: Bearer allroutes_sk_..." \
-F [email protected] \
-F model="dall-e-2" \
-F n=4 \
-F size="1024x1024"
Currently supported: dall-e-2, stable-diffusion-3-variation.
SDK Examples
Python
# Generation
result = client.images.generate(
model="dall-e-3",
prompt="A cyberpunk city at sunset, photorealistic",
size="1024x1792",
quality="hd",
)
url = result.data[0].url
print(url)
# Edit
with open("photo.png", "rb") as img, open("mask.png", "rb") as mask:
edit = client.images.edit(
model="dall-e-2",
image=img,
mask=mask,
prompt="Replace the dog with a cat",
size="1024x1024",
)
Node.js
const result = await client.images.generate({
model: "dall-e-3",
prompt: "A cyberpunk city at sunset, photorealistic",
size: "1024x1792",
quality: "hd",
});
console.log(result.data[0].url);
Supported Models
| Model | Provider | Strength |
|---|---|---|
dall-e-3 | OpenAI | Best prompt adherence, single image only |
dall-e-2 | OpenAI | Cheap, supports edits and variations |
flux-pro-1.1 | Black Forest Labs | Highest fidelity, photorealistic |
flux-schnell | Black Forest Labs | Fastest, good for ideation |
stable-diffusion-3.5-large | Stability AI | Open weights, customizable |
imagen-3 | Strong typography and text rendering | |
ideogram-v2 | Ideogram | Best for posters/logos with text |
recraft-v3 | Recraft | Vector and design-style outputs |
Pricing
Image pricing is per-image, not per-token:
| Model | Cost per image (1024x1024 standard) |
|---|---|
dall-e-3 | $0.040 |
dall-e-3 (HD) | $0.080 |
dall-e-2 | $0.020 |
flux-pro-1.1 | $0.040 |
flux-schnell | $0.003 |
stable-diffusion-3.5-large | $0.065 |
imagen-3 | $0.040 |
See Models for live pricing.
Best Practices
- Use
revised_prompt-- DALL-E 3 rewrites prompts for safety; the field reveals what was actually used so you can iterate - Set
seedfor SD/Flux -- reproducibility helps with prompt iteration and A/B comparisons - Pick by strength -- DALL-E 3 for prompt adherence; Flux Pro for photorealism; Ideogram for text-in-image
- Cache by prompt -- the gateway's exact-match cache covers identical (prompt, model, size) requests, saving the per-image cost on retries
- Download promptly --
urlresponses expire after 1 hour; download or useb64_jsonfor archival
Troubleshooting
| Symptom | Cause | Fix |
|---|---|---|
400: prompt too long | Over 4000 chars | Trim or summarize the prompt |
400: content_policy_violation | Safety filter triggered | Reword or switch to a less-restricted model |
| Faces look unrealistic | Generic SD weights | Use flux-pro-1.1 or DALL-E 3 HD |
| Output text is garbled | Most models struggle with text | Use imagen-3 or ideogram-v2 |
See Also
- Files API -- store and reuse generated images
- Models API -- live pricing and capability lookups
- Chat Completions -- multimodal chat with
modalities: ["text", "image"] - Caching -- cache identical prompts to skip regeneration