- How to generate dozens of AI images overnight without sitting at your computer: the difference between ChatGPT chat and the OpenAI API, a looping script, and Batch API that processes images even when your computer is off.
You cannot give the regular ChatGPT chat window a single instruction and wake up to 50 finished images. The chat interface generates one image per message and waits for your response before continuing. The approach that actually works is bypassing the chat and going directly to the OpenAI API, with a short script running in a loop on an open computer, or with the Batch API that processes everything in the cloud even when your computer is completely off.
This guide covers both approaches, including the code to run them, current pricing, and which image model fits each one.
In short
| Question | Short answer |
|---|---|
| Why isn't the chat enough? | It generates one image per message and waits for your next response |
| What does work? | Going directly to the OpenAI API, not the chat window |
| Method 1 | A Python script running in a loop, the computer must stay on |
| Method 2 | Batch API: upload a request file, OpenAI processes it in the cloud within up to 24 hours, at half the price |
| Stable model for Batch | gpt-image-2 |
| Fast model for scripts | gpt-image-2.5-flare, but it does not support the Batch API |
| Image output price (gpt-image-2) | $30 per million tokens |
Why you can't just tell the chat "make 50 images overnight"
ChatGPT in its chat form is a conversational tool: it responds to a message and waits for the next one. There is no mechanism that reads a list of 50 descriptions and runs through them one by one without you present, and even if you ask it to "keep going on its own," it does not actually run in the background once the window is closed.
The API is a different story. It is the programmatic entry point to the same image models that power ChatGPT, without the chat interface wrapped around them. Each API call is a single request, and you can chain dozens or hundreds of such requests in a script, or submit them all at once through a path called the Batch API. This is exactly how you connected Codex to a Shopify store: not through chat, but through programmatic access.
Two ways to generate images without sitting at your computer
| Method | Computer must stay on? | Cost | Time to results | Recommended model |
|---|---|---|---|---|
| Script in a loop | Yes | Standard price | Seconds per image | gpt-image-2.5-flare |
| Batch API | No | 50% discount | Up to 24 hours, usually faster | gpt-image-2 |
Both approaches require an API key from an OpenAI developer account, not a regular ChatGPT Plus subscription. Billing is usage-based, not a fixed monthly subscription.
Method 1: A script running in a loop, with the computer genuinely staying on
This is the approach closest to what you described: start the script before bed and let it work through the night. It requires the computer to stay on and connected to the internet until the run finishes.
- Open a developer account at platform.openai.com and generate an API key.
- Install the official Python library:
pip install openai. - Prepare a text file with 50 different descriptions, one per line.
- Write a script that iterates over the list in a loop, saves each image as a file, and waits a few seconds between requests.
- Run it before bed and check the images folder in the morning.
from openai import OpenAI
import base64, time
client = OpenAI()
with open("prompts.txt", encoding="utf-8") as f:
prompts = [line.strip() for line in f if line.strip()]
for i, prompt in enumerate(prompts):
try:
result = client.images.generate(
model="gpt-image-2.5-flare",
prompt=prompt,
size="1024x1024",
quality="high",
)
image_bytes = base64.b64decode(result.data[0].b64_json)
with open(f"image_{i+1:03}.png", "wb") as out:
out.write(image_bytes)
print(f"Saved image {i+1} of {len(prompts)}")
except Exception as e:
print(f"Image {i+1} failed: {e}")
time.sleep(3)
The try/except here is not decorative: if one prompt violates the content policy and comes back as an error, the remaining 49 images will continue generating instead of the entire run stopping.
Request rate is capped based on your account tier. According to the gpt-image-2.5-flare model documentation (checked September 25, 2026), the lowest tier is limited to 5 images per minute, while higher tiers go up to 250 images per minute. A new account running a script that moves too fast will simply hit rate-limit errors in the middle of the night.
Method 2: Batch API, which keeps running even when the computer is off
Definition: The Batch API is an asynchronous path in the OpenAI API. You upload a single file with up to 50,000 requests, OpenAI processes all of them within up to 24 hours, and you download the results when they are ready, at a 50 percent discount off the standard price.
This is the most precise answer to the question "generate images while I sleep": not only do you not need to sit at your computer, you can shut it off entirely after submitting the request.
- Build a jsonl file, one line per image:
{"custom_id": "image-1", "method": "POST", "url": "/v1/images/generations", "body": {"model": "gpt-image-2", "prompt": "Image description here", "size": "1024x1024"}}
- Upload the file:
batch_input_file = client.files.create(file=open("prompts.jsonl", "rb"), purpose="batch")
- Create the batch:
batch = client.batches.create(
input_file_id=batch_input_file.id,
endpoint="/v1/images/generations",
completion_window="24h",
)
According to the Batch API documentation (checked September 25, 2026), "24h" is currently the only valid value for the completion_window field.
- Go to sleep. OpenAI processes the requests on their end.
- In the morning, check the status with
client.batches.retrieve(batch.id)and download the results file withclient.files.content(...). - Match each image to its original description using
custom_id. The same documentation explicitly notes that the row order in the output file is not necessarily the same as in the input file.
One point that determines which model to use here: we checked the official model pages on September 25, 2026, and only gpt-image-2, gpt-image-1, and gpt-image-1-mini currently support the Batch API. The newer models, gpt-image-2.5-flare and gpt-image-2.5-sunburst, are not yet supported on this path, so for Batch runs you use gpt-image-2.
What this actually costs
Pricing is based on tokens, not a fixed per-image rate. The table below is based on the official pricing page and the individual model pages, all checked September 25, 2026:
| Model | Image input per million tokens | Cached image input | Image output per million tokens | Batch API support | Announced retirement date |
|---|---|---|---|---|---|
| gpt-image-2.5-flare | $8 | $2 | $30 | No (checked September 25, 2026) | Not yet set |
| gpt-image-2 | $8 | $2 | $30 | Yes | Not yet set, official migration target |
| gpt-image-1-mini | $2.50 | $0.25 | $8 | Yes | December 1, 2026 |
| gpt-image-1 | $10 | $2.50 | $40 | Yes | October 23, 2026 |
The exact cost per individual image depends on the resolution and quality you choose, which is why OpenAI points to a dedicated cost calculator inside their image generation guide rather than publishing a fixed per-image price. Through the Batch API you pay exactly half the price shown in the table, for the same model.
Worth noting: the cheaper gpt-image-1-mini and gpt-image-1 are headed for retirement roughly one to two months from the date this guide was published, so for anything built to last, gpt-image-2 is the better choice.
For more background on the newer models themselves, there is a full guide to ChatGPT Images 2.5.
A no-code alternative: Make or n8n
Anyone who does not want to touch Python can build a similar workflow in a visual automation tool: a list of prompts in a spreadsheet, a step that iterates through them row by row, an OpenAI API call for each row, and saving the result to Google Drive. The workflow is scheduled to run automatically at a set time overnight, with no need to remember to trigger it manually.
The advantage here is similar to the Batch API: both Make and n8n run in the cloud, so your computer does not need to stay on for the workflow to happen. Setting up this kind of workflow is covered in the full Make guide and the full n8n guide.
Safety rules before running an unattended job
- Set a budget cap on your API account before starting a run you will not be watching, so a loop error does not run far more times than you planned.
- OpenAI's content policy applies to the API as well. A prompt that violates it comes back as an error, not an image, so error handling in the script, or checking the
custom_idin the Batch output file, is what separates a run that continues from one that stops halfway through. - Do not use the same ten words in every prompt. Repetitive descriptions produce images that are too similar to each other. You can use ready-made ChatGPT prompt templates to vary the phrasing before running the full list.
- Test with 2 to 3 prompts first, not 50, to confirm that the model, size, and quality you chose produce exactly what you want.
The bottom line
The answer to the original question is not "yes, you can tell the chat." The answer is that there are two real approaches: a script running in a loop while the computer is on, for immediate control over every image, or the Batch API running in the cloud at half the price even when the computer is off, for a run that genuinely asks nothing of you beyond submitting it. And for anyone who has already connected Codex to a store, moving from chat to the API is exactly the same leap you made once before.
If that shift, from chat to work that runs on its own, interests you beyond just images, it is exactly what the interactive course ChatGPT 2026: From Chat to Automation covers, at 9.90 ILS.
Sources
- OpenAI: Batch API Guide (checked September 25, 2026)
- OpenAI: Official Pricing Page (checked September 25, 2026)
- OpenAI: Image Generation Guide (checked September 25, 2026)
- OpenAI: gpt-image-2 Model Page (checked September 25, 2026)
- OpenAI: gpt-image-2.5-flare Model Page (checked September 25, 2026)
- OpenAI: gpt-image-1-mini Model Page (checked September 25, 2026)
- OpenAI: Deprecations Page (checked September 25, 2026)
