Back to Blog

How to Run Batch Image Generation via API

Andrew Adams

Andrew Adams

·11 min read
How to Run Batch Image Generation via API

Generating images one at a time works for prototyping, but production workflows demand volume. Whether you are building a product catalog, creating social media assets at scale, or populating a content library, batch image generation via API lets you produce hundreds or thousands of images in a single run. Wireflow connects multiple AI image models into automated pipelines that handle batch requests, retry failures, and deliver results to your storage of choice.

For a hands-on look at this in action, check out the batch AI generation feature page, which walks through the visual interface for setting up batch jobs without writing code.

Why Batch Image Generation Matters

Single-request image APIs charge per call and require you to manage concurrency, error handling, and output storage manually. Batch processing solves these problems by grouping requests into a single job that the API provider can optimize and schedule more efficiently. Common use cases include:

  • E-commerce product shots across multiple angles and backgrounds
  • Social media content calendars requiring dozens of variations per week
  • Training data generation for computer vision models
  • A/B testing ad creatives at scale

The difference between a single API call and a batch pipeline is the difference between hand-writing letters and using a printing press. Both produce output, but only one scales.

Batch processing pipeline visualization

Choosing the Right API for Batch Generation

Not all image generation APIs handle batch requests the same way. Here is what to evaluate when selecting a provider for high-volume image workflows:

Provider Batch Support Concurrency Limit Cost per Image Output Format
OpenAI DALL-E 3 Sequential only 5 RPM (free), 50 RPM (paid) $0.04-0.12 PNG, URL
Stability AI Native batch endpoint 150 RPM $0.002-0.006 PNG, JPEG, WebP
fal.ai Queue-based async 100+ concurrent $0.01-0.05 PNG, JPEG
Replicate Prediction batches Unlimited (queued) Model-dependent PNG, WebP
Wireflow API Pipeline-native batch 10 exec/min, up to 200 req/min (Enterprise) Usage-based credits Any format

The key distinction is whether the API offers true batch endpoints (submit N prompts, get N results) or requires you to build concurrency management yourself. Stability AI and fal.ai provide dedicated batch modes, while DALL-E requires you to handle parallelism in your own code. Wireflow takes a different approach by letting you define a workflow graph once and execute it repeatedly with different inputs via its REST API.

Setting Up Your First Batch Request with Wireflow

The basic pattern for batch image generation using Wireflow follows three steps: build your workflow, execute it per prompt via the API, and poll for results. First, create a workflow in the visual editor that chains an input node to an image generation model like generate:flux_2_pro or generate:imagen4, then connect it to an output node. Once saved, you can trigger it programmatically using workflow templates:

const API_BASE = "https://www.wireflow.ai/api/v1";
const API_KEY = "sk-your-api-key"; // from Settings > API Keys
const WORKFLOW_ID = "your-workflow-id";

const prompts = [
  "Professional headshot, neutral background, soft lighting",
  "Product photo of wireless earbuds on marble surface",
  "Minimalist logo design, blue and white color scheme",
  "Interior design render, modern living room, natural light"
];

async function executeWorkflow(prompt) {
  const res = await fetch(`${API_BASE}/workflows/${WORKFLOW_ID}/execute`, {
    method: "POST",
    headers: {
      "Authorization": `Bearer ${API_KEY}`,
      "Content-Type": "application/json",
      "Idempotency-Key": `batch-${Date.now()}-${prompt.slice(0, 20)}`
    },
    body: JSON.stringify({
      nodes: [{ id: "input_1", type: "basedNode", position: { x: 0, y: 0 },
        data: { label: "Prompt", category: "input", nodeType: "input:text",
          params: { text: prompt } } }],
      edges: []
    })
  });
  return res.json(); // { executionId: "exec_..." }
}

This triggers a real execution on Wireflow's infrastructure. Each call returns an executionId that you use to poll for the completed image. The API authenticates via Bearer token with keys generated from your dashboard, and accepts an optional Idempotency-Key header to prevent duplicate executions within 24 hours.

API request flow diagram

