Or better: have some of the P in API - programming, in Python. A bit better dall-e-3 demo.
import base64
import requests
import os
import time; starttime = time.time()
''' DALL-E API for image creation - URL json object returned:
{"created": 1744839275, "data": [{"url": "https://..."}, {"url": "https://..."}]}
'''
prompt = """
Photo Image: A monkey eating pasta with red sauce in a human restaurant.
""".replace('\n', ' ').strip()
headers = {"Authorization": f"Bearer {os.environ.get('OPENAI_API_KEY')}"}
request = {
"prompt": prompt, # DALL-E 3: max 4000 characters // DALL-E 2: max 1000
"model": "dall-e-3", # Defaults to dall-e-2 // optional
"quality": "standard", # or "hd" // no dall-e-2
"size": "1024x1024", # 1024x1024, 1792x1024, or 1024x1792 // 1792: no dall-e-2
"response_format": "url", # or b64_json for data
"style": "vivid", # or "natural", which is poor // no dall-e-2
"user": "my_id1234", # your customer tracker sent to OpenAI
}
response = requests.post(
"https://api.openai.com/v1/images/generations",
headers=headers,
json=request,
)
try:
response.raise_for_status()
data = response.json()
# Print each URL line-by-line for n>1 models
print("\nURLs:")
for item in data.get('data', []):
url = item.get('url')
if url:
print(url)
except requests.HTTPError as err:
print(f"HTTP error: {err}")
print(response.text)
print(str(time.time()-starttime) + " seconds")
input("\nCopy the url - links aren't saved!\nLinks good for an hour.")