Run a complete example
This runnable example remains pinned to gpt-image-2. Use it as a baseline, then choose an available model and its supported request settings for your evaluation.
The examples below generate four logo variations and extract a product onto a transparent background. Install the OpenAI SDK with pip install openai for Python or gem install openai for Ruby. Set OPENAI_API_KEY and save the product photograph as input_images/shampoo.webp. Live requests incur API usage charges.
View the complete example
Generate and edit transparent assets
python
import base64
from pathlib import Path
from openai import OpenAI
client = OpenAI()
prompt = """
Create an original, non-infringing logo for a company called Field & Flour, a local bakery.
The logo should feel warm, simple, and timeless. Use clean, vector-like shapes, a strong silhouette, and balanced negative space.
Favor simplicity over detail so it reads clearly at small and large sizes. Flat design, minimal strokes, no gradients unless essential.
Fully transparent background. Deliver a single centered logo with generous padding, clean alpha edges, and no solid backdrop, scenery, checkerboard, or watermark.
"""
result = client.images.generate(
model="gpt-image-2",
prompt=prompt,
size="1024x1536",
quality="medium",
background="transparent",
output_format="png",
n=4, # Generate 4 versions of the logo
)
# Preserve the returned PNG bytes, including the alpha channel.
for index, item in enumerate(result.data, start=1):
Path(f"logo-generation-{index}-gpt-image-2.png").write_bytes(
base64.b64decode(item.b64_json)
)
# Extract a product from a reference image.
prompt = """
Extract the product from the input image and isolate it on a fully transparent background.
Output: centered product, crisp silhouette, no halos/fringing.
Preserve product geometry and label legibility exactly.
Add only light polishing. Do not add a solid backdrop, checkerboard, scenery, or shadow.
Do not restyle the product; remove the background and preserve clean alpha transparency.
"""
result = client.images.edit(
model="gpt-image-2",
image=[
Path("input_images/shampoo.webp"),
],
prompt=prompt,
size="1024x1536",
quality="medium",
background="transparent",
output_format="png",
)
Path("extract-product-gpt-image-2.png").write_bytes(
base64.b64decode(result.data[0].b64_json)
)ruby
require "base64"
require "openai"
require "pathname"
client = OpenAI::Client.new
result = client.images.generate(
model: "gpt-image-2",
prompt: "Create an original logo for Field & Flour, a local bakery. Use warm, simple shapes on a fully transparent background, with clean alpha edges and no shadow or checkerboard.",
size: "1024x1536", quality: :medium, background: :transparent, output_format: :png, n: 4
)
Array(result.data).each_with_index do |item, index|
File.binwrite("logo-generation-#{index + 1}-gpt-image-2.png", Base64.strict_decode64(item.b64_json || raise("No PNG returned")))
end
result = client.images.edit(
model: "gpt-image-2", image: OpenAI::FilePart.new(Pathname("input_images/shampoo.webp"), content_type: "image/webp"),
prompt: "Extract the product onto a fully transparent background. Preserve its geometry and label, with clean edges and no shadow or restyling.",
size: "1024x1536", quality: :medium, background: :transparent, output_format: :png
)
File.binwrite("extract-product-gpt-image-2.png", Base64.strict_decode64(Array(result.data).fetch(0).b64_json || raise("No PNG returned")))For additional prompts and complete workflows, see the original notebook.