OpenAI’s image generation API lets you create high-quality images from text prompts, edit existing images with inpainting, and generate variations from a source image. Two models are available: DALL-E 3, which rewrites your prompts internally for better results and supports style and quality controls; and GPT Image (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/openai/openai-cookbook/llms.txt
Use this file to discover all available pages before exploring further.
gpt-image-1), a newer model with stronger instruction-following, photorealism, and world knowledge built in. Both share the same client.images interface.
Generate an image with DALL-E 3
Callclient.images.generate with your prompt and preferred settings. DALL-E 3 automatically rewrites short prompts into more detailed descriptions before generation, so you can work at a high level of abstraction.
Sizes, quality, and style
DALL-E 3 exposes three parameters beyond the prompt that have a meaningful effect on output.Size
DALL-E 3 supports three sizes. The aspect ratio affects composition: square images tend toward balanced scenes, wide images favor landscapes, and tall images suit portraits and mobile-style photography.| Size | Aspect ratio | Best for |
|---|---|---|
1024x1024 | 1:1 | Icons, product shots, balanced compositions |
1792x1024 | 16:9 | Landscapes, banners, wide scenes |
1024x1792 | 9:16 | Portraits, mobile wallpapers, vertical compositions |
Quality
hd quality produces images with finer texture, more consistent composition across the frame, and better adherence to detailed prompts. It adds roughly 10 seconds to generation time and increases cost per image.
Style
| Style | Description |
|---|---|
vivid | Hyper-real, cinematic, and dramatic. The default in ChatGPT. |
natural | Closer to realistic photography or illustration without over-exaggeration. Use when vivid produces results that are too dramatic. |
Generate with GPT Image (gpt-image-1)
GPT Image (gpt-image-1) is OpenAI’s newest image generation model. It has broad world knowledge baked in, follows detailed instructions more reliably than previous models, and produces photorealistic results with greater consistency.
gpt-image-1 returns images as base64-encoded JSON (b64_json) rather than URLs. Decode the response before saving or displaying the image.Detailed instruction following
GPT Image excels at following long, precise specifications. You can describe character design, materials, lighting setup, and compositional rules in a single prompt.Edit an image with inpainting
Theclient.images.edit endpoint lets you modify a specific region of an existing image by providing a mask that identifies the area to change. Only the masked pixels are regenerated; the rest of the image stays intact.
Prepare the source image and mask
Both must be PNG files of equal size. The mask uses transparency (alpha channel) to indicate the area to edit — fully transparent pixels will be replaced, opaque pixels will be preserved.
Generate variations
client.images.variations creates alternative versions of an existing image while preserving its general composition and subject matter.
Practical use cases
Product photo generation
Generate polished product shots on clean backgrounds at scale, without a photography studio.
Icon and logo prototyping
Rapidly iterate on icon sets and logo concepts before handing off to a designer.
Marketing asset creation
Produce hero images, social banners, and ad creatives from a single descriptive prompt.
Custom avatar generation
Create personalized character designs, avatars, or mascots based on detailed specifications.
Return format options
By default, DALL-E 3 returns a URL. You can request base64-encoded JSON instead if you need to handle the image directly in your application without a separate download step.Model comparison
| Feature | DALL-E 3 | GPT Image (gpt-image-1) |
|---|---|---|
| Prompt rewriting | Yes (automatic) | No (uses prompt as-is) |
| Photorealism | High | Very high |
| Instruction following | Good | Excellent |
| Output format | URL or b64_json | b64_json |
| Edits endpoint | DALL-E 2 only | Check API reference |
| Style parameter | vivid / natural | Not applicable |
| Quality parameter | standard / hd | Not applicable |
Prompt tips
Getting consistent, high-quality results from image generation models depends heavily on how you write prompts.- Be specific about style: “oil painting”, “photorealistic”, “flat vector illustration”, “charcoal sketch”
- Describe lighting: “soft ambient light”, “dramatic rim lighting”, “golden hour”, “studio lighting with soft shadows”
- Set the scene: include background, foreground, and compositional intent
- For DALL-E 3: since prompts are rewritten automatically, you can write naturally; for maximum fidelity to your original intent, add the instruction “I NEED to test how the tool works with extremely simple prompts” to suppress rewriting
- For GPT Image: prompts are used as-is, so be thorough and precise