Skip to main content

Use these patterns when you need consistent brand assets or precise image edits. They adapt the OpenAI Cookbook guidance on high-fidelity edits and automation. Primary reference: Generate images with high input fidelity.

Preserve detail with input_fidelity="high"

When to enable

  • Logo or product color tweaks that must preserve surrounding detail.
  • Portrait adjustments where faces need to stay recognizable.
  • Localized edits (add/remove props) without altering the background.
from openai import OpenAI
client = OpenAI(
    base_url="https://us.inference.heroku.com/v1",
    api_key=os.environ["INFERENCE_KEY"],
)

def edit_image(image_bytes: bytes, prompt: str) -> bytes:
    result = client.images.edit(
        model="gpt-image-1",
        image=image_bytes,
        prompt=prompt,
        input_fidelity="high",
        quality="high",
        output_format="png",
    )
    return base64.b64decode(result.data[0].b64_json)

Automate asset pipelines

Workflow tips

  • Store source images in Heroku Data for Redis or S3; pull by URL and feed to the edit endpoint.
  • Run edits in a worker dyno and push results to a CDN (CloudFront/Fastly) via background jobs.
  • Track prompt + output pairs in Postgres so designers can revert or reapply edits.

The cookbook suggests batching edits (resize, add/remove elements, face preservation) with helper functions and Pillow for preview generation.[^fidelity]

import base64
from io import BytesIO
from PIL import Image

def store_derivative(raw_bytes: bytes, filename: str):
    image = Image.open(BytesIO(raw_bytes))
    thumbnail = image.resize((512, int(image.height * 512 / image.width)))
    buffer = BytesIO()
    thumbnail.save(buffer, format="PNG")
    upload_to_s3(filename, buffer.getvalue())
Wrap S3 uploads in retry logic (Heroku recommends tenacity or AWS exponential backoff) and emit metrics when edits fail.

Team workflow

Governance

  • Restrict edit prompts to pre-approved templates (color swaps, copy updates) to avoid off-brand outputs.
  • Attach a simple React admin UI (served from Heroku) to preview before publishing.
  • Emit provenance metadata (prompt, date, operator) with each asset to satisfy audit requests.

Versioning

Store both the original and edited image hashes. If a new brand guideline is released, queue re-edits by iterating over historical prompts and swapping colors/overlays. High fidelity mode ensures incremental changes keep prior detail intact. Reference: OpenAI “Generate images with high input fidelity,” Jul 2025.