Back to Eliza

Image Generation

packages/cloud-frontend/content/api/images.mdx

2.0.17.2 KB
Original Source

import { Callout, Tabs } from "@/docs/components";

Image Generation

<div className="status-badge status-stable">Stable</div>

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

Generate Image

<div className="api-endpoint"> <span className="method-badge method-badge-post">POST</span> <span className="path">/api/v1/generate-image</span> </div>

Create images from text descriptions.

Request

<Tabs items={['cURL', 'JavaScript', 'Python']}> <Tabs.Tab>

bash
curl -X POST "https://elizacloud.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
  }'

</Tabs.Tab> <Tabs.Tab>

javascript
const response = await fetch('https://elizacloud.ai/api/v1/generate-image', {
  method: 'POST',
  headers: {
    'Authorization': 'Bearer YOUR_API_KEY',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    prompt: 'A serene mountain landscape at sunset',
    model: 'google/gemini-2.5-flash-image',
    aspectRatio: '1:1',
    numImages: 1,
  }),
});

const data = await response.json();
console.log(data.images[0].url);

</Tabs.Tab> <Tabs.Tab>

python
import requests

response = requests.post(
    'https://elizacloud.ai/api/v1/generate-image',
    headers={
        'Authorization': 'Bearer YOUR_API_KEY',
        'Content-Type': 'application/json',
    },
    json={
        'prompt': 'A serene mountain landscape at sunset',
        'model': 'google/gemini-2.5-flash-image',
        'aspectRatio': '1:1',
        'numImages': 1,
    }
)

data = response.json()
print(data['images'][0]['url'])

</Tabs.Tab> </Tabs>

Parameters

ParameterTypeRequiredDescription
promptstringDescription 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

json
{
  "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
}
<Callout type="info"> 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. </Callout>

Available Models

Model availability changes with provider catalogs and deployment configuration. Use /api/v1/models, the API Explorer, or the generated OpenAPI reference for the current image model list and defaults.


Image-to-Image Generation

Transform existing images by providing a sourceImage parameter:

javascript
const response = await fetch("https://elizacloud.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:

json
{
  "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:

json
{
  "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

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

Batch Generation

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

bash
curl -X POST "https://elizacloud.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.