Handling Rate Limits and Retries

Every image API enforces rate limits. Wireflow caps execution starts at 10 per minute across all plans, while request limits scale from 10/min (Free) to 200/min (Enterprise). When generating hundreds of images, your batch system needs proper throttling with automated pipeline logic and exponential backoff:

async function pollExecution(executionId, maxAttempts = 20) {
  let delay = 1000;
  for (let i = 0; i < maxAttempts; i++) {
    const res = await fetch(
      `${API_BASE}/workflows/executions/${executionId}/poll`,
      { headers: { "Authorization": `Bearer ${API_KEY}` } }
    );
    const data = await res.json();
    if (data.status === "COMPLETED") return data;
    if (data.status === "FAILED") throw new Error(data.error);
    await new Promise(r => setTimeout(r, delay));
    delay = Math.min(delay * 1.5, 10000);
  }
  throw new Error("Polling timed out");
}

async function batchGenerate(prompts, { maxConcurrent = 5 } = {}) {
  const results = [];
  for (let i = 0; i < prompts.length; i += maxConcurrent) {
    const batch = prompts.slice(i, i + maxConcurrent);
    const executions = await Promise.all(
      batch.map(p => executeWorkflow(p))
    );
    const completed = await Promise.all(
      executions.map(e => pollExecution(e.executionId))
    );
    results.push(...completed);
  }
  return results;
}

Key considerations for production batch systems:

  • Implement exponential backoff starting at 1 second, multiplying by 1.5 per attempt, capping at 10 seconds
  • Watch for 429 responses and respect the Retry-After header returned by the API
  • Track partial results so you can resume interrupted batches using Idempotency-Key headers
  • Log failed prompts separately for manual review, checking the X-Request-Id header for support debugging
  • Set a global timeout to prevent indefinite hangs

Scaling with Webhooks and Async Execution

For truly large batches (1000+ images), synchronous polling becomes inefficient. Wireflow supports webhook-triggered execution where you submit jobs via a public URL and receive results asynchronously. Each workflow can be assigned a webhook endpoint at /workflow/{webhookId}/trigger, which requires no API key and accepts CORS requests from any origin. This makes it ideal for integrating with reusable templates triggered from external systems:

  1. Submit phase: POST each prompt to your workflow's webhook trigger URL. The endpoint returns a 202 status with an executionId immediately.
  2. Processing phase: Wireflow processes images across its infrastructure using models like generate:flux_2_pro or generate:imagen3. No client-side polling needed if you use a callback.
  3. Delivery phase: Poll completed executions at GET /workflows/executions/{id} using your API key to retrieve timing, credit usage, and node outputs.
  4. Verification phase: Your system confirms receipt and stores the final assets.
# Trigger via webhook (no API key needed)
curl -X POST https://www.wireflow.ai/api/v1/workflow/YOUR_WEBHOOK_ID/trigger \
  -H "Content-Type: application/json" \
  -d '{"prompt": "Product photo of headphones on white background"}'
# Returns: { "executionId": "exec_789" }

This decoupled architecture means your application never blocks waiting for image generation. You can submit a batch of 5,000 product images from a CI pipeline, a Zapier automation, or even a simple HTML form, and collect results as each execution completes.

Async webhook architecture

Optimizing Cost and Speed

Batch generation costs add up quickly at scale. Here are proven strategies to reduce spend while maintaining quality, applicable across any image generation platform:

Resolution tiering: Generate thumbnails at 512x512 for previews, then upscale only the approved ones to full resolution. This cuts costs by 60-70% for workflows with human review steps.

Model selection per task: Use faster, cheaper models like generate:flux_2 for drafts and premium models like generate:flux_2_pro or generate:imagen4 for final outputs. Wireflow workflows support routing different prompts to different model nodes within the same pipeline.

Prompt deduplication: Before submitting a batch, hash your prompts and skip duplicates. In product catalogs, you often have near-identical prompts that differ only in product name.

Credit-aware scheduling: Check your available credits before large batches. The API returns a 402 status with a detailed breakdown of requiredCredits and availableCredits per node if your balance is insufficient, letting you plan capacity in advance.

