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
flux,recraft,gpt-image,ideogram, ornano-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)
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
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)

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:
- Authenticate with Cloudinary.
- Send a prompt to the Image Generation API.
- Choose a model family and tier.
- Save the result as a managed asset.
- 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?
Why save AI-generated images as managed Cloudinary assets?
Can I switch between AI models without changing my application code?
model.family parameter while keeping the rest of your application logic the same. This simplifies testing and future-proofs your AI image generation workflow.

