How to Maintain Visual Consistency in AI-Generated Images via API

Sep 2, 2026·7 min read

You're building a product catalog generator: 500 SKUs, each needing five scene variations. Every call returns a slightly different product shape, handle angle, or label color. Or you're running a character avatar pipeline and each generated pose drifts away from the original appearance. Text-to-image models are probabilistic by design — without additional anchors, creative variance is the default. In production pipelines where visual identity is non-negotiable, that variance is a bug.

This guide covers the concrete techniques available on GenRelay to enforce visual consistency across batches of AI-generated images, with copy-paste Python code and exact cost numbers.


Why Does Visual Drift Happen Across Generations?

Visual drift happens because each API call samples independently from the model's learned distribution. Your prompt is a constraint, not a deterministic instruction. Two requests with identical prompts will produce similar but not identical images — different lighting angle, slightly different proportions, shifted color balance. The longer and more descriptive the prompt, the more the model is constrained, but you can never fully eliminate variance through text alone.

The reliable solutions all involve giving the model a visual anchor: a reference image that defines what "this product" or "this character" actually looks like. Text describes; reference images show.


How Does Reference-Guided Generation Work on GenRelay?

Reference-guided generation is a consistency mechanism where you pass an existing image alongside your text prompt. The model uses the reference to anchor composition, color, subject identity, or style while still following the prompt for scene variation. On GenRelay, Nano Banana Pro and Nano Banana 2 support reference-guided generation via the standard /v1/images/generations endpoint with an image parameter.

import requests
import base64
import os

API_KEY = os.environ["GENRELAY_API_KEY"]

def reference_generate(reference_path: str, prompt: str, size: str = "1024x1024") -> str:
    """Generate an image anchored to a reference, for visual consistency."""
    with open(reference_path, "rb") as f:
        ref_b64 = base64.b64encode(f.read()).decode("utf-8")

    response = requests.post(
        "https://genrelay.ai/v1/images/generations",
        headers={"Authorization": f"Bearer {API_KEY}"},
        json={
            "model": "nano-banana-pro",
            "prompt": prompt,
            "image": ref_b64,
            "size": size,
            "n": 1
        }
    )
    response.raise_for_status()
    return response.json()["data"][0]["url"]

Key parameter: "image" is a base64-encoded PNG or JPEG. The reference image should be clean, well-lit, and free of distracting backgrounds — a cluttered or low-resolution reference weakens the model's ability to anchor subject identity, and you'll see more drift in the outputs.


How Do I Generate a Consistent Batch at Scale?

For product catalogs or character sets requiring many consistent outputs, you need a loop that applies the same reference to each scene prompt. The following pattern generates a batch of consistent product images against varying backgrounds:

import requests
import base64
import os
import time
from pathlib import Path

API_KEY = os.environ["GENRELAY_API_KEY"]

SCENE_PROMPTS = [
    "Product centered on white studio backdrop, soft diffused lighting, macro lens",
    "Product placed on a wooden kitchen counter, morning sunlight, lifestyle photography",
    "Product on dark slate surface, dramatic side lighting, minimalist composition",
    "Product outdoors on a picnic blanket, natural daylight, shallow depth of field",
    "Product on a glass shelf in a modern bathroom, clean white walls, editorial style",
]

def batch_reference_generate(reference_path: str, prompts: list[str], size: str = "1024x1024") -> list[str]:
    with open(reference_path, "rb") as f:
        ref_b64 = base64.b64encode(f.read()).decode("utf-8")

    results = []
    for i, prompt in enumerate(prompts):
        response = requests.post(
            "https://genrelay.ai/v1/images/generations",
            headers={"Authorization": f"Bearer {API_KEY}"},
            json={
                "model": "nano-banana-pro",
                "prompt": prompt,
                "image": ref_b64,
                "size": size,
                "n": 1
            }
        )
        response.raise_for_status()
        url = response.json()["data"][0]["url"]
        results.append(url)
        print(f"[{i+1}/{len(prompts)}] Generated: {url[:60]}...")
        time.sleep(0.2)  # light throttle; adjust for your plan's rate limits

    return results

# Usage
urls = batch_reference_generate("product_reference.png", SCENE_PROMPTS)

For high-volume batches (hundreds of images per run), replace the sequential loop with an asyncio pattern using a semaphore to cap concurrency at your plan limit. See the batch image generation guide for the full asyncio queue implementation.


When to Use GPT-image-2 Instead of Reference-Guided Generation

