跳转到主要内容
Build an AI image generator using the Midjourney API through Ace Data Cloud.

What you’ll build

A Python application that can:
  • Generate images from text prompts
  • Upscale images to high resolution
  • Create variations of generated images
  • Handle async generation with webhooks

Quick start

import requests
import time

API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.acedata.cloud"

# Generate an image
response = requests.post(
    f"{BASE_URL}/midjourney/imagine",
    headers={"Authorization": f"Bearer {API_KEY}"},
    json={
        "prompt": "A futuristic city at sunset, cyberpunk style --ar 16:9",
        "mode": "fast",
    },
)

result = response.json()
print("Image URL:", result["image_url"])
print("Actions available:", result["actions"])

Upscale an image

After generating, upscale for higher resolution:
# Get the image_id from the generation response
image_id = result["image_id"]

upscale = requests.post(
    f"{BASE_URL}/midjourney/imagine",
    headers={"Authorization": f"Bearer {API_KEY}"},
    json={
        "image_id": image_id,
        "action": "upscale",
        "index": 1,  # Upscale first image (1-4)
    },
)

upscaled = upscale.json()
print("Upscaled URL:", upscaled["image_url"])

Alternative: Use Flux for faster generation

For rapid prototyping, Flux generates images in seconds:
response = requests.post(
    f"{BASE_URL}/flux/images",
    headers={"Authorization": f"Bearer {API_KEY}"},
    json={
        "model": "flux-schnell",
        "prompt": "A serene mountain landscape",
    },
)

Next steps