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 › API06: Automate Prod…

API06: Automate Product Photo Background Swaps via API

Anonymous community contributor (alias): Starlight Film Published: Category:E-commerce

Bottom line up front: swapping a background via API isn't a two-step "cut out, then paste down" job — it's a single edit task. You pass in the original image URL, describe only the new background you want, and the model hands back a finished shot with the lighting already blended in. The way to do it is to call Flux Art's OpenAPI (a multi-model AI visual creation and production platform where one account gives you 50+ image and video generation models): `POST /images/generations`, set `mode` to `edit`, pass a public HTTPS URL for the original image in `image_urls`, with base URL `https://open-api.flux-art.ai/openapi/v1` — the console lives at https://flux-art.ai. For multi-image fusion and precise local repainting, the recommended primary model is Nano Banana 2.

How Is Doing Background Swaps via API Different From Cutting Out in PS?

The difference comes down to one key point: you no longer need to first produce a cleanly cut-out transparent-background image.

The traditional workflow is linear: cut the edges → remove fringing → paste on the new background → add a shadow → blend the lighting. Any step can go wrong, and the last two take the most effort — get the shadow or lighting wrong and the image looks fake at a glance.

The API approach folds that whole sequence into a single task: hand it the original image and a description of the target background, and the model outputs an already-blended result directly. The shadow and lighting are generated, not something you add by hand. That's the real source of the efficiency gain — it's not "cutting out faster," it's three fewer steps.

StageTraditional PS WorkflowFlux Art API (`mode=edit`)
Cutting edgesPen tool/channels, manualHandled internally by the model, no intermediate file produced
Removing fringingManual retouchingSame as above
Swapping backgroundPaste a layerPrompt describes the target background
ShadowHand-drawnProduced together with the generation
Lighting blendManual color gradingProduced together with the generation
Time per imageA few minutes for a skilled retoucherOne task, can run concurrently in batch
Batch capabilityScales by adding more peopleLoop to create tasks

To be honest about the limits: the model isn't magic. Subjects with extremely complex edges — hair, transparent glass, cutout mesh fabric — are still a weak point, so spot-check the output. For these, my current approach is to let the API run a first pass, then pull out the ones that don't pass and fix them by hand, rather than betting everything on the model.

How Do You Call a Single Background-Swap Task?

Three fields matter: `mode=edit`, `image_urls`, and a prompt that only describes what needs to change.

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-bg-white-v1" \

-d '{

"model": "gemini-3-pro-image-preview",

"mode": "edit",

"prompt": "Change the background to a pure white photography studio backdrop, keep the product's original color, material, and label text intact, and add a natural contact shadow at the bottom",

"image_urls": ["https://your-domain.com/sku10086.jpg"],

"aspect_ratio": "1:1"

}'

Three things you must remember:

  • `image_urls` must be a publicly accessible HTTPS URL. Intranet addresses or private OSS links that require a signature can't be reached by the server and will return `400 invalid_media_url`.
  • The prompt should only describe "what to change" and "what to preserve." Writing a constraint like "keep the product's original color, material, and label text" is far more reliable than just writing "swap to a white background."
  • Don't get `mode` wrong. `generate` creates from scratch; `edit` is what modifies the original image. This field is required.

After creating the task, poll `GET /tasks/{task_id}` as usual; status moves through `queued` → `processing` → `succeeded`/`failed`/`canceled`.

What Went Wrong in My First Attempt at Batch-Converting Product Photos to White Backgrounds?

Let me walk through a concrete example. That batch was home goods, and they all needed to be converted to a uniform white-background studio style.

My first-version prompt was dead simple: "Change the background to white." At first glance the results looked fine; look closer and they were full of problems — the product's colors had drifted, a beige ceramic mug got "washed" nearly pure white and blended right into the background; several products also looked like they were floating, with no shadow, like they'd been pasted on.