Caching layers: Store generated images with their prompt hash as the key. Future requests for the same prompt return cached results instantly with zero API cost.

Storing and Organizing Batch Output

A batch of 500 images is worthless without proper organization. Your storage strategy should account for asset pipeline management from generation through delivery:

/output/
  /batch-2026-04-21/
    /approved/
    /rejected/
    /pending-review/
    manifest.json      # Maps prompt → output file → metadata

The manifest file is critical. It maps each prompt to its output, records generation parameters, and tracks approval status. This lets you reproduce any image later or audit which prompts produced which results. Store metadata like model version, seed value, and generation timestamp alongside each image.

For cloud storage, upload directly from the generation pipeline to your CDN. Services like R2, S3, or GCS all support presigned URLs that let the image API write directly to your bucket without proxying through your server.

Organized asset library

Try It Yourself

Try it yourself: Explore the Wireflow API docs to set up your first batch image generation workflow with pre-configured nodes and real API endpoints.

Frequently Asked Questions

What is batch image generation via API?

Batch image generation is the process of submitting multiple image creation requests to an AI image API in a single operation, rather than making individual calls one at a time. It allows you to generate dozens or thousands of images from a list of prompts with automated concurrency, error handling, and result collection. With Wireflow, you build a workflow graph once and execute it repeatedly via the REST API at POST /workflows/{id}/execute.

How many images can I generate in a single batch?

This depends on your API provider and plan. Wireflow enforces 10 execution starts per minute across all plans, with daily limits ranging from 50 (Free) to unlimited (Enterprise). You can queue as many executions as your daily limit allows. Stability AI supports up to 10,000 images per batch request, while fal.ai queues unlimited requests based on your concurrency tier.

What is the cheapest API for batch image generation?

Stability AI offers the lowest per-image cost at $0.002-0.006 per image for their SDXL models. fal.ai is competitive for open-source models like Flux, typically $0.01-0.03 per image. Wireflow uses credit-based pricing that bundles model costs with pipeline infrastructure, so the total cost depends on which nodes your workflow uses.

How do I handle failures in a batch?

Implement retry logic with exponential backoff for transient errors (rate limits, timeouts). Track failed prompts in a separate queue for manual review. Use Idempotency-Key headers on Wireflow execute calls so retried requests do not create duplicate executions within the 24-hour replay window. Poll each execution and check for FAILED status with the error message in the response.

Can I use different models within the same batch?

Yes. Wireflow workflows support multi-model routing natively. You can chain nodes like generate:flux_2_pro for photorealistic product shots and generate:imagen3 for artistic illustrations within the same workflow graph. The visual editor lets you connect branching logic that routes prompts to different model nodes based on input parameters.

How long does a batch of 1000 images take?

With Wireflow's 10 executions per minute cap, 1000 sequential executions would take roughly 100 minutes. In practice, each execution runs its internal pipeline in parallel, so the wall-clock time per image depends on the model. You can also distribute work across multiple workflows or use webhook triggers to decouple submission from processing.

Do I need to store all generated images?

Not necessarily. Many workflows include a filtering step where a classifier or human reviewer selects the best outputs. Generate more than you need (2-3x), filter programmatically for quality, then store only the approved results. This produces better final output at marginally higher generation cost.

What format should batch output images use?

PNG for images requiring transparency or maximum quality. WebP for web delivery (30-50% smaller than PNG with negligible quality loss). JPEG for photographs where file size matters more than pixel-perfect accuracy. Most APIs support format selection per request, so you can mix formats within a single batch.

Conclusion

Batch image generation via API transforms image creation from a manual, one-at-a-time process into a scalable production system. The key components are proper concurrency management, retry logic with exponential backoff, async processing via webhooks for large volumes, and organized output storage. Whether you are generating 50 product photos or 50,000 training images, the architecture remains the same. Wireflow provides the pipeline infrastructure to connect these pieces through a visual workflow editor and REST API, letting you focus on prompt engineering and creative direction rather than API plumbing.