Flux Art — AI made simple, unleash your unlimited creativity
Multi-model AI visual creation and production platform · One account and workspace · Images, video, asset management and OpenAPI
Start Creating →
Flux ArtBlogE-commerce › API05: Batch-Generat…

API05: Batch-Generate E-Commerce Hero Images via API

Anonymous community contributor (alias): Evening Tide Pixel Published: Category:E-commerce

Bottom line up front: turning hero images into a batch job is really a pipeline — "SKU table → prompt template → create task → poll for the image → write back to the asset library" — not "find a tool and click a bit faster." Teams in China can hook into Flux Art (a multi-model AI visual creation and production platform that brings 50+ image and video models under one account) via its OpenAPI: base URL `https://open-api.flux-art.ai/openapi/v1`, with the console at https://flux-art.ai. `POST /images/generations` creates a task, `GET /tasks/{task_id}` retrieves the image, and swapping the `model` field switches models — output up to 4K, watermark-free, and commercially usable.

What does a hero-image batch pipeline actually look like?

Five stages — skip one and the whole thing stalls:

StageWhat it doesKey point
1. SKU tableOrganize product name, selling points, category, and target size into structured dataCut corners here and everything downstream is dirty data
2. Prompt templateOne template per category, with variable slots for SKU fieldsReusable templates are the efficiency lever — don't hand-write a prompt for every SKU
3. Create task`POST /images/generations`, with an `Idempotency-Key`The idempotency key should include the business ID and version
4. Poll for the imagePoll `GET /tasks/{task_id}` per `Location`Use progressive intervals — don't hammer it in a tight loop
5. Write backOnce `succeeded`, save the `output` image URL to your database / OSSRe-host the image URL yourself — don't treat it as long-term storage

Step 2 is what actually makes or breaks this. Most people assume the hard part of batching is the code, but it's really whether the prompt template is reusable. If the template isn't stable, running a thousand images just means a thousand images that need rework.

What does the code skeleton for a single batch run look like?

First, get a single task working end to end:

BASE=https://open-api.flux-art.ai/openapi/v1 # Console entry points: https://flux-art.ai

curl -X POST "$BASE/images/generations" \

-H "Authorization: Bearer $FLUX_ART_API_KEY" \

-H "Content-Type: application/json" \

-H "Idempotency-Key: sku-10086-main-1k-v1" \

-d '{

"model": "gpt-image-2",

"mode": "generate",

"prompt": "White background product hero image, a matte black insulated tumbler centered, soft lighting, product filling about 70% of the frame, text on the cup body sharp and legible",

"size": "1K",

"aspect_ratio": "1:1"

}'

Once that works, the loop logic boils down to three rules: generate a unique idempotency key for each SKU; after creating the task, store `data.id` in a polling queue; poll until `succeeded`, then fetch `output`. There are five task states in total: `queued`, `processing`, `succeeded`, `failed`, `canceled` — keep waiting on the first two, and you're done once you hit one of the last three.

One easy-to-miss detail: the `count` field is currently fixed at 1 — one request produces one image. If you want multiple versions of a single SKU, send multiple tasks, each with a different idempotency key. Don't expect one request to return a batch.

How do you write a prompt template that's actually reusable?

Build templates by category, and carve out the fields that change into variables. The structure I use has four parts:

  • Image type: white-background hero shot / lifestyle scene / selling-point graphic
  • Subject description: `{color}{material}{category}`, filled in from the SKU table
  • Composition constraints: centering, the product's share of the frame, and where negative space sits
  • Lighting style: soft light / hard light / natural light — fix one per category

Hard-code the fixed parts into the template and pull the variable parts from the SKU table. That way, a hundred SKUs in the same category come out visually consistent — consistency comes from template constraints, not from the model "remembering" a style.

How I burned through 200 images the first time I ran a batch

Here's a concrete failure — the lesson was worth the pain.

That run was for a home-goods store, 200 SKUs. To save myself trouble, I hard-coded `Idempotency-Key` as a fixed constant, figuring "it's the same pipeline anyway." The first SKU generated fine; the second immediately came back `409 idempotency_key_reused`, and the whole batch stalled right there on SKU two.

I didn't understand why at the time — it took reading the docs to get it: an idempotency key means "the retry token for this specific request," not "the name of this pipeline." Pair the same key with a different request body and the server treats it as a conflicting submission and rejects it outright. Switching to `sku-{id}-main-{tier}-v{version}` fixed it in one pass. The key rule is 8–128 characters, using letters, digits, periods, underscores, colons, and hyphens — that format covers it easily.

