Prompt Engineering: Implementing Cost-Efficient Batch Processing Pipelines
Framework Overview
- Core Technique: Meta-Prompting / Task Automation Instruction
- Target LLMs: Optimized for Claude (for script generation), compatible with agents like Cursor or general coding assistants able to handle tool documentation consumption.
- Primary Use Case: Automating expensive resource tasks (image generation) by switching between synchronous high-priority requests and asynchronous low-cost batch jobs ($50% discount).
The Prompt Template
У меня пайплайн генерации картинок через API (GPT Image / Nano Banana Pro). Хочу платить вдвое меньше. У обоих провайдеров есть Batch API со скидкой 50% на отложенную генерацию. Изучи их актуальные доки и добавь в пайплайн батч-режим: команда отправить пачку запросов, команда проверить статус, команда забрать готовые картинки. Референсные изображения в батче нельзя слать multipart - загрузи их через Files API провода и передавай по file_id. Перед генерацией всегда спрашивай меня: срочно или батчем. В конце проверь весь цикл на дешевом тестовом запросе.Execution Workflow & Rules
- Documentation Review: The agent must first parse the specific technical owns/documentation for GPT Image or Nano Banana Pro to identify correct endpoint structures.
- Logic Implementation: Implement three mandatory commands into a script: 'send pack', 'check status', and 'retrieve results'.
- File Management Constraint: Instead of using heavy multipart uploads for reference images within batches, use any way permitted by documentation such as uploading via `Files API` then passing through `file_id`.
- Decision Logic (The Gatekeeper): Insert an interceptor prompt that asks if tasks are "urgent" (synchronous) OR "batchable" (asynchronous with 50% discount).
- Validation Phase: Execute one cheap test cycle before running full production loadsto ensure code integrity properly handles non-priority requests.
Behavioral Tuning & Anti-Hallucination
- Cost Avoidance Rule: Prioritize Batch APIs unless speed is explicitly requested; this prevents unnecessary spending on low-urgency assets where quality remains identical but price drops significantly ($0.18 down to $0.09 etc.).
- Constraint Compliance: Strict adherence to file handling protocols—specifically avoiding the mistake of sending raw data in batch mode instead of utilizing proper ID references (`file_id`).
- Verification Requirement: If a generation fails or returns undesirable/incorrectly rendered content ('кривой'), trigger localized regeneration only for those specific items rather than restarting the entire set.
Bottom Line: This method transforms expensive, high-cost API calls into cost-efficient automated pipelines by leveraging asynchronous delay and agentic decision logic without sacrificing output quality.
! DYOR (Do Your Own Research)