The problem was that I only said what I wanted, not what to preserve. While repainting, the model let the "white" instruction bleed onto the subject itself.

The fix is to turn the prompt from a single sentence into three parts: target background + subject protection + contact detail. That's exactly the pattern in the example above — "change to a pure white studio backdrop" (target), "keep the product's original color, material, and label text" (protection), "add a natural contact shadow at the bottom" (detail). After regenerating with that structure, the colors held and the shadow looked natural.

The third trap was polling. Don't write a tight loop that hits the endpoint every second — the account-level task-read limit is 120 requests per minute, and running just a few tasks in parallel is enough to hit `429`. Wait two or three seconds before the first check, then back off progressively, and if you get a 429, wait according to `Retry-After`.

Which Model Should You Choose for Background Swaps?

It depends on what you need:

NeedRecommended ModelReason
Background swaps, multi-image fusion, precise local repaintingNano Banana 2 (`gemini-3-pro-image-preview`)Excels at multi-image fusion and precise local repainting; supports 14 aspect ratios, up to 4K
Background needs accurate Chinese textGPT Image 2 (`gpt-image-2`)Strong text rendering and instruction following; 3 precision tiers x 4 resolution tiers, 12 total
High-volume routine white backgroundsPick based on your own test results — run a batch on each firstSame endpoint, just change the `model` field; no code changes needed
Image-translation-style text edits`qwen-mt-image`, `qwen-image-edit-max`Built for terminology-matched translation and editing

Because it's the same `POST /images/generations` endpoint, running a comparison costs almost nothing — configure a list of models as an array, run two or three models on the same batch of images, and pick whichever holds up best by eye before locking in your primary model. That's more reliable than trusting any benchmark.

Find Your Scenario: What to Do on Flux Art

Your ScenarioThe Most Painful PartWhat to Do on Flux ArtRecommended Primary Model
Real product shots need a uniform white backgroundCutting out is slow, shadows look fake`mode=edit` + `image_urls`; write the prompt in three parts — target background + subject protection + contact shadowNano Banana 2 (`gemini-3-pro-image-preview`)
Need to switch to a lifestyle scene backgroundLighting won't blend inSame as above; describe the light direction in the prompt so the shadow matches the ambient lightNano Banana 2
Product color keeps getting alteredRepainting bleeds onto the subjectState explicitly in the prompt to "keep the product's original color, material, and label text"Nano Banana 2
Background needs Chinese promotional textText comes out blurry or with typosUse GPT Image 2 and write the exact copy into the promptGPT Image 2 (`gpt-image-2`)
Batch-refreshing old imagesThousands of legacy images that no one has time forLoop to create tasks; put the SKU and background type in the idempotency key; write finished images back to your asset libraryNano Banana 2
Hair/transparent/cutout-mesh subjectsEdges go wrongLet the API run a first pass, pull out the failures and fix by hand — don't rely on the model for everythingNano Banana 2 + manual backstop

Is This Work Worth Automating Right Now?

It comes down to your backlog. 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; physical goods online retail sales reached CNY 13.0923 trillion, up 5.2%, accounting for 26.1% of total retail sales of consumer goods. With roughly a quarter of retail happening online, every store is sitting on a pile of existing images that keep needing to be refreshed — new season, new style, new platform, new size, new campaign, new background. The work never actually finishes.

The China Internet Network Information Center (CNNIC)'s 57th Statistical Report on China's Internet Development shows that as of December 2025, the number of generative AI product users in China reached 602 million, up 141.7% year over year. Plenty of people already know how to use these tools — the real difference is whether "a person clicks through it" or "a system runs it automatically."

The dividing line is the same as ever: images with fixed specs that can be described in a standardized way are suited to batch runs; creative images that require design judgment are still faster done by a person.

