Docs Guides
Guide

Python gpt-image-1 Create/Edit

First result:

# Create an image from openai import OpenAI import base64 client = OpenAI( base_url="https://api.digislash.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-1", 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)
json
# Edit an image import base64 from openai import OpenAI client = OpenAI( base_url="https://api.digislash.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-1", 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 ![image.png](/tutorials/assets/help/python/6562372/519764.png) ![image.png](/tutorials/assets/help/python/6562372/519766.png) ![image.png](/tutorials/assets/help/python/6562372/519767.png) ![image.png](/tutorials/assets/help/python/6562372/519768.png) ![image.png](/tutorials/assets/help/python/6562372/519769.png) ![image.png](/tutorials/assets/help/python/6562372/519765.png) with open("gift-basket.png", "wb") as f: f.write(image_bytes)
json

First result: Reference images for the second example:

Second result: