How I Kept AI Image Generation Costs Near Zero On A 2 GB Single-Core Server
Description and use
An AI image generation pipeline on a 2 GB single‑core VPS that uses sequential processing, upload tracking, correct metadata headers, peak memory monitoring, subprocess rendering, and final packaging to keep API costs near zero.
Problem
Running an AI image generation pipeline on a 2 GB single‑core VPS caused frequent out‑of‑memory crashes and wasted API credits due to repeated regenerations and metadata rejections.
Outcome
The pipeline processed 39 finished products, producing ~856 MB of output from ~19,000 lines of code, while keeping API costs near zero by eliminating duplicate uploads and metadata rejections.
Workflow
- 1. Maintain an upload ledger (upload_tracker.py) to skip already submitted assets.
- 2. Generate platform‑specific CSV headers with make_metadata.py, optionally using titles.json.
- 3. Process images sequentially on the single core, calling gc.collect() after each asset.
- 4. Measure peak RSS with resource.getrusage(RUSAGE_SELF).ru_maxrss after each run.
- 5. Render heavy steps (e.g., image resizing) in a child subprocess to reclaim memory.
- 6. Render at the required resolution (e.g., 60 dpi for previews, 300 dpi for final).
- 7. Package finished products with pack_product.py, creating a cover (1280×720) and thumbnail (600×600) using Pillow.
- 8. Convert Markdown to styled PDF with md2pdf.py using reportlab.
- 9. Store all research and logs in a permanent research/ folder to avoid re‑doing work.
Evidence
I killed a batch job at 2 AM because the server had 40 MB of RAM left and I could hear the fan spinning like it was trying to escape.
When people talk about AI image costs they mean API credits. My costs stayed near zero for a different reason: I stopped throwing away work.
All three big channels reject a wrong CSV header instantly.
Four habits, all of them learned by hitting a wall first.
- Record date: 2026-10-15T16:41:34.759Z