Flux Art is a multi-model AI visual creation and production platform — one account gives you access to 50+ leading global image and video generation models (GPT Image 2, the full Nano Banana lineup, Seedance 2.0, and more), with direct, stable access from within China, no extra network setup needed, full-power throughput with no rate limiting or queueing, output up to 4K, zero watermarks, and commercial use allowed. It supports editing capabilities such as up to 14 reference images, subject-segmentation skipping, and terminology-matched translation. 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. Operating entity: 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, physical goods online retail sales 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 (602 million generative AI product users, 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 (the `mode=edit` and `image_urls` fields, idempotency key rules, error codes, task status, and the 120-requests-per-minute read limit): 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 →

Frequently Asked Questions (16 Qs, Grouped by Intent Cluster)

How-To

Q: How do you swap a product photo's background using the API?

A: Call `POST /images/generations` with `mode` set to `edit`, pass a public HTTPS URL for the original image in `image_urls`, describe the target background and the subject features to preserve in the prompt, then poll `GET /tasks/{task_id}` to retrieve the image.

Q: Do I need to cut out the image myself first?

A: No. Swapping the background is a single edit task — edge cutting, shadow, and lighting blend are all handled by the model together, with no intermediate transparent-background file produced.

Q: How do I pass a reference image or the original image to the API?

A: Use the `image_urls` field with a publicly accessible HTTPS URL. Intranet addresses or private links that require a signature can't be reached by the server.

Q: How do I do local repainting?

A: Also use `mode=edit`; write the prompt to describe only the part that needs to change, and state clearly what to preserve, so the edit doesn't bleed onto the subject.

Q: How do I batch-refresh old images?

A: Loop to create tasks with a unique idempotency key for each image (we suggest `sku-{id}-bg-{type}-v{version}`), then poll to retrieve the images and write them back to your asset library.

Troubleshooting

Q: What does a 400 invalid_media_url error mean?

A: The server can't reach the address in `image_urls`. Check whether it's an intranet address, a private OSS link that needs a signature, or an expired link. Don't retry this type of error.

Q: What if the second image already returns a 409?

A: You've hardcoded a fixed idempotency key. Use a new unique key for each image; only reuse the original key when retrying after a timeout or a 5xx error.

Q: What if polling returns a 429?

A: The account-level task-read limit is 120 requests per minute. Wait according to the `Retry-After` response header, and switch your polling interval to a progressive backoff.

Model Choice

Q: Which model's API should I use for background swaps?

A: For multi-image fusion and precise local repainting, use Nano Banana 2 (`gemini-3-pro-image-preview`); if the background needs accurate Chinese text, use GPT Image 2.

Q: How do I figure out which model fits my product category best?

A: You can switch models on the same endpoint just by changing the `model` field. Run two or three models on the same batch of images and pick by eye — that's more reliable than reading benchmarks.

Q: How should API background swaps and manual cutouts divide the work?

A: Run regular, well-defined subjects through the API in batch; for complex edges like hair, transparency, or cutout mesh, run a first pass through the API and then fix by hand — don't rely entirely on the model.

Feasibility

Q: Can the product get distorted or change color after a background swap?

A: It can — if the prompt only says what you want and not what to preserve. Explicitly stating "keep the product's original color, material, and label text" improves this significantly, though you should still spot-check the output.

Q: Can the shadow look natural?

A: Explicitly request "a natural contact shadow at the bottom" in the prompt and describe the light direction; the shadow is produced together with the generated image and tends to look more natural than one added by hand.

Q: Can images go straight to a live listing after a background swap?

A: In terms of file properties, yes — up to 4K, zero watermarks, commercial use allowed. But you should still spot-check product consistency by hand, since the color and material need to match the real item.

Pricing

Q: How many credits does one background swap cost?

A: There's no published flat rate — images are billed per image, and size and quality affect consumption for some models. Go by the `usage.points_charged` value returned with the task.

Q: How do I keep costs down?

A: Run a first pass at a lower tier to screen results, and only re-run at a higher tier for images you're confident about listing. Your parameters are the cost switch.