How to Generate Product Images with AI API — Developer Guide
You're building an e-commerce platform. Sellers upload raw product photos — uneven backgrounds, bad lighting, mixed aspect ratios. You need clean, consistent product images at scale without a photo studio or a per-image manual editing queue. That's exactly the problem AI image generation APIs solve.
This guide walks through generating and editing product images using GenRelay's unified API, which gives you access to Nano Banana Pro, Nano Banana 2, and GPT-image-2 from a single endpoint. No separate provider integrations, no per-model credential management.
Which model should I use for product images?
GenRelay exposes three image models as of August 2026, each with a different cost-quality profile:
| Model | Best for | Output sizes | Price per image |
|---|---|---|---|
| Nano Banana Pro | Studio-quality renders, photorealistic lighting | 1K / 2K / 4K | $0.030 / $0.030 / $0.042 |
| Nano Banana 2 | High-volume catalog generation, consistent style | 1K / 4K | $0.020 / $0.036 |
| GPT-image-2 | Editing existing photos, background replacement, text overlay | Standard | $0.014/image |
For most product photography workflows:
- New product renders from a text prompt → Nano Banana Pro (better photorealism, higher detail ceiling)
- Standardized catalog at volume → Nano Banana 2 (lower unit cost, consistent output at scale)
- Retouching or background replacement on existing product photos → GPT-image-2 (native image editing support)
For a deeper quality comparison, see Nano Banana Pro vs GPT-image-2.
How do I authenticate with the GenRelay image API?
Authentication uses a Bearer token in the Authorization header. Get your API key from the GenRelay console. The same key works across all three image models — no per-model credentials.
import requests
GENRELAY_API_KEY = "your_key_here"
headers = {
"Authorization": f"Bearer {GENRELAY_API_KEY}",
"Content-Type": "application/json"
}
Every request below uses this header object. Store the key in an environment variable, not in source code.
How do I generate a product image from a text prompt?
Send a POST request to /v1/images/generations with your chosen model, prompt, and size. The response returns an image URL.
import requests
GENRELAY_API_KEY = "your_key_here"
def generate_product_image(prompt: str, model: str = "nano-banana-pro", size: str = "1024x1024") -> str:
response = requests.post(
"https://genrelay.ai/v1/images/generations",
headers={
"Authorization": f"Bearer {GENRELAY_API_KEY}",
"Content-Type": "application/json"
},
json={
"model": model,
"prompt": prompt,
"n": 1,
"size": size
}
)
response.raise_for_status()
return response.json()["data"][0]["url"]
# Generate a product image for a wireless speaker
url = generate_product_image(
prompt="Professional product photo of a matte black wireless speaker on a clean white background, "
"studio lighting, soft drop shadow, slightly angled front view, e-commerce style",
model="nano-banana-pro",
size="1024x1024"
)
print(url)
Effective prompt structure for product images: [adjective] product photo of [product description] on [background], [lighting], [shadow type], [angle], [style notes]. Concrete descriptors ("soft drop shadow", "angled front view") produce more consistent results than abstract ones ("professional", "high quality").
For 4K output, use "size": "4096x4096" ($0.042 per image on Nano Banana Pro, $0.036 on Nano Banana 2).
How do I edit or retouch an existing product image?
GPT-image-2 supports in-image editing through the /v1/images/edits endpoint. Pass the original image as a Base64-encoded string and describe the change. This is practical for background replacement, adding lifestyle context, or correcting small defects.
import requests
import base64
GENRELAY_API_KEY = "your_key_here"
def edit_product_image(image_path: str, edit_prompt: str) -> str:
with open(image_path, "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
response = requests.post(
"https://genrelay.ai/v1/images/edits",
headers={
"Authorization": f"Bearer {GENRELAY_API_KEY}",
"Content-Type": "application/json"
},
json={
"model": "gpt-image-2",
"image": image_b64,
"prompt": edit_prompt,
"n": 1
}
)
response.raise_for_status()
return response.json()["data"][0]["url"]
# Replace a cluttered background with a clean studio background
url = edit_product_image(
image_path="raw_product_photo.jpg",
edit_prompt="Replace the background with a clean white studio backdrop with soft shadows. "
"Keep the product unchanged. Ensure consistent lighting on the product."
)
print(url)
Background replacement via GPT-image-2 costs $0.014 per image — substantially lower than manual post-processing at scale. See the GPT-image-2 API page for the full list of supported edit operations.
What does product image generation cost at catalog scale?
For a catalog of 10,000 SKUs, each needing one image at 1K resolution:
| Model | Unit cost (1K) | 10,000 images | Notes |
|---|---|---|---|
| Nano Banana Pro | $0.030 | $300 | Highest photorealism |
| Nano Banana 2 | $0.020 | $200 | Consistent, good for standardized catalog |
| GPT-image-2 | $0.014 | $140 | For editing existing photos |
A mixed strategy — GPT-image-2 for retouching products that already have photos, Nano Banana 2 for new SKUs — can bring average cost below $0.018 per image. For 100K+ image catalogs, batching with concurrency controls and exponential-backoff retry logic matters more than per-image cost optimization. See the batch image generation guide for concurrency patterns.
For a quick sequential batch with basic error handling:
import requests
import time
GENRELAY_API_KEY = "your_key_here"
PRODUCTS = [
{"sku": "SKU001", "prompt": "Product photo of a ceramic pour-over coffee dripper, white background, studio lighting, top-down angle"},
{"sku": "SKU002", "prompt": "Product photo of a bamboo cutting board, white background, soft shadows, slightly angled view"},
{"sku": "SKU003", "prompt": "Product photo of a stainless steel insulated water bottle, white background, straight-on view, matte finish"},
]
results = []
for product in PRODUCTS:
try:
r = requests.post(
"https://genrelay.ai/v1/images/generations",
headers={"Authorization": f"Bearer {GENRELAY_API_KEY}"},
json={
"model": "nano-banana-2",
"prompt": product["prompt"],
"n": 1,
"size": "1024x1024"
},
timeout=30
)
r.raise_for_status()
results.append({"sku": product["sku"], "url": r.json()["data"][0]["url"]})
except requests.HTTPError as e:
results.append({"sku": product["sku"], "error": str(e)})
time.sleep(0.1) # modest buffer between requests
success = sum(1 for r in results if "url" in r)
print(f"Generated {success} / {len(PRODUCTS)} images")
FAQ
Can I request a transparent background (PNG with alpha channel)?
As of August 2026, include "transparent background, PNG format" in your prompt and set "response_format": "b64_json" to receive Base64-encoded PNG data. Results are most reliable with Nano Banana Pro. Nano Banana 2 and GPT-image-2 may produce a white fill instead of true transparency — test on your specific product type before running at scale.
What aspect ratios does the image API support?
The size parameter accepts standard dimension strings: 1024x1024, 1792x1024, 1024x1792. Square (1:1) produces the most consistent results across all three models and is safest for catalog use where images need to fit a fixed tile grid.
Does Nano Banana Pro support 2K output?
Yes. Nano Banana Pro supports 1K (1024x1024), 2K (2048x2048), and 4K (4096x4096) at $0.030, $0.030, and $0.042 respectively. The 2K tier is the same price as 1K, making it the default choice when image quality is a priority without the cost jump of 4K.
What happens if I hit a rate limit (HTTP 429)?
Implement exponential backoff. The 429 response includes a Retry-After header indicating how many seconds to wait. Start with that value and double it on repeated failures. For concurrent batch generation, add a semaphore to cap simultaneous in-flight requests.
Can I use AI-generated product images commercially?
GenRelay passes through the usage rights from each underlying model provider. Nano Banana Pro, Nano Banana 2, and GPT-image-2 each permit commercial use under their standard terms. Review the model-specific terms in the GenRelay console before deploying to production catalogs.