Skip to Content

Image Generation

Stable

Generate high-quality images from text prompts using state-of-the-art AI models.

Generate Image

POST/api/v1/generate-image

Create images from text descriptions.

Request

curl -X POST "https://cloud.milady.ai/api/v1/generate-image" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "prompt": "A serene mountain landscape at sunset", "model": "google/gemini-2.5-flash-image", "aspectRatio": "1:1", "numImages": 1 }'

Parameters

ParameterTypeRequiredDescription
promptstring✓Description of the image to generate
modelstringModel to use. Default: google/gemini-2.5-flash-image
aspectRatiostringOutput aspect ratio. Default: 1:1
numImagesintegerNumber of images (1-4). Default: 1
stylePresetstringStyle preset to apply (see below)
sourceImagestringBase64 data URL for image-to-image generation

Available Aspect Ratios

Aspect RatioDescription
1:1Square (default)
16:9Wide landscape
9:16Tall portrait
4:3Standard landscape
3:4Standard portrait
21:9Ultra-wide cinematic
9:21Ultra-tall vertical

Style Presets

PresetDescription
noneNo style modification (default)
photographicRealistic lighting and details
digital-artVibrant colors, modern aesthetics
comic-bookBold lines, dramatic shading
fantasy-artMagical and ethereal elements
analog-filmFilm grain and vintage tones
neon-punkCyberpunk style with neon colors
isometricIsometric perspective
low-polyLow-poly 3D style
origamiPaper-folding style
line-artClean line art with minimal shading
cinematicDramatic lighting and composition
3d-modelHigh-quality 3D rendered appearance

Response

{ "images": [ { "url": "https://your-storage.vercel-storage.com/images/abc123.webp", "text": "Optional text response from the model", "mimeType": "image/webp", "fileSize": 102400 } ], "numImages": 1 }

The url field contains a permanent link to the generated image. The image field (base64) is only included as a fallback if blob storage upload fails.


Available Models

ModelProviderSpeedBest For
google/gemini-2.5-flash-imageGoogleFastGeneral use (default)
google/gemini-3.1-flash-image-previewGoogleFastPreview/testing
google/gemini-3-pro-imageGoogleMediumHigher quality
openai/gpt-5-nanoOpenAIMediumOpenAI image generation
bfl/flux-kontext-maxBFLMediumContext-aware generation

Tip: Start with google/gemini-2.5-flash-image for quick iterations.


Image-to-Image Generation

Transform existing images by providing a sourceImage parameter:

const response = await fetch("https://cloud.milady.ai/api/v1/generate-image", { method: "POST", headers: { Authorization: "Bearer YOUR_API_KEY", "Content-Type": "application/json", }, body: JSON.stringify({ prompt: "Transform this into a watercolor painting", sourceImage: "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAA...", model: "google/gemini-2.5-flash-image", }), });

The sourceImage must be a base64-encoded data URL with the format data:{mimeType};base64,{base64Data}.


Prompt Tips

Be Specific

Good prompts include subject, style, lighting, and composition details:

{ "prompt": "A golden retriever puppy playing in autumn leaves, golden hour lighting, shallow depth of field, professional photography" }

Use Style Presets

Apply consistent styling using the stylePreset parameter:

{ "prompt": "Portrait of a woman in natural lighting", "stylePreset": "photographic", "aspectRatio": "3:4" }

Style Keywords

Enhance your prompts with these style modifiers:

CategoryKeywords
Photographyprofessional photo, DSLR, 35mm film, macro, portrait
Art Stylesoil painting, watercolor, digital art, concept art, anime
Lightinggolden hour, studio lighting, dramatic shadows, soft light
Qualityhighly detailed, 8K, masterpiece, award winning

Error Handling

CodeErrorSolution
400Invalid promptCheck prompt is non-empty string
400Invalid modelUse a supported model from the list above
402Insufficient creditsAdd credits to your account
429Rate limitedWait and retry with exponential backoff
500Generation failedRetry, or try a different model

Example Error Response

{ "error": "Insufficient credits for image generation", "required": 0.02 }

Batch Generation

Generate multiple images in a single request (up to 4):

curl -X POST "https://cloud.milady.ai/api/v1/generate-image" \ -H "Authorization: Bearer YOUR_API_KEY" \ -H "Content-Type: application/json" \ -d '{ "prompt": "Cyberpunk cityscape at night", "model": "google/gemini-2.5-flash-image", "numImages": 4, "aspectRatio": "16:9" }'

Each image in the batch is generated with the style preset applied.