Reference-guided generation and instruction-based editing serve different consistency goals:

Approach Model Best for Consistency mechanism
Reference-guided generation Nano Banana Pro / Nano Banana 2 New scene variants anchored to subject Visual reference image input
Instruction-based editing GPT-image-2 Targeted changes to an existing image Edit preserves everything except the instructed change
Text-only generation Any Exploration, creative variety None — maximum variance

If you already have a generated image you're happy with and want to change only the background, lighting, or a specific object — GPT-image-2 editing is the better path. The model preserves what you don't instruct it to change, which is a strong consistency guarantee for small deltas.

If you're starting from a reference product photo and need to place it in 20 different scenes, Nano Banana Pro reference-guided generation scales more efficiently — each call takes the reference, not a prior generated output.

For detailed editing workflows, see the AI image editing API guide.


What Prompt Engineering Improves Consistency?

When combined with a reference image, prompt structure significantly affects how tightly outputs cluster:

  1. Describe the scene, not the subject. Since the reference defines the subject, your prompt should describe the environment, lighting, and framing. Prompts that re-describe the subject ("a red bottle with a black cap") compete with the reference and introduce drift.

  2. Specify photography style. Terms like "product photography", "macro lens", "editorial style", "studio lighting" constrain the model toward consistent visual treatment across scenes.

  3. Use consistent size and resolution. Changing the size parameter between calls changes crop, framing, and composition. Pick one size and stick with it for a batch.

  4. Avoid open-ended creative terms. Words like "artistic", "dreamy", "creative interpretation" give the model more expressive latitude — useful for exploration, counterproductive for consistency.


What Does Consistent Image Generation Cost?

Model Size Price 100-image batch cost
Nano Banana Pro 1K (1024×1024) $0.030 / image $3.00
Nano Banana Pro 2K (2048×2048) $0.030 / image $3.00
Nano Banana Pro 4K (4096×4096) $0.042 / image $4.20
Nano Banana 2 1K $0.020 / image $2.00
Nano Banana 2 4K $0.036 / image $3.60
GPT-image-2 (edit) 1024×1024 $0.014 / image $1.40

Scenario — 500-SKU product catalog, 5 scenes per product:

  • 2,500 images at Nano Banana Pro 1K: 2,500 × $0.030 = $75.00
  • 2,500 images at Nano Banana 2 1K: 2,500 × $0.020 = $50.00

For print-ready catalogs where 4K output is needed, Nano Banana Pro 4K at $0.042 is the path: 2,500 × $0.042 = $105.00.


FAQ

Does GenRelay support seed parameters to reproduce exact outputs?
As of September 2026, seed-based deterministic reproduction is not exposed across GenRelay image model endpoints. For reproducibility, save the reference image and the exact prompt — re-running the same combination with a reference produces outputs in a much tighter consistency range than text-only prompts.

How much does reference image quality affect the output?
Significantly. A clean, well-lit reference with a neutral background produces the tightest anchoring. If your reference has a busy background, consider preprocessing it to isolate the subject — this reduces the model's attention on irrelevant areas and improves subject fidelity across the batch.

Can I use the same reference image across multiple models?
Yes. The base64 encoding of the reference image is model-agnostic. You can use the same encoded image across Nano Banana Pro and Nano Banana 2 calls without re-encoding.

How many concurrent reference-guided generation requests can I run?
Standard GenRelay accounts support up to 10 concurrent image requests. For batch jobs above that rate, use an asyncio semaphore (asyncio.Semaphore(10)) to avoid 429 rate-limit errors.

Does GPT-image-2 support reference image input the same way?
GPT-image-2 uses an editing endpoint (/v1/images/edits) where you pass the image you want modified. It is not reference-guided generation — it interprets the image as the target to edit rather than a subject anchor for a new scene. For subject-anchored new-scene generation, Nano Banana Pro is the correct model on GenRelay.


Summary

Visual consistency in AI image generation pipelines requires a visual anchor, not just better prompts. The reference-guided generation pattern on Nano Banana Pro — passing a base64-encoded reference alongside each scene prompt — is the most reliable production approach for maintaining subject identity across large batches. For targeted edits on existing images, GPT-image-2's instruction-based editing preserves everything outside the instructed change. Structure your prompts around the scene, not the subject, and keep resolution consistent across a batch run to minimize drift.

Related posts

Join our DiscordHow to Maintain Visual Consistency in AI-Generated Images via API — GenRelay