import base64
import os
from pathlib import Path
from openai import OpenAI
client = OpenAI(
api_key=os.environ["HEIHUZI_API_KEY"],
base_url="https://code.heihuzi.ai/v1",
timeout=600.0,
max_retries=0,
)
with open("reference.png", "rb") as image:
result = client.images.edit(
model="gpt-image-2.5-sunburst",
image=image,
prompt="Change the blue cup to a bright red cup. Keep the cup shape and the white background.",
n=1,
size="1024x1024",
quality="low",
output_format="png",
)
if not result.data:
raise RuntimeError("No image returned")
for index, item in enumerate(result.data, 1):
if not item.b64_json:
raise RuntimeError("Missing b64_json")
Path(f"edited-{index}.png").write_bytes(base64.b64decode(item.b64_json))
print("Saved", len(result.data), "image(s)")