DALL-E is a text-to-image Transformer that generates lifelike images from textual descriptions. DALL-E 2 combines text understanding with diffusion-based image generation, linking language and visual content through models such as CLIP. section 15.0 section 15.5
Generation begins by encoding the prompt into a latent representation. That representation conditions diffusion as the model repeatedly denoises a random noise vector until it produces an image matching the description. The broader diffusion process adds noise during training and learns to remove it during generation. section 15.0 section 15.5
Generate an image from a prompt
A Python program creates an OpenAI client, calls the image-generation endpoint with model="dall-e-2", supplies the prompt “an astronaut in a space suit riding a unicorn,” requests a 512×512 standard-quality image, and prints the returned URL. The URL expires after an hour, and repeated runs can produce different results because generation is stochastic. A follow-up exercise changes the prompt to “a cat in a suit working on a computer.” section 15.5.2
Listing 15.10 Image generation with DALL-E 2
from openai import OpenAI openai_api_key=your actual OpenAI API key here, in quotes #1 client=OpenAI(api_key=openai_api_key) #2 response = client.images.generate( model="dall-e-2", prompt="an astronaut in a space suit riding a unicorn", size="512x512", quality="standard", n=1, ) #3 image_url = response.data[0].url print(image_url) #4
Inspect the complete Python call, including client construction, model selection, prompt, size, quality, result count, and URL extraction. section 15.5.2



