from openai import OpenAI
import base64

API_KEY = ""

# Connect to server with API key authentication
client = OpenAI(api_key=API_KEY)

result = client.images.generate(
    model="dall-e-3", # currently best model for single picture generation
    prompt="a photorealistic picture of cute cat with big eyes",
    size="1024x1024",
    response_format="b64_json" # return base64-encoded picture data
)

# convert base64 to binary png picture data
image_base64 = result.data[0].b64_json
image_bytes = base64.b64decode(image_base64)

# Save the image to a file
with open("cat.png", "wb") as f:
    f.write(image_bytes)
