Automate AI Image Generation with Python, 85 Designs

Learn how to automate AI image generation with Python: use GPT-4o prompts and DALL-E 3 images to produce 85 designs for ~$14 total. Step-by-step, cost-tested.

Spread the love
Bikers rights gif via giphy
"bikers rights" portlandia gif via giphy

TL;DR

You can automate AI image generation with Python by using GPT-4o to write detailed prompts and sending them directly to DALL–E 3 for the final images—all in one looped script.

The run came out to roughly $0.16 per finished design, with most of the spend coming from DALL–E 3 image generation and a smaller portion from GPT-4o prompt generation.

You don’t need to be a developer, but you do need comfort with installing Python, running pip, managing an API key, and executing a script from the command line.

The script can embed the full prompt in the filename, which makes it easy to search, organize, and recreate designs later without guessing what you typed.

I wrote a simple Python script that auto-generates AI artwork for a print-on-demand store, and honestly, I’m kind of obsessed with it. 🤙 The whole thing cranked out 85 unique designs for roughly $14 in API costs. No design degree, no fancy software subscriptions, just a 187-line script connecting two OpenAI models together. If you’ve been manually generating AI images one by one for your e-commerce store, clicking, saving, renaming, repeat, this is gonna feel like going from a bicycle to a rocketship. 💪

https://www.youtube.com/watch?v=

Discover how to automate design creation for your POD store!

The Problem With Doing AI Art One at a Time

So I’m thinking of starting a print on demand store and I need some designs for the merchandise. And I was going to do them through using AI one by one by one, but that gets old fast.

Eye-catching youtube thumbnail about ai design generation
Discover how to automate design creation for your pod store!

If you’ve spent any time in ChatGPT or Midjourney generating images manually, you know the drill. Type a prompt. Wait. Download. Rename the file to something useful. Open a new chat. Do it again. And again. It’s death by a thousand clicks, and the worst part is that most of the creative value is in deciding what to make, not in the repetitive mechanical steps of actually making it.

The fix is pretty obvious once you think about it: why don’t I just write a script and have it completely create the images for me and save them? That’s exactly what I did. And it works stupidly well.

How the Script Actually Works (The Two-Brain Approach)

The script is only 187 lines of Python. That’s it. And the core logic is surprisingly straightforward, it uses two different OpenAI models that talk to each other.

Info icon.

How the two models work together

GPT-4o acts as your creative director—it writes the detailed image prompts. DALL–E 3 acts as your artist—it generates the actual images from those prompts. Your script is just the middleman connecting them.

Here’s the flow:

Step 1: GPT-4o generates the prompt. The script tells GPT-4o that it’s a graphic designer and asks it to create a detailed, specific image prompt based on whatever theme or niche you’re going for. Skateboard designs, motivational posters, dog portraits, whatever your store needs. GPT-4o is great at this because it understands composition, color theory, and art direction in a way that produces genuinely good prompts, often better than what most of us would write by hand.

Step 2: DALL-E 3 generates the image. That prompt gets passed straight to the DALL-E 3 API, which creates a 1024×1024 image (or you can go landscape/portrait at 1792×1024). The image comes back as data, and the script saves it as a PNG.

Step 3: Smart file naming. This is the part I’m most proud of, honestly. The script saves each image into a designated folder and names it with the design theme, a sequential number, and the full prompt text. So you end up with files like skateboard_78_retro-neon-kickflip-over-sunset.png. You can always know what the prompt was that created this in case you want to recreate it.

Then it loops. Over and over and over. You walk away, make coffee, come back to a folder full of designs.

The Actual Code (Simplified)

If you don’t know any Python, it’s pretty actually easy, you just install it and copy paste. There’s some more to it, but because of AI, you really don’t need to know how to code anything anymore.

That said, I want to be honest: “you don’t need to know how to code” is a slight exaggeration. You don’t need to be a software engineer. But you do need to be comfortable enough to install Python, run pip install openai in a terminal, and paste in an API key. If you’ve ever installed a WordPress plugin or edited a Shopify theme file, you can handle this.

Here’s a simplified version of the core logic, based on patterns from the OpenAI Images API documentation:

from openai import OpenAI import os, base64 from pathlib import Path client = OpenAI(api_key=os.getenv('OPENAI_API_KEY')) def generate_prompt(theme):     response = client.chat.completions.create(         model="gpt-4o",         messages=[             {"role": "system", "content": "You are a graphic designer..."},             {"role": "user", "content": f"Create an image prompt for: {theme}"}         ]     )     return response.choices[0].message.content def generate_image(prompt):     response = client.images.generate(         model="dall-e-3",         prompt=prompt,         size="1024x1024",         quality="standard",         n=1     )     return response.data[0].url # Loop through as many as you want for i in range(85):     prompt = generate_prompt("skateboard artwork")     image_url = generate_image(prompt)     # ... download and save with descriptive filename

