Skip to content

RESOURCES / BLOG

Cloudinary’s New Image Generation API: One API, Multiple AI Models, and Built-in Asset Management

Image

At conference booths, developers often ask whether we support image generation at Cloudinary, given our emphasis on media management. As of now, I can say, “Yes! Yes, we do.” — here’s how!

Cloudinary’s Image Generation API lets developers generate images from text prompts using multiple AI model families, then store the result as a managed Cloudinary asset for delivery, optimization, resizing, and transformation.

In this tutorial, we’ll use Python to call the API, generate an image, and save the final result to Cloudinary.

A Python script that can:

  • Generate an image from a text prompt.
  • Choose a model family like fluxrecraftgpt-imageideogram, or nano-banana.
  • Save generated output as a managed Cloudinary asset.
  • Print the final image URL, public ID, size, and file size.

First, follow the instructions on Cloudinary docs to install the image generation add-on to your account. While you’re in the Cloudinary console, make note of your API key, secret and the cloud name where you want assets to be stored.

Install the Python dependency:

pip install requests

Export your Cloudinary credentials:

export CLOUDINARY_API_KEY="your-api-key"
export CLOUDINARY_API_SECRET="your-api-secret"
export CLOUDINARY_CLOUD_NAME="your-cloud-name"Code language: JavaScript (javascript)

Here’s your script. Save it as generate.py.

Run the script with a prompt:

python3 generate.py "A medieval monk"Code language: JavaScript (javascript)
 A medieval monk
This image was generated with the default Flux model.

The script sends a request to Cloudinary’s Image Generation API:

payload = {
    "prompt": prompt,
    "model": {
        "family": model_family,
        "tier": tier
    },
    "target": {
        "target_type": "managed_asset",
        "public_id": public_id
    }
}
Code language: JavaScript (javascript)

Then it calls the API using HTTP Basic Auth:

resp = requests.post(
    f"{IMAGE_GEN_BASE}/generate/{cloud_name}/text_to_image",
    auth=(
        os.environ["CLOUDINARY_API_KEY"],
        os.environ["CLOUDINARY_API_SECRET"]
    ),
    json=payload,
    timeout=90,
)
Code language: JavaScript (javascript)

This is the fun part. You can pick the image generation model that best suits your use case. For example, I find that nano-banana works well with images that include text.

You can switch model families without changing the rest of your application code:

python3 generate.py \
  "A futuristic Tokyo skyline at sunset" \
  --model flux \
  --tier premium
Code language: JavaScript (javascript)

Supported model families include:

flux
gpt-image
ideogram
recraft
nano-banana
Another monk
This was the same prompt, done with Ideogram model.

That makes it easier to test different visual styles while keeping one integration path.

The important part of the request is this:

"target": {
    "target_type": "managed_asset",
    "public_id": public_id
}
Code language: JavaScript (javascript)

This tells Cloudinary to save the generated image as a managed asset on your account, instead of returning only a temporary output.

After generation, the script prints something like:

Image ready!
Public ID: generated/fox-hiking
URL: https://res.cloudinary.com/...
Size: 1024×1024 px
File size: 840 KB
Code language: PHP (php)

Once the image is in Cloudinary, you can resize it, optimize it, crop it, transform it, and deliver it through Cloudinary’s CDN. Wicked fast and easy!

Generate a new image:

python3 generate.py "Marie de France playing pool"
Code language: JavaScript (javascript)
Marie de France
I love this image! Marie de France was a 12th century author of some famous french literature that I particularly like. I don’t think she ever played pool, though. Also this pool table is awesomely “AI-pilled.”

Use a premium model:

python3 generate.py \
  "A cinematic product photo of a sneaker floating over water" \
  --model flux \
  --tier premium
Code language: JavaScript (javascript)

Most image generation APIs return an output.

Cloudinary’s Image Generation API returns an output that can immediately become part of your media pipeline.

That means developers can generate an image and then use the same platform to:

  • Store it.
  • Transform it.
  • Optimize it.
  • Resize it.
  • Deliver it.
  • Reuse it across applications.

For apps that already manage media with Cloudinary, AI image generation becomes part of the existing workflow instead of a separate one-off process. The pipeline just got way simplified for you!

This Python script is small, but it covers the core production workflow:

  1. Authenticate with Cloudinary.
  2. Send a prompt to the Image Generation API.
  3. Choose a model family and tier.
  4. Save the result as a managed asset.
  5. Return a usable image URL.

If you’re building developer tools, e-commerce workflows, campaign generators, or AI-powered creative apps, this approach gives you both image generation and image delivery in the same pipeline.

Ready to level up your media workflow? Start using Cloudinary for free and build better visual experiences today.

What is Cloudinary’s Image Generation API?
Cloudinary’s Image Generation API lets developers generate AI images from text prompts using multiple leading AI model families—including Flux, GPT-Image, Ideogram, Recraft, and Nano Banana—through a single API. Unlike standalone image generation services, generated images can be saved directly as managed Cloudinary assets for optimization, transformations, storage, and global CDN delivery.
Why save AI-generated images as managed Cloudinary assets?
Saving generated images as managed Cloudinary assets means they’re immediately available throughout your existing media pipeline. Instead of downloading and re-uploading files, you can instantly resize, crop, optimize, compress, apply AI transformations, organize assets, and deliver them through Cloudinary’s global CDN. This streamlines production workflows for e-commerce, marketing, creative automation, and AI-powered applications.
Can I switch between AI models without changing my application code?
Yes. Cloudinary’s Image Generation API uses a consistent request format across supported model families. In most cases, switching from Flux to GPT-Image, Ideogram, Recraft, or Nano Banana only requires changing the model.family parameter while keeping the rest of your application logic the same. This simplifies testing and future-proofs your AI image generation workflow.
Can I optimize and transform AI-generated images after they’re created?
Yes. Once an image is stored as a managed Cloudinary asset, you can use the full suite of Cloudinary image transformations. This includes automatic format and quality optimization, responsive resizing, cropping, background removal, overlays, effects, AI-powered editing, and on-the-fly delivery transformations—all without creating duplicate files. Explore available options in the Cloudinary Image Transformation documentation.
How do I get started with Cloudinary Image Generation?
Start by enabling the Image Generation add-on in your Cloudinary account, generating your API credentials, and following the official setup guide. Once configured, you can send a text prompt to the Image Generation API, choose an AI model family, and save the resulting image directly into your Cloudinary media library for immediate use across your applications.

Start Using Cloudinary

Sign up for our free plan and start creating stunning visual experiences in minutes.

Sign Up for Free