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.
Original image copyright © REUTERS/ABC Affiliate WABC
In this tutorial, we'll use Python to call the API, generate an image, and save the final result to Cloudinary.
What you'll build
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
Prerequisites
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"
Here's your script. Save it as 'generate.py'.
Generate your first AI image
Run the script with a prompt:
python3 generate.py "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
}
}
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,
)
Choose an AI image model
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
Supported model families include:
flux
gpt-image
ideogram
recraft
nano-banana
This was the same prompt, done with Ideogram model
That makes it easier to test different visual styles while keeping one integration path.
Save generated images as Cloudinary assets
The important part of the request is this:
"target": {
"target_type": "managed_asset",
"public_id": public_id
}
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
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!
Full usage examples
Generate a new image:
python3 generate.py "Marie de France playing pool"
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
Why this is useful
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!
Final thoughts
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.
| Cloudinary ❤️ developers |
|---|
| Ready to level up your media workflow? Start using Cloudinary for free and build better visual experiences today. |
| 👉 Create your free account |



Top comments (0)