Image Generation
Generate high-quality images from text prompts using state-of-the-art AI models.
Generate Image
Create images from text descriptions.
Request
cURL
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
| Parameter | Type | Required | Description |
|---|---|---|---|
prompt | string | âś“ | Description of the image to generate |
model | string | Model to use. Default: google/gemini-2.5-flash-image | |
aspectRatio | string | Output aspect ratio. Default: 1:1 | |
numImages | integer | Number of images (1-4). Default: 1 | |
stylePreset | string | Style preset to apply (see below) | |
sourceImage | string | Base64 data URL for image-to-image generation |
Available Aspect Ratios
| Aspect Ratio | Description |
|---|---|
1:1 | Square (default) |
16:9 | Wide landscape |
9:16 | Tall portrait |
4:3 | Standard landscape |
3:4 | Standard portrait |
21:9 | Ultra-wide cinematic |
9:21 | Ultra-tall vertical |
Style Presets
| Preset | Description |
|---|---|
none | No style modification (default) |
photographic | Realistic lighting and details |
digital-art | Vibrant colors, modern aesthetics |
comic-book | Bold lines, dramatic shading |
fantasy-art | Magical and ethereal elements |
analog-film | Film grain and vintage tones |
neon-punk | Cyberpunk style with neon colors |
isometric | Isometric perspective |
low-poly | Low-poly 3D style |
origami | Paper-folding style |
line-art | Clean line art with minimal shading |
cinematic | Dramatic lighting and composition |
3d-model | High-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
| Model | Provider | Speed | Best For |
|---|---|---|---|
google/gemini-2.5-flash-image | Fast | General use (default) | |
google/gemini-3.1-flash-image-preview | Fast | Preview/testing | |
google/gemini-3-pro-image | Medium | Higher quality | |
openai/gpt-5-nano | OpenAI | Medium | OpenAI image generation |
bfl/flux-kontext-max | BFL | Medium | Context-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:
| Category | Keywords |
|---|---|
| Photography | professional photo, DSLR, 35mm film, macro, portrait |
| Art Styles | oil painting, watercolor, digital art, concept art, anime |
| Lighting | golden hour, studio lighting, dramatic shadows, soft light |
| Quality | highly detailed, 8K, masterpiece, award winning |
Error Handling
| Code | Error | Solution |
|---|---|---|
| 400 | Invalid prompt | Check prompt is non-empty string |
| 400 | Invalid model | Use a supported model from the list above |
| 402 | Insufficient credits | Add credits to your account |
| 429 | Rate limited | Wait and retry with exponential backoff |
| 500 | Generation failed | Retry, 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.