Skip to main content

Request Body

model
string
default:"dall-e-3"
Model to use (e.g., dall-e-3, flux-pro, midjourney).
prompt
string
required
Text description of the desired image.
n
integer
default:"1"
Number of images to generate (1-4, model dependent).
size
string
default:"1024x1024"
Image size. Options vary by model:
  • DALL-E 3: 1024x1024, 1792x1024, 1024x1792
  • Other models: 512x512, 1024x1024, etc.
quality
string
default:"standard"
Image quality (standard or hd). DALL-E 3 only.
response_format
string
default:"url"
Response format: url or b64_json.
style
string
default:"vivid"
Style for DALL-E 3: vivid or natural.
user
string
A unique identifier for the end-user.

Response

Synchronous Response (DALL-E, Flux Schnell, etc.)

created
integer
Unix timestamp of creation.
data
array
Array of generated images.Each object contains:
  • url (string): URL of the generated image
  • b64_json (string): Base64-encoded image (if requested)
  • revised_prompt (string): The prompt used (DALL-E 3)

Asynchronous Response (Midjourney, Flux Pro, Ideogram, etc.)

Some models require longer processing time and return an async response:
created
integer
Unix timestamp of creation.
task_id
string
Unique task identifier for polling.
status
string
Initial status: pending.
poll_url
string
Relative URL to poll for results (e.g., /v1/images/generations/{task_id}).
data
array
Array with placeholder data. url will be empty until completed.
When you receive status: "pending", use the Get Image Status endpoint to poll for the result.
curl -X POST "https://api.lemondata.cc/v1/images/generations" \
  -H "Authorization: Bearer sk-your-api-key" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "dall-e-3",
    "prompt": "A white cat sitting on a windowsill watching rain",
    "size": "1024x1024",
    "quality": "standard",
    "n": 1
  }'
{
  "created": 1706000000,
  "data": [
    {
      "url": "https://...",
      "revised_prompt": "A fluffy white cat with bright eyes sitting peacefully on a wooden windowsill, watching raindrops stream down the glass window..."
    }
  ]
}

Available Models

ModelTypeFeatures
dall-e-3SyncBest quality, prompt enhancement
dall-e-2SyncFaster, more affordable
flux-proAsyncPhotorealistic, high quality
flux-schnellSyncVery fast
midjourneyAsyncArtistic style
ideogram-v3AsyncBest text rendering
stable-diffusion-3SyncOpen source, customizable
Async models return status: "pending" and require polling. See Get Image Status for how to retrieve results.

Handling Async Responses

For async models, check if the response contains status: "pending":
import requests
import time

def generate_image(prompt, model="midjourney"):
    # Create image request
    response = requests.post(
        "https://api.lemondata.cc/v1/images/generations",
        headers={"Authorization": "Bearer sk-your-api-key"},
        json={"model": model, "prompt": prompt}
    )
    data = response.json()

    # Check if async
    if data.get("status") == "pending":
        task_id = data["task_id"]
        print(f"Async task started: {task_id}")

        # Poll for result
        while True:
            status_resp = requests.get(
                f"https://api.lemondata.cc/v1/images/generations/{task_id}",
                headers={"Authorization": "Bearer sk-your-api-key"}
            )
            status_data = status_resp.json()

            if status_data["status"] == "completed":
                return status_data["data"][0]["url"]
            elif status_data["status"] == "failed":
                raise Exception(status_data.get("error", "Generation failed"))

            time.sleep(3)
    else:
        # Sync response
        return data["data"][0]["url"]

# Usage
url = generate_image("a beautiful sunset over mountains", model="midjourney")
print(f"Generated image: {url}")