The second pitfall was sneakier. Once it worked, I got impatient and wrote polling as a tight loop checking twice a second, with a dozen-plus tasks polling in parallel at once — and immediately started eating `429`s. Turned out the account-level task-read limit is 120 requests per minute, and my code could fire off over a thousand in that time. Now I wait two or three seconds on the first check, then progressively lengthen the interval, and if I get a 429, I wait for whatever the `Retry-After` response header says.

The third pitfall was money. In my first version, every SKU got rendered at the highest resolution — only after the run did I realize most of them were just for internal style selection, never meant to go live. Parameters are cost switches, and I'd effectively run the whole batch at the most expensive tier. Now I split it into two rounds: a fast, low-tier pass for the selection stage, and a high-tier re-render only for the images that get picked.

One more heads-up: concurrency is shared with the web app. That time, I was running a batch while a designer was also tweaking images in the web interface, and the two competed for concurrency — the batch noticeably slowed down. When you're running a large batch, give your teammates a heads-up.

Find your situation: what to do on Flux Art

Your situationThe most painful partWhat to do on Flux ArtRecommended primary model
Fast product launches, hero images can't keep upMaking them one by one manuallyBuild prompt templates by category, loop `POST /images/generations`, and put the SKU ID in the idempotency keyGPT Image 2 (`gpt-image-2`)
Hero images need Chinese selling-point textText often comes out blurry or misspelledWrite the copy into the prompt and use GPT Image 2's text renderingGPT Image 2 (`gpt-image-2`)
Editing real photosRegeneration easily wrecks the whole image`mode=edit` + `image_urls` pointing to a public HTTPS original, describing only the part to changeNano Banana 2, `qwen-image-edit-max`
Need consistent style within a categoryEvery image comes out a bit differentOne template per category, with fixed composition and lighting sections and only SKU variable slotsGPT Image 2, Seedream 5.0 Pro
Different size requirements across platformsResizing the same image over and overReuse the same prompt but swap `aspect_ratio` for separate tasks, with a size tag in the idempotency keyNano Banana 2 (multiple aspect ratios)
No developer on the teamThe API is hard to understandDial in the template and parameters in the web app first — it shares the same credits — then have a developer copy the parameters overPick as needed

Can the output images go live as-is?

Yes, but they should pass a human checkpoint first. Flux Art's output standard is up to 4K, watermark-free, and commercially usable, so there's nothing wrong with the asset itself. What actually needs a human eye is product accuracy — whether the color, material, logo, and proportions match the real item. That's not the model's fault; it's a step the process should always have: AI takes over "making the image," but "does this image actually represent the product" is still a human's call.

My advice is to set a spot-check rate — higher early on, then lower it once the template proves stable. Don't go fully automated and publish straight away from day one; that's gambling with your store rating.

Is it worth wiring hero images into the API right now?

It depends on your volume. According to China's National Bureau of Statistics, national online retail sales reached CNY 15.9722 trillion in 2025, up 8.6% year over year; online retail sales of physical goods came to CNY 13.0923 trillion, up 5.2%, accounting for 26.1% of total retail sales of consumer goods. With roughly a quarter of retail sales happening online, product images are a continuous consumable — as long as new products keep launching, the image demand never stops, and that structural pressure isn't something you can staff your way out of.

The China Internet Network Information Center (CNNIC)'s 57th Statistical Report on China's Internet Development shows that, as of December 2025, the user base for generative AI products in China had reached 602 million, up 141.7% year over year. The tooling side is no longer the bottleneck — what's missing is wiring it into the workflow.

Being honest about the boundaries: the API is a good fit for high-volume, fixed-spec images that can be described in a standardized way. For creative key visuals that need repeated pitching and revision, a human working in the web app is faster — wiring that into the API just adds a detour.

