Python gpt-image-2.5-sunburst Create/Edit
# Create an image
from openai import OpenAI
import base64
client = OpenAI( base_url="https://4zapi.com/v1",
api_key="sk-xxx")
prompt = """
A children's book illustration of a veterinarian listening to a baby otter's heartbeat with a stethoscope.
"""
result = client.images.generate(
model="gpt-image-2.5-sunburst",
prompt=prompt
)
image_base64 = result.data[0].b64_json
image_bytes = base64.b64decode(image_base64)
# Save the image to a file
with open("otter.png", "wb") as f:
f.write(image_bytes)
# Edit an image
import base64
from openai import OpenAI
client = OpenAI( base_url="https://4zapi.com/v1",
api_key="sk-xxx")
prompt = """
Generate a photorealistic image of a gift basket on a white background labeled "Relax & Unwind" with a ribbon and handwriting-like typography, containing all items from the reference images.
"""
result = client.images.edit(
model="gpt-image-2.5-sunburst",
image=[
open("body-lotion.png", "rb"),
open("bath-bomb.png", "rb"),
open("incense-kit.png", "rb"),
open("soap.png", "rb"),
],
prompt=prompt
)
image_base64 = result.data[0].b64_json
image_bytes = base64.b64decode(image_base64)
# Save the image to a file






with open("gift-basket.png", "wb") as f:
f.write(image_bytes)
First result: Reference images for the second example:
Second result: