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

FieldTypeRequiredDescription
modelstringYesImage model (e.g., dall-e-3, flux-pro-1.1, stable-diffusion-3.5-large)
promptstringYesText description (max 4000 characters for DALL-E 3)
sizestringNo1024x1024 (default), 1024x1792, 1792x1024, 512x512
nintegerNoNumber of images (1 for DALL-E 3, up to 10 for SD/Flux)
qualitystringNostandard (default) or hd
stylestringNovivid (default) or natural (DALL-E 3 only)
response_formatstringNourl (default) or b64_json
negative_promptstringNoThings to avoid (SD/Flux only)
seedintegerNoReproducible generation (SD/Flux only)
aspect_ratiostringNoFlux/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 image=@photo.png \
  -F mask=@mask.png \
  -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 image=@source.png \
  -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

ModelProviderStrength
dall-e-3OpenAIBest prompt adherence, single image only
dall-e-2OpenAICheap, supports edits and variations
flux-pro-1.1Black Forest LabsHighest fidelity, photorealistic
flux-schnellBlack Forest LabsFastest, good for ideation
stable-diffusion-3.5-largeStability AIOpen weights, customizable
imagen-3GoogleStrong typography and text rendering
ideogram-v2IdeogramBest for posters/logos with text
recraft-v3RecraftVector and design-style outputs

Pricing

Image pricing is per-image, not per-token:

ModelCost 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 seed for 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 -- url responses expire after 1 hour; download or use b64_json for archival

Troubleshooting

SymptomCauseFix
400: prompt too longOver 4000 charsTrim or summarize the prompt
400: content_policy_violationSafety filter triggeredReword or switch to a less-restricted model
Faces look unrealisticGeneric SD weightsUse flux-pro-1.1 or DALL-E 3 HD
Output text is garbledMost models struggle with textUse 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