That’s the skeleton. The real script has error handling, file-saving logic, and the smart naming convention, but this is the engine. Two API calls per image, running in a loop.

Warning callout icon.

Protect your API key

Never hard-code your OpenAI API key directly into your script or share it publicly. Use environment variables (like os.getenv('OPENAI_API_KEY')) to keep it secure. If someone gets your key, they can run up charges on your account. This isn’t theoretical, it happens all the time.

What It Actually Costs (Real Numbers)

This is the part everyone wants to know, and I’ve got real numbers because I literally just ran this.

I’ve generated about 85 images and that’s cost me, let’s see, probably 12 bucks. $14. It’s $8.58 in images and then there’s an additional $2 in API calls for the text model, GPT-4o.

Cost ComponentModelAmount
Image GenerationDALL-E 3~$8.58
Prompt GenerationGPT-4o~$2.00
Misc. API overhead~$3.42
Total for 85 images~$14.00
Real cost breakdown from generating 85 print-on-demand designs via the OpenAI API.

That works out to roughly $0.16 per finished design. Sixteen cents. For a unique, AI-generated piece of artwork with a custom prompt tailored to your niche. Compare that to hiring a freelance designer on Fiverr where even a cheap one runs $5-10 per design. At this cost, you could generate 500 designs for under $100 and just cherry-pick the best ones.

Do you ever feel overwhelmed by the need for endless designs; wonder if there's a shortcut out there; or do you just keep struggling on your own? 😅
Do you ever feel overwhelmed by the need for endless designs; wonder if there’s a shortcut out there; or do you just keep struggling on your own? 😅

Leave a Comment

Frequently asked questions (FAQ)

LiaisonLabs is your local partner for SEO & digital marketing services in Mount Vernon, Washington. Here are some answers to the most frequently asked questions about our SEO services.

SEO (Search Engine Optimization) is the process of improving your website's visibility in search engines like Google. When potential customers in Mount Vernon or Skagit County search for your products or services, SEO helps your business appear at the top of search results. This drives more qualified traffic to your website—people who are actively looking for what you offer. For local businesses, effective SEO means more phone calls, more foot traffic, and more revenue without paying for every click like traditional advertising.

A local SEO partner understands the unique market dynamics of Skagit Valley and the Pacific Northwest. We know the seasonal patterns that affect local businesses, from tulip festival tourism to agricultural cycles. Local expertise means we understand which keywords your neighbors are searching, which directories matter for your industry, and how to position your business against local competitors. Plus, we're available for in-person meetings and truly invested in the success of our Mount Vernon business community.

SEO is a long-term investment, and most businesses begin seeing meaningful results within 3 to 6 months. Some quick wins—like optimizing your Google Business Profile or fixing technical issues—can show improvements within weeks. However, building sustainable rankings that drive consistent traffic takes time. The good news? Unlike paid advertising that stops the moment you stop paying, SEO results compound over time. The work we do today continues delivering value for months and years to come.

SEO pricing varies based on your goals, competition, and current website health. Local SEO packages for small businesses typically range from $500 to $2,500 per month, while more comprehensive campaigns for competitive industries may require a larger investment. We offer customized proposals based on a thorough audit of your website and competitive landscape. During your free consultation, we'll discuss your budget and create a strategy that delivers measurable ROI—because effective SEO should pay for itself through increased revenue.

Both aim to improve search visibility, but the focus differs significantly. Local SEO targets customers in a specific geographic area—like Mount Vernon, Burlington, Anacortes, or greater Skagit County. It emphasizes Google Business Profile optimization, local citations, reviews, and location-based keywords. Traditional SEO focuses on broader, often national rankings and prioritizes content marketing, backlink building, and technical optimization. Most Mount Vernon businesses benefit from a local-first strategy, though many of our clients combine both approaches to capture customers at every stage of their search journey.

Absolutely! SEO and paid advertising work best as complementary strategies. Google Ads deliver immediate visibility and are great for testing keywords and driving quick traffic. SEO builds sustainable, long-term visibility that doesn't require ongoing ad spend. Together, they create a powerful combination—ads capture immediate demand while SEO builds your organic presence over time. Many of our Mount Vernon clients find that strong SEO actually improves their ad performance by increasing Quality Scores and reducing cost-per-click, ultimately lowering their total marketing costs while increasing results.