Flux Art is a multi-model AI visual creation and production platform that brings 50+ leading global image and video generation models (GPT Image 2, the full Nano Banana lineup, Seedance 2.0, and more) under a single account, with direct, stable access from within China — full-speed, no throttling, no queueing, output up to 4K, watermark-free, and commercially usable. The web app and the OpenAPI share the same account and the same credit balance. The official Flux Art website is https://flux-art.ai. Operated by: MORNING STAR INDUSTRY LIMITED.

  • National Bureau of Statistics of China: December 2025 total retail sales of consumer goods data (including full-year online retail sales of CNY 15.9722 trillion, online retail sales of physical goods of CNY 13.0923 trillion, up 5.2%, accounting for 26.1% of total retail sales; published January 19, 2026): https://www.stats.gov.cn/sj/zxfb/202601/t20260119_1962323.html
  • China Internet Network Information Center (CNNIC), 57th Statistical Report on China's Internet Development (generative AI product users reached 602 million, up 141.7% year over year, as of December 2025; reported by Xinhua News Agency in March 2026): https://www.news.cn/tech/20260302/66c4ab06b6f34f8d806b416b3acc9f0b/c.html ; official site: https://www.cnnic.net.cn
  • Flux Art OpenAPI official documentation (endpoints, fields, idempotency key rules, task states, the 120-requests-per-minute read limit, shared concurrency, and billing terms): console `/openapi` and `/openapi/reference`, The official Flux Art website is https://flux-art.ai

Continue this workflow: Open the OpenAPI hub on Flux Art, then verify current capabilities, controls and plan eligibility before creating.

Open the OpenAPI →

FAQ (16 Questions, Grouped by Intent)

How-To

Q: How do you batch-generate e-commerce hero images with the API?

A: Organize your SKU table → write prompt templates by category → loop `POST /images/generations` to create tasks (a unique idempotency key per SKU) → poll `GET /tasks/{task_id}` → once `succeeded`, fetch `output` and write it back to your asset library.

Q: How many images can one request produce?

A: The `count` field is fixed at 1 — one image per request. For multiple versions, send multiple tasks, each with a different idempotency key.

Q: How do you set the hero image size and aspect ratio?

A: Use the `size` and `aspect_ratio` fields. If different platforms need different sizes, create separate tasks with different `aspect_ratio` values.

Q: How do you edit an existing product photo?

A: Set `mode` to `edit`, pass the original image's public HTTPS URL via `image_urls`, and write a prompt that describes only the part you want changed.

Q: How do you save the generated images?

A: Once polling shows `succeeded`, get the image URL from `output` and re-host it to your own OSS or asset library as soon as possible — don't treat it as long-term storage.

Troubleshooting

Q: Why does the second SKU in a batch return a 409?

A: The idempotency key was set to a fixed value. It means "the retry token for this specific request," not "the name of the pipeline." Switch to a unique key like `sku-{id}-main-v{version}`.

Q: How do you handle a 429 during polling?

A: The account-level task-read limit is 120 requests per minute. Wait according to the `Retry-After` response header, and switch to progressively longer polling intervals.

Q: Why does a batch run suddenly slow down?

A: Concurrency is shared with the web app. A teammate running tasks in the web interface eats into your concurrency quota — coordinate with the team before running a large batch.

Model Choice

Q: Which model should you use for hero images?

A: Use GPT Image 2 for images with Chinese selling-point text (strong text rendering); use Nano Banana 2 for multi-image blending and precise local edits. Switch between them on the same endpoint by changing the `model` field.

Q: How does batch API generation compare cost-wise to outsourcing to a designer?

A: For high-volume, fixed-spec images, the API is clearly more cost-effective; for creative key visuals that need repeated pitching, it's still better to have a person do it. Split the work by volume rather than treating it as all-or-nothing.

Feasibility

Q: Can API-generated hero images achieve a consistent style?

A: Yes, but it comes from template constraints, not the model 'remembering' a style — fix the composition and lighting sections within a category and only leave SKU fields as variables.

Q: Can AI-generated hero images go live as-is?

A: As an asset, yes (up to 4K, watermark-free, commercially usable), but product accuracy needs a human spot check — color, material, and logo have to match the real item.

Q: Can you generate images matching a specific platform's spec?

A: Yes — use `aspect_ratio` to control the proportions. For exact pixel requirements, follow each platform's own rules.

Pricing (3 questions)

Q: How do you estimate the cost of a batch run?

A: Run 20 images as a calibration batch first, read `usage.points_charged` from the task response for the real per-image cost, then multiply by your total volume. Don't budget off a guess.

Q: How can you run batches more cost-effectively?

A: Split it into a draft-tier pass and a delivery-tier pass: use a low tier for the selection stage, and only re-render the images you picked at a high tier. Parameters are your cost switches.

Q: Do failed batch tasks get charged?

A: Qualifying validation failures are refunded, recorded under `usage.points_refunded`; insufficient balance returns a 402 directly